# 2. Whisper Batch Transcription

> **RTX 5090:** 8–15× realtime transcription vs 2–4× on Mac
> **Why it matters:** Hours of audio transcribed in minutes — unlocks bulk audio workflows

---

## What Is Whisper?

[Whisper](https://github.com/openai/whisper) is OpenAI's open-source speech-to-text model. We use [whisper.cpp](https://github.com/ggerganov/whisper.cpp) — a high-performance C/C++ implementation that supports CUDA GPU acceleration.

The `large-v3-turbo` model (~1.5 GB) delivers near-human accuracy across 99 languages.

```
┌──────────────────────────────────────────────────────────────────────┐
│ Whisper Transcription Pipeline                                       │
│                                                                      │
│  Audio File (.wav/.mp3)                                              │
│       │                                                              │
│       ▼                                                              │
│  [FFmpeg: decode + resample to 16kHz mono]                          │
│       │                                                              │
│       ▼                                                              │
│  [Whisper: Mel spectrogram → Encoder → Decoder → Text]              │
│       │              ▲                                               │
│       │              │ GPU accelerates this (CUDA or Metal)         │
│       ▼                                                              │
│  Transcript (.txt / .srt / .vtt / .json)                            │
│                                                                      │
└──────────────────────────────────────────────────────────────────────┘
```

---

## Performance: Mac vs Razer

| Audio Length | Mac M4 Pro (Metal) | Razer RTX 5090 (CUDA) | Speedup |
| ------------ | ------------------ | --------------------- | ------- |
| 1 minute     | ~15–30s            | ~4–8s                 | ~3×     |
| 10 minutes   | ~2.5–5 min         | ~40–80s               | ~3×     |
| 1 hour       | ~15–30 min         | ~4–8 min              | ~3×     |
| 10 hours     | ~2.5–5 hours       | ~40–80 min            | ~3–4×   |
| 100 hours    | ~1–2 days          | ~7–13 hours           | ~3–4×   |

### Realtime Multiplier

| Machine        | Speed           | Meaning                  |
| -------------- | --------------- | ------------------------ |
| Mac M4 Pro     | ~2–4× realtime  | 1 hour audio → 15–30 min |
| Razer RTX 5090 | ~8–15× realtime | 1 hour audio → 4–8 min   |

---

## How to Use It

### Single File Transcription

```bash
# Basic transcription
whisper-cli -m ~/whisper-models/ggml-large-v3-turbo.bin -f audio.wav

# With timestamps (SRT format for subtitles)
whisper-cli -m ~/whisper-models/ggml-large-v3-turbo.bin -f audio.wav -osrt

# JSON output with word-level timestamps
whisper-cli -m ~/whisper-models/ggml-large-v3-turbo.bin -f audio.wav -ojf

# Specify language (skip auto-detect for speed)
whisper-cli -m ~/whisper-models/ggml-large-v3-turbo.bin -f audio.wav -l en
```

### Batch Transcription Script

Create this script to transcribe an entire folder of audio files:

```bash
#!/bin/bash
# batch-transcribe.sh — Transcribe all audio files in a directory
# Usage: bash batch-transcribe.sh /path/to/audio/files

INPUT_DIR="${1:-.}"
MODEL="$HOME/whisper-models/ggml-large-v3-turbo.bin"
OUTPUT_DIR="${INPUT_DIR}/transcripts"

mkdir -p "$OUTPUT_DIR"

echo "=== Batch Whisper Transcription ==="
echo "Input:  $INPUT_DIR"
echo "Output: $OUTPUT_DIR"
echo "Model:  ggml-large-v3-turbo"
echo ""

TOTAL=0
DONE=0
START_TIME=$(date +%s)

# Count files
for f in "$INPUT_DIR"/*.{wav,mp3,m4a,flac,ogg,webm} 2>/dev/null; do
    [ -f "$f" ] && ((TOTAL++))
done

echo "Found $TOTAL audio files"
echo ""

for f in "$INPUT_DIR"/*.{wav,mp3,m4a,flac,ogg,webm} 2>/dev/null; do
    [ -f "$f" ] || continue
    ((DONE++))

    BASENAME=$(basename "$f" | sed 's/\.[^.]*$//')
    echo "[$DONE/$TOTAL] Transcribing: $(basename "$f")"

    whisper-cli \
        -m "$MODEL" \
        -f "$f" \
        -l en \
        -otxt \
        -of "$OUTPUT_DIR/$BASENAME" \
        2>/dev/null

    # Also generate SRT for subtitle use
    whisper-cli \
        -m "$MODEL" \
        -f "$f" \
        -l en \
        -osrt \
        -of "$OUTPUT_DIR/$BASENAME" \
        2>/dev/null

    echo "  -> $OUTPUT_DIR/$BASENAME.txt"
    echo "  -> $OUTPUT_DIR/$BASENAME.srt"
    echo ""
done

END_TIME=$(date +%s)
ELAPSED=$((END_TIME - START_TIME))
echo "=== Done! $DONE files in ${ELAPSED}s ==="
```

### Convert Non-WAV Audio First

```bash
# Whisper works best with 16kHz mono WAV
# Convert any audio format with ffmpeg

# Single file
ffmpeg -i podcast.mp3 -ar 16000 -ac 1 podcast.wav

# Batch convert all MP3s in a folder
for f in *.mp3; do
    ffmpeg -i "$f" -ar 16000 -ac 1 "${f%.mp3}.wav"
done
```

### Python Integration

```python
"""Transcribe audio using whisper.cpp via subprocess."""
import subprocess
import json
from pathlib import Path

def transcribe(audio_path: str, language: str = "en") -> dict:
    """Transcribe an audio file and return structured result."""
    model = Path.home() / "whisper-models" / "ggml-large-v3-turbo.bin"
    output_base = Path(audio_path).stem

    result = subprocess.run(
        [
            "whisper-cli",
            "-m", str(model),
            "-f", audio_path,
            "-l", language,
            "-ojf",  # JSON with full metadata
            "-of", output_base,
        ],
        capture_output=True, text=True, timeout=600,
    )

    # Read the JSON output
    json_path = Path(f"{output_base}.json")
    if json_path.exists():
        with open(json_path) as f:
            return json.load(f)

    return {"error": result.stderr, "text": result.stdout}

# Usage
result = transcribe("meeting-recording.wav")
print(result["transcription"][0]["text"])
```

---

## Real-World Use Cases

### 1. LysnrAI Voice Dictation Pipeline

Your LysnrAI desktop app captures voice → sends to Whisper for transcription. On the Razer, this becomes near-instant:

```
Voice input (5 seconds) → Whisper (CUDA) → Text in <1 second
```

### 2. Meeting Transcription

```bash
# Record a 1-hour Zoom meeting → get full transcript in ~5 minutes
whisper-cli -m ~/whisper-models/ggml-large-v3-turbo.bin \
    -f zoom-meeting.wav -l en -otxt -osrt
```

### 3. Podcast / YouTube Processing

```bash
# Download YouTube audio
yt-dlp -x --audio-format wav "https://youtube.com/watch?v=..." -o "video.wav"

# Transcribe
whisper-cli -m ~/whisper-models/ggml-large-v3-turbo.bin -f video.wav -otxt -osrt
```

### 4. Subtitle Generation

```bash
# Generate SRT subtitles for video
whisper-cli -m ~/whisper-models/ggml-large-v3-turbo.bin \
    -f movie.wav -l en -osrt

# Output: movie.srt — ready to import into video editors
```

### 5. Multi-Language Transcription

```bash
# Auto-detect language
whisper-cli -m ~/whisper-models/ggml-large-v3-turbo.bin -f audio.wav

# Force specific language
whisper-cli -m ~/whisper-models/ggml-large-v3-turbo.bin -f audio.wav -l ja  # Japanese
whisper-cli -m ~/whisper-models/ggml-large-v3-turbo.bin -f audio.wav -l ta  # Tamil
```

---

## Benefits

| Benefit         | Description                                                  |
| --------------- | ------------------------------------------------------------ |
| **Speed**       | Process a full day of meetings in under an hour              |
| **Privacy**     | All transcription runs locally — no data leaves your machine |
| **Cost**        | Zero API costs (vs $0.006/min for cloud Whisper API)         |
| **Accuracy**    | large-v3-turbo is near-human accuracy for English            |
| **Offline**     | Works without internet — useful on flights, trains           |
| **Batch scale** | Process hundreds of files overnight                          |

### Cost Comparison (100 hours of audio)

| Method                     | Cost   | Time             |
| -------------------------- | ------ | ---------------- |
| OpenAI Whisper API         | ~$36   | ~minutes (cloud) |
| Mac M4 Pro (local)         | $0     | ~25–50 hours     |
| **Razer RTX 5090 (local)** | **$0** | **~7–13 hours**  |

---

## Skills You'll Learn

| Skill                        | What You'll Learn                                      | Career Value                           |
| ---------------------------- | ------------------------------------------------------ | -------------------------------------- |
| **Audio processing**         | Sample rates, codecs, mono/stereo, WAV vs compressed   | Foundational for any audio/speech work |
| **Speech-to-text pipelines** | Mel spectrograms, encoder-decoder models, beam search  | Core ML/NLP skill                      |
| **CUDA acceleration**        | How GPU parallelism speeds up neural network inference | Top ML engineering skill               |
| **Batch processing**         | Shell scripting for processing thousands of files      | DevOps / data engineering              |
| **Subtitle formats**         | SRT, VTT, JSON — standards for timed text              | Media tech / accessibility             |
| **Model quantization**       | Understanding why ggml models are smaller and faster   | ML deployment knowledge                |
| **ffmpeg mastery**           | Audio/video conversion, resampling, format detection   | Essential multimedia tool              |
| **Python subprocess**        | Integrating CLI tools into Python applications         | Backend engineering pattern            |

---

## Monitoring GPU During Transcription

```bash
# Watch GPU utilization in real-time
watch -n 0.5 nvidia-smi

# Or use nvtop for a richer view
sudo apt install nvtop
nvtop

# Expected during Whisper:
# GPU Utilization: 80–95%
# VRAM Usage: ~2–3 GB (model + buffers)
# Power: ~150–200W
```

---

## Next Steps

- [ ] Transcribe a test audio file and verify output quality
- [ ] Create `batch-transcribe.sh` in `__LOCAL_LLMs/scripts/`
- [ ] Benchmark: time a 10-minute file on Razer vs Mac
- [ ] Try multi-language transcription (English + Tamil)
- [ ] Integrate Whisper output into LysnrAI transcription pipeline
- [ ] Experiment with `whisper-cli --translate` for translation mode
