Sync from davanstrien/uv-scripts via hub-sync
Browse files- BENCHMARKS.md +8 -0
- MODELS.md +3 -0
- README.md +18 -2
- rumble-transcribe.py +294 -0
BENCHMARKS.md
CHANGED
|
@@ -57,3 +57,11 @@ Result published as [`davanstrien/apollo-11-diarized`](https://huggingface.co/da
|
|
| 57 |
"Transcription" starts once the server is up; "whole job" includes the checkpoint download (17–30 s) and engine load and warmup (4–5.5 min). A part that loops until `max_tokens` finishes last and sets the batch time: in the slower NVFP4 run one part took 171 s, the others 122 s or less. The cards report error rates about 1.0% (FP8) and 3.6% (NVFP4) higher than BF16, in relative terms. With no ground truth here, word agreement with the BF16 run (difflib ratio, mean over files) was 0.80 for FP8 and 0.82–0.83 for NVFP4, and 0.80 for a second BF16 run on the mp3 input, so on this noisy 1971 audio the quantized checkpoints differ from BF16 about as much as two BF16 runs differ from each other.
|
| 58 |
|
| 59 |
Did not work on 2026-11-03: vLLM 0.33.0 (the NeMo Speech plugin fails at startup: `_parse_chat_message_content_parts` is missing); FP8 on `l40sx1` (FlashInfer's JIT build of a Mamba kernel fails at the first request). For comparison, `nemotron-transcribe-saturate.py` (SGLang-Omni main, BF16) took 7.0 min (97x) on the same FLAC files, and its FP8 checkpoint does not load.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
"Transcription" starts once the server is up; "whole job" includes the checkpoint download (17–30 s) and engine load and warmup (4–5.5 min). A part that loops until `max_tokens` finishes last and sets the batch time: in the slower NVFP4 run one part took 171 s, the others 122 s or less. The cards report error rates about 1.0% (FP8) and 3.6% (NVFP4) higher than BF16, in relative terms. With no ground truth here, word agreement with the BF16 run (difflib ratio, mean over files) was 0.80 for FP8 and 0.82–0.83 for NVFP4, and 0.80 for a second BF16 run on the mp3 input, so on this noisy 1971 audio the quantized checkpoints differ from BF16 about as much as two BF16 runs differ from each other.
|
| 58 |
|
| 59 |
Did not work on 2026-11-03: vLLM 0.33.0 (the NeMo Speech plugin fails at startup: `_parse_chat_message_content_parts` is missing); FP8 on `l40sx1` (FlashInfer's JIT build of a Mamba kernel fails at the first request). For comparison, `nemotron-transcribe-saturate.py` (SGLang-Omni main, BF16) took 7.0 min (97x) on the same FLAC files, and its FP8 checkpoint does not load.
|
| 60 |
+
|
| 61 |
+
**`rumble-transcribe.py`** (CBS Suspense, 10 episodes, 295 min, from the Internet Archive via `download-ia.py`; vLLM 0.32.0 image, default options, auto language detection):
|
| 62 |
+
|
| 63 |
+
| GPU | Transcription | RTFx | Whole job | Cost | Output |
|
| 64 |
+
|-----|---------------|------|-----------|------|--------|
|
| 65 |
+
| L4 | 40 s (incl. mp3 decoding) | 438x | 152 s | ~$0.03 | 10 `.txt`, 648 chunks, 0 truncated, English detected for all |
|
| 66 |
+
|
| 67 |
+
Word disagreement with `cohere-transcribe.py` on the same episodes, after lowercasing and stripping punctuation: 9.0% (44,292 Cohere words, 43,717 Rumble words; 2,235 substitutions, 1,158 deletions, 583 insertions). Ignoring "ha", "uh", "um", "hmm", "ah", "oh" and "mm": 8.7%.
|
MODELS.md
CHANGED
|
@@ -15,6 +15,7 @@ What each script does, what it costs and what we measured. The [README](README.m
|
|
| 15 |
| `moss-transcribe-diarize-server.py` | [MOSS-Transcribe-Diarize](https://huggingface.co/OpenMOSS-Team/MOSS-Transcribe-Diarize) (0.9B) | in-job sgl-omni server | JSON speaker segments (+ optional `.txt`) | 47.4x RT aggregate (A100, 6 streams) |
|
| 16 |
| `nemotron-transcribe.py` | [Nemotron 3.5 Transcribe](https://huggingface.co/nvidia/NVIDIA-Nemotron-3.5-Transcribe-30B-A4B) (30B MoE, ~4B active, 40 languages) | in-job vLLM 0.32 + NeMo Speech server | `.txt` (+ JSON word timestamps, speakers and diarization with `--timestamps`) | 116x RT aggregate (RTX PRO 6000, 10 files) + ~8 min fixed setup |
|
| 17 |
| `nemotron-transcribe-saturate.py` | Nemotron 3.5 Transcribe (same model) | in-job SGLang-Omni server, driven by [saturate](https://github.com/davanstrien/saturate) | parquet `{id, text, finish_reason, duration_s, model, prompt, error}` | 81x RT aggregate (RTX PRO 6000, 10 files) + ~9 min fixed setup |
|
|
|
|
| 18 |
|
| 19 |
**`cohere-transcribe.py`** (recommended for plain text) — uses `model.transcribe()` with automatic long-form chunking, overlap, and reassembly. Stable dependencies.
|
| 20 |
|
|
@@ -34,6 +35,8 @@ What each script does, what it costs and what we measured. The [README](README.m
|
|
| 34 |
|
| 35 |
**`nemotron-transcribe-saturate.py`** — the same model on **SGLang-Omni** (no NeMo), with saturate as the driver: a fixed window of files in flight (`--concurrency`), resumable parquet output keyed by input path, and durable error rows (`--retry-errors`). Input is a glob (`"hf://buckets/user/audio/**/*.mp3"`), output a dataset id or fsspec URI. It is plain transcription only, because SGLang-Omni's integration has no timestamps, speaker tags or translation; each file is one request of up to an hour. On the same 10 episodes it ran at 81x realtime once up (vLLM path: 116x) in a 12.8 min job; its text differs from the vLLM recipe's by 2.4% of words and from Cohere's by 7.3%, with no looping or truncated files. Two workarounds are pinned in its `SERVING` dict. The model card names SGLang-Omni 0.2.0, but that wheel predates the Nemotron integration, so a `main` commit is installed. The integration also expects the architecture name `NeMoSpeechLMForConditionalGeneration` while the Hub checkpoint declares `Nemotron3_5TranscribeForConditionalGeneration`, so the local copy's `config.json` is renamed before serving. The FP8 checkpoint does not load on this integration (its audio encoder's FP8 scales are reported as unexpected weights), so this recipe stays on BF16. SGLang-Omni decodes each file with torchcodec, which rejects a whole mp3 with one damaged frame; re-encode such files (e.g. to 16 kHz FLAC) first.
|
| 36 |
|
|
|
|
|
|
|
| 37 |
## Notes
|
| 38 |
|
| 39 |
- **Tokenizer workaround**: `cohere-transcribe.py` applies a one-line patch for a tokenizer compat issue. Will be removed once upstream fixes land ([model discussion](https://huggingface.co/CohereLabs/cohere-transcribe-03-2026/discussions/11)).
|
|
|
|
| 15 |
| `moss-transcribe-diarize-server.py` | [MOSS-Transcribe-Diarize](https://huggingface.co/OpenMOSS-Team/MOSS-Transcribe-Diarize) (0.9B) | in-job sgl-omni server | JSON speaker segments (+ optional `.txt`) | 47.4x RT aggregate (A100, 6 streams) |
|
| 16 |
| `nemotron-transcribe.py` | [Nemotron 3.5 Transcribe](https://huggingface.co/nvidia/NVIDIA-Nemotron-3.5-Transcribe-30B-A4B) (30B MoE, ~4B active, 40 languages) | in-job vLLM 0.32 + NeMo Speech server | `.txt` (+ JSON word timestamps, speakers and diarization with `--timestamps`) | 116x RT aggregate (RTX PRO 6000, 10 files) + ~8 min fixed setup |
|
| 17 |
| `nemotron-transcribe-saturate.py` | Nemotron 3.5 Transcribe (same model) | in-job SGLang-Omni server, driven by [saturate](https://github.com/davanstrien/saturate) | parquet `{id, text, finish_reason, duration_s, model, prompt, error}` | 81x RT aggregate (RTX PRO 6000, 10 files) + ~9 min fixed setup |
|
| 18 |
+
| `rumble-transcribe.py` | [Rumble-2-Flash](https://huggingface.co/Reson8/Rumble-2-Flash) (0.5B Qwen3-ASR, 45 languages) | vLLM 0.32 image | `.txt` | 438x RT (L4, 10 files, incl. audio decoding) + ~80 s model load |
|
| 19 |
|
| 20 |
**`cohere-transcribe.py`** (recommended for plain text) — uses `model.transcribe()` with automatic long-form chunking, overlap, and reassembly. Stable dependencies.
|
| 21 |
|
|
|
|
| 35 |
|
| 36 |
**`nemotron-transcribe-saturate.py`** — the same model on **SGLang-Omni** (no NeMo), with saturate as the driver: a fixed window of files in flight (`--concurrency`), resumable parquet output keyed by input path, and durable error rows (`--retry-errors`). Input is a glob (`"hf://buckets/user/audio/**/*.mp3"`), output a dataset id or fsspec URI. It is plain transcription only, because SGLang-Omni's integration has no timestamps, speaker tags or translation; each file is one request of up to an hour. On the same 10 episodes it ran at 81x realtime once up (vLLM path: 116x) in a 12.8 min job; its text differs from the vLLM recipe's by 2.4% of words and from Cohere's by 7.3%, with no looping or truncated files. Two workarounds are pinned in its `SERVING` dict. The model card names SGLang-Omni 0.2.0, but that wheel predates the Nemotron integration, so a `main` commit is installed. The integration also expects the architecture name `NeMoSpeechLMForConditionalGeneration` while the Hub checkpoint declares `Nemotron3_5TranscribeForConditionalGeneration`, so the local copy's `config.json` is renamed before serving. The FP8 checkpoint does not load on this integration (its audio encoder's FP8 scales are reported as unexpected weights), so this recipe stays on BF16. SGLang-Omni decodes each file with torchcodec, which rejects a whole mp3 with one damaged frame; re-encode such files (e.g. to 16 kHz FLAC) first.
|
| 37 |
|
| 38 |
+
**`rumble-transcribe.py`** — when you want **punctuated, cased text for a lot of audio at the lowest cost**, in one of 45 languages. [Rumble-2-Flash](https://huggingface.co/Reson8/Rumble-2-Flash) is a 0.5B Qwen3-ASR model (Apache 2.0) that averages 6.60 WER on the Open ASR Leaderboard's English track (v1.16.1). The recipe runs it on the stock vLLM 0.32 image, which supports the architecture natively. Files are cut into chunks of at most 30 s, each cut at the quietest 20 ms in the last 5 s before the limit, so chunks do not overlap and there is no duplicated text at boundaries. On the same 10 Suspense episodes as the Nemotron runs (4.9 h), `l4x1` decoded and transcribed everything in 40 s. The whole Job ran for 152 s (about $0.03), about 80 s of it model download and engine load. After lowercasing and stripping punctuation, its words differ from Cohere's by 9.0% (Nemotron vs Cohere: 7.0%; Granite vs Cohere: 7.7%). There is no ground truth, so this measures agreement, not accuracy. Part of the gap is by design: Cohere writes laughter as "ha ha ha" and keeps fillers, while the model card's default (`<nofiller>`) drops "uh" and "um" (`--keep-fillers` keeps them). Most of the rest is substitutions (2,235 of 3,976 word edits). In one episode we read closely, Rumble skipped about 30 words of shouted, overlapping dialogue. The template options from the card (`--language`, `--words-for-digits`, `--keep-fillers`, `--no-verbatim`) map onto the model's control tokens; without `--language` the model names the language per chunk and the recipe records the most common one per file.
|
| 39 |
+
|
| 40 |
## Notes
|
| 41 |
|
| 42 |
- **Tokenizer workaround**: `cohere-transcribe.py` applies a one-line patch for a tokenizer compat issue. Will be removed once upstream fixes land ([model discussion](https://huggingface.co/CohereLabs/cohere-transcribe-03-2026/discussions/11)).
|
README.md
CHANGED
|
@@ -63,7 +63,7 @@ hf jobs uv run --flavor l4x1 -s HF_TOKEN --timeout 30m \
|
|
| 63 |
|
| 64 |
**Harder audio.** Mount `/apollo11` instead of `/podcast`: two clips of 1969 mission tapes with radio noise and crosstalk. The [demo Bucket's README](https://huggingface.co/buckets/uv-scripts/transcription-demo) gives the sources and licences (NASA, public domain).
|
| 65 |
|
| 66 |
-
**Why no flags.** The Nemotron scripts carry a [`[tool.hf-jobs]` header](https://huggingface.co/docs/hub/jobs-configuration#define-the-launch-config-in-the-script) that sets the GPU, image and secrets. The other scripts have no header yet and take flags, as in the MOSS command. `hf jobs uv run --dry-run <script>` shows the resolved settings.
|
| 67 |
|
| 68 |
</details>
|
| 69 |
|
|
@@ -95,8 +95,9 @@ hf jobs uv run \
|
|
| 95 |
| Who said what, in English or Chinese | `moss-transcribe-diarize.py` (`-server.py` for many files) | Slow on long files; server version needs `a100-large` |
|
| 96 |
| Word timestamps and speaker tags from one model, in 40 languages (speaker tags in 13) | `nemotron-transcribe.py` | ~8 min fixed setup before the first file |
|
| 97 |
| Nemotron text for a large batch, resumable | `nemotron-transcribe-saturate.py` | Plain text only |
|
|
|
|
| 98 |
|
| 99 |
-
Only the
|
| 100 |
|
| 101 |
<details>
|
| 102 |
<summary>Cohere Transcribe command</summary>
|
|
@@ -195,6 +196,21 @@ The folder scripts take `/input /output` and `--max-files N` for a test run (the
|
|
| 195 |
|
| 196 |
</details>
|
| 197 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
<details>
|
| 199 |
<summary><code>easytranscriber-transcribe.py</code></summary>
|
| 200 |
|
|
|
|
| 63 |
|
| 64 |
**Harder audio.** Mount `/apollo11` instead of `/podcast`: two clips of 1969 mission tapes with radio noise and crosstalk. The [demo Bucket's README](https://huggingface.co/buckets/uv-scripts/transcription-demo) gives the sources and licences (NASA, public domain).
|
| 65 |
|
| 66 |
+
**Why no flags.** The Nemotron and Rumble scripts carry a [`[tool.hf-jobs]` header](https://huggingface.co/docs/hub/jobs-configuration#define-the-launch-config-in-the-script) that sets the GPU, image and secrets. The other scripts have no header yet and take flags, as in the MOSS command. `hf jobs uv run --dry-run <script>` shows the resolved settings.
|
| 67 |
|
| 68 |
</details>
|
| 69 |
|
|
|
|
| 95 |
| Who said what, in English or Chinese | `moss-transcribe-diarize.py` (`-server.py` for many files) | Slow on long files; server version needs `a100-large` |
|
| 96 |
| Word timestamps and speaker tags from one model, in 40 languages (speaker tags in 13) | `nemotron-transcribe.py` | ~8 min fixed setup before the first file |
|
| 97 |
| Nemotron text for a large batch, resumable | `nemotron-transcribe-saturate.py` | Plain text only |
|
| 98 |
+
| Punctuated text in 45 languages, cheaply (5 h of audio in 40 s on an L4) | `rumble-transcribe.py` | Plain text only; drops laughter and fillers by default |
|
| 99 |
|
| 100 |
+
Only the Nemotron and Rumble scripts set their own GPU and image. The others need flags, for example Cohere on an L4:
|
| 101 |
|
| 102 |
<details>
|
| 103 |
<summary>Cohere Transcribe command</summary>
|
|
|
|
| 196 |
|
| 197 |
</details>
|
| 198 |
|
| 199 |
+
<details>
|
| 200 |
+
<summary><code>rumble-transcribe.py</code></summary>
|
| 201 |
+
|
| 202 |
+
| Flag | Default | Description |
|
| 203 |
+
|------|---------|-------------|
|
| 204 |
+
| `--language` | detect | English name of the language (`English`, `Dutch`); omit to detect it per chunk (recorded in `summary.jsonl`) |
|
| 205 |
+
| `--words-for-digits` | off | Write numbers as words instead of digits |
|
| 206 |
+
| `--keep-fillers` | off | Keep fillers such as "um" and "uh" |
|
| 207 |
+
| `--no-verbatim` | off | Collapse repeated words |
|
| 208 |
+
| `--chunk-seconds` | 30 | Maximum chunk length; each cut is at the quietest 20 ms in the last `--search-seconds` (default 5) before the limit |
|
| 209 |
+
| `--batch-files` | 32 | Files loaded per vLLM call; finished files are skipped on a rerun (`--overwrite` to redo) |
|
| 210 |
+
| `--max-files` | all | Limit files to process (for testing) |
|
| 211 |
+
|
| 212 |
+
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jobs]
|
| 11 |
+
# # vllm, torch and transformers come from the image (PYTHONPATH). Local GPU: uv run --with vllm.
|
| 12 |
+
# image = "vllm/vllm-openai:v0.32.0"
|
| 13 |
+
# python = "/usr/bin/python3"
|
| 14 |
+
# env = { PYTHONPATH = "/usr/local/lib/python3.12/dist-packages" }
|
| 15 |
+
# flavor = "l4x1"
|
| 16 |
+
# secrets = ["HF_TOKEN"]
|
| 17 |
+
# timeout = "1h"
|
| 18 |
+
#
|
| 19 |
+
# [tool.uv-scripts]
|
| 20 |
+
# maintenance = "active"
|
| 21 |
+
# ///
|
| 22 |
+
|
| 23 |
+
"""
|
| 24 |
+
Transcribe a directory of audio files with Reson8/Rumble-2-Flash via vLLM.
|
| 25 |
+
|
| 26 |
+
Rumble-2-Flash is a 0.5B Qwen3-ASR model (Apache 2.0, 45 languages). On the
|
| 27 |
+
Open ASR Leaderboard (v1.16.1) it averages 6.60 WER on the English track.
|
| 28 |
+
|
| 29 |
+
Designed for HF Buckets mounted as volumes with `hf jobs uv run -v ...`.
|
| 30 |
+
|
| 31 |
+
Long files are cut into chunks of at most --chunk-seconds. Each cut is placed at
|
| 32 |
+
the quietest point in the last few seconds before the limit, so chunks do not
|
| 33 |
+
overlap and words are rarely split. All chunks in a batch of files go through
|
| 34 |
+
vLLM in one call. Files that already have a transcript in the output directory
|
| 35 |
+
are skipped, so a rerun continues where the last run stopped.
|
| 36 |
+
|
| 37 |
+
Input: Output:
|
| 38 |
+
/input/episode1.mp3 -> /output/episode1.txt
|
| 39 |
+
/input/sub/clip.wav -> /output/sub/clip.txt
|
| 40 |
+
/output/summary.jsonl
|
| 41 |
+
|
| 42 |
+
Examples:
|
| 43 |
+
|
| 44 |
+
# HF Jobs with bucket volumes (the header sets image, flavor and secrets)
|
| 45 |
+
hf jobs uv run \\
|
| 46 |
+
-v hf://buckets/user/audio-input:/input:ro \\
|
| 47 |
+
-v hf://buckets/user/transcripts:/output \\
|
| 48 |
+
https://huggingface.co/datasets/uv-scripts/transcription/raw/main/rumble-transcribe.py \\
|
| 49 |
+
/input /output --language English
|
| 50 |
+
|
| 51 |
+
# Local GPU (Linux + CUDA)
|
| 52 |
+
uv run --with vllm rumble-transcribe.py ./audio ./out --max-files 3
|
| 53 |
+
|
| 54 |
+
Options from the model card's chat template:
|
| 55 |
+
--language NAME English name ("Dutch", "English"). Omit to detect per chunk.
|
| 56 |
+
--words-for-digits Write numbers as words (default: digits).
|
| 57 |
+
--keep-fillers Keep "um" and "uh" (default: dropped).
|
| 58 |
+
--no-verbatim Collapse repeated words (default: kept).
|
| 59 |
+
"""
|
| 60 |
+
|
| 61 |
+
import argparse
|
| 62 |
+
import importlib.metadata
|
| 63 |
+
import json
|
| 64 |
+
import logging
|
| 65 |
+
import sys
|
| 66 |
+
import time
|
| 67 |
+
from collections import Counter
|
| 68 |
+
from pathlib import Path
|
| 69 |
+
|
| 70 |
+
import numpy as np
|
| 71 |
+
|
| 72 |
+
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s")
|
| 73 |
+
logger = logging.getLogger(__name__)
|
| 74 |
+
|
| 75 |
+
MODEL = "Reson8/Rumble-2-Flash"
|
| 76 |
+
SAMPLE_RATE = 16000
|
| 77 |
+
AUDIO_EXTENSIONS = {".mp3", ".wav", ".flac", ".ogg", ".m4a", ".wma", ".aac", ".opus"}
|
| 78 |
+
ASR_TEXT_TAG = "<asr_text>"
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def discover_audio_files(input_dir: Path) -> list[Path]:
|
| 82 |
+
"""Return every audio file under input_dir, sorted."""
|
| 83 |
+
files = []
|
| 84 |
+
for path in sorted(input_dir.rglob("*")):
|
| 85 |
+
if path.is_file() and path.suffix.lower() in AUDIO_EXTENSIONS:
|
| 86 |
+
files.append(path)
|
| 87 |
+
return files
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def load_audio(file_path: Path) -> np.ndarray:
|
| 91 |
+
"""Load a file as 16 kHz mono float32."""
|
| 92 |
+
import librosa
|
| 93 |
+
|
| 94 |
+
audio, _ = librosa.load(str(file_path), sr=SAMPLE_RATE, mono=True)
|
| 95 |
+
return audio.astype(np.float32)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def quietest_sample(audio: np.ndarray, start: int, end: int) -> int:
|
| 99 |
+
"""Return the sample index at the centre of the quietest 20 ms frame in [start, end)."""
|
| 100 |
+
frame = SAMPLE_RATE // 50
|
| 101 |
+
window = audio[start:end]
|
| 102 |
+
n_frames = len(window) // frame
|
| 103 |
+
if n_frames == 0:
|
| 104 |
+
return end
|
| 105 |
+
frames = window[: n_frames * frame].reshape(n_frames, frame)
|
| 106 |
+
energy = np.sqrt(np.mean(frames**2, axis=1))
|
| 107 |
+
best_frame = int(np.argmin(energy))
|
| 108 |
+
return start + best_frame * frame + frame // 2
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def chunk_audio(audio: np.ndarray, chunk_seconds: float, search_seconds: float) -> list[np.ndarray]:
|
| 112 |
+
"""Cut audio into chunks of at most chunk_seconds, each cut at a quiet point."""
|
| 113 |
+
max_len = int(chunk_seconds * SAMPLE_RATE)
|
| 114 |
+
search_len = int(search_seconds * SAMPLE_RATE)
|
| 115 |
+
chunks = []
|
| 116 |
+
start = 0
|
| 117 |
+
while len(audio) - start > max_len:
|
| 118 |
+
limit = start + max_len
|
| 119 |
+
cut = quietest_sample(audio, limit - search_len, limit)
|
| 120 |
+
chunks.append(audio[start:cut])
|
| 121 |
+
start = cut
|
| 122 |
+
chunks.append(audio[start:])
|
| 123 |
+
return chunks
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def parse_output(raw: str) -> tuple[str | None, str]:
|
| 127 |
+
"""Split raw model output into (detected language, text).
|
| 128 |
+
|
| 129 |
+
With --language set, the prompt already ends with "language X<asr_text>",
|
| 130 |
+
so the output is plain text. Without it, the output starts with
|
| 131 |
+
"language <Name><asr_text>".
|
| 132 |
+
"""
|
| 133 |
+
text = raw.replace("<|im_end|>", "").strip()
|
| 134 |
+
if ASR_TEXT_TAG not in text:
|
| 135 |
+
return None, text
|
| 136 |
+
header, _, body = text.partition(ASR_TEXT_TAG)
|
| 137 |
+
language = header.removeprefix("language").strip() or None
|
| 138 |
+
return language, body.strip()
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def build_prompt(tokenizer, args) -> str:
|
| 142 |
+
"""Render the model's chat template for one audio input."""
|
| 143 |
+
messages = [{"role": "user", "content": [{"type": "audio"}]}]
|
| 144 |
+
template_kwargs = {
|
| 145 |
+
"digits": not args.words_for_digits,
|
| 146 |
+
"filler": args.keep_fillers,
|
| 147 |
+
"verbatim": not args.no_verbatim,
|
| 148 |
+
}
|
| 149 |
+
if args.language:
|
| 150 |
+
template_kwargs["language"] = args.language
|
| 151 |
+
return tokenizer.apply_chat_template(
|
| 152 |
+
messages, tokenize=False, add_generation_prompt=True, **template_kwargs
|
| 153 |
+
)
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
def output_path_for(file_path: Path, input_dir: Path, output_dir: Path) -> Path:
|
| 157 |
+
return output_dir / file_path.relative_to(input_dir).with_suffix(".txt")
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def transcribe_batch(llm, sampling_params, prompt, files, args, input_dir, output_dir) -> list[dict]:
|
| 161 |
+
"""Load, chunk and transcribe one batch of files; write one .txt per file."""
|
| 162 |
+
chunk_owner = [] # file index for each chunk, in order
|
| 163 |
+
requests = []
|
| 164 |
+
durations = []
|
| 165 |
+
for file_index, file_path in enumerate(files):
|
| 166 |
+
audio = load_audio(file_path)
|
| 167 |
+
durations.append(len(audio) / SAMPLE_RATE)
|
| 168 |
+
for chunk in chunk_audio(audio, args.chunk_seconds, args.search_seconds):
|
| 169 |
+
chunk_owner.append(file_index)
|
| 170 |
+
requests.append({"prompt": prompt, "multi_modal_data": {"audio": (chunk, SAMPLE_RATE)}})
|
| 171 |
+
|
| 172 |
+
outputs = llm.generate(requests, sampling_params)
|
| 173 |
+
|
| 174 |
+
texts_per_file = [[] for _ in files]
|
| 175 |
+
languages_per_file = [Counter() for _ in files]
|
| 176 |
+
truncated_per_file = [0 for _ in files]
|
| 177 |
+
for file_index, output in zip(chunk_owner, outputs):
|
| 178 |
+
completion = output.outputs[0]
|
| 179 |
+
language, text = parse_output(completion.text)
|
| 180 |
+
if text:
|
| 181 |
+
texts_per_file[file_index].append(text)
|
| 182 |
+
if language:
|
| 183 |
+
languages_per_file[file_index][language] += 1
|
| 184 |
+
if completion.finish_reason == "length":
|
| 185 |
+
truncated_per_file[file_index] += 1
|
| 186 |
+
|
| 187 |
+
results = []
|
| 188 |
+
for file_index, file_path in enumerate(files):
|
| 189 |
+
full_text = " ".join(texts_per_file[file_index])
|
| 190 |
+
txt_path = output_path_for(file_path, input_dir, output_dir)
|
| 191 |
+
txt_path.parent.mkdir(parents=True, exist_ok=True)
|
| 192 |
+
txt_path.write_text(full_text + "\n", encoding="utf-8")
|
| 193 |
+
|
| 194 |
+
top_language = languages_per_file[file_index].most_common(1)
|
| 195 |
+
result = {
|
| 196 |
+
"file": str(file_path.relative_to(input_dir)),
|
| 197 |
+
"duration_s": round(durations[file_index], 1),
|
| 198 |
+
"chunks": chunk_owner.count(file_index),
|
| 199 |
+
"truncated_chunks": truncated_per_file[file_index],
|
| 200 |
+
"language": args.language or (top_language[0][0] if top_language else None),
|
| 201 |
+
"word_count": len(full_text.split()),
|
| 202 |
+
}
|
| 203 |
+
results.append(result)
|
| 204 |
+
logger.info(
|
| 205 |
+
f" {result['file']}: {result['duration_s']:.0f}s, {result['chunks']} chunks, "
|
| 206 |
+
f"{result['word_count']} words, language={result['language']}"
|
| 207 |
+
)
|
| 208 |
+
return results
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
def main():
|
| 212 |
+
parser = argparse.ArgumentParser(
|
| 213 |
+
description="Transcribe audio files with Reson8/Rumble-2-Flash via vLLM.",
|
| 214 |
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
| 215 |
+
epilog=__doc__,
|
| 216 |
+
)
|
| 217 |
+
parser.add_argument("input_dir", help="Directory containing audio files (searched recursively)")
|
| 218 |
+
parser.add_argument("output_dir", help="Directory for .txt transcripts and summary.jsonl")
|
| 219 |
+
parser.add_argument("--model", default=MODEL, help=f"Model id (default: {MODEL})")
|
| 220 |
+
parser.add_argument("--language", default=None, help='English language name, e.g. "Dutch". Omit to detect.')
|
| 221 |
+
parser.add_argument("--words-for-digits", action="store_true", help="Write numbers as words")
|
| 222 |
+
parser.add_argument("--keep-fillers", action="store_true", help='Keep fillers such as "um" and "uh"')
|
| 223 |
+
parser.add_argument("--no-verbatim", action="store_true", help="Collapse repeated words")
|
| 224 |
+
parser.add_argument("--chunk-seconds", type=float, default=30.0, help="Maximum chunk length (default: 30)")
|
| 225 |
+
parser.add_argument(
|
| 226 |
+
"--search-seconds",
|
| 227 |
+
type=float,
|
| 228 |
+
default=5.0,
|
| 229 |
+
help="Look this far back from the chunk limit for a quiet cut point (default: 5)",
|
| 230 |
+
)
|
| 231 |
+
parser.add_argument("--batch-files", type=int, default=32, help="Files loaded per vLLM call (default: 32)")
|
| 232 |
+
parser.add_argument("--max-files", type=int, default=None, help="Process at most this many files")
|
| 233 |
+
parser.add_argument("--overwrite", action="store_true", help="Redo files that already have a transcript")
|
| 234 |
+
parser.add_argument("--max-tokens", type=int, default=1024, help="Max new tokens per chunk (default: 1024)")
|
| 235 |
+
parser.add_argument("--max-model-len", type=int, default=4096, help="vLLM max model length (default: 4096)")
|
| 236 |
+
parser.add_argument("--gpu-memory-utilization", type=float, default=0.85)
|
| 237 |
+
args = parser.parse_args()
|
| 238 |
+
|
| 239 |
+
if args.search_seconds >= args.chunk_seconds:
|
| 240 |
+
parser.error("--search-seconds must be smaller than --chunk-seconds")
|
| 241 |
+
|
| 242 |
+
input_dir = Path(args.input_dir)
|
| 243 |
+
output_dir = Path(args.output_dir)
|
| 244 |
+
if not input_dir.is_dir():
|
| 245 |
+
logger.error(f"Input directory does not exist: {input_dir}")
|
| 246 |
+
sys.exit(1)
|
| 247 |
+
output_dir.mkdir(parents=True, exist_ok=True)
|
| 248 |
+
|
| 249 |
+
files = discover_audio_files(input_dir)
|
| 250 |
+
if not files:
|
| 251 |
+
logger.error(f"No audio files in {input_dir} ({', '.join(sorted(AUDIO_EXTENSIONS))})")
|
| 252 |
+
sys.exit(1)
|
| 253 |
+
if args.max_files:
|
| 254 |
+
files = files[: args.max_files]
|
| 255 |
+
todo = [f for f in files if args.overwrite or not output_path_for(f, input_dir, output_dir).exists()]
|
| 256 |
+
logger.info(f"Found {len(files)} audio file(s); {len(files) - len(todo)} already done, {len(todo)} to do")
|
| 257 |
+
if not todo:
|
| 258 |
+
return
|
| 259 |
+
|
| 260 |
+
from vllm import LLM, SamplingParams
|
| 261 |
+
|
| 262 |
+
logger.info(f"Loading {args.model} in vLLM {importlib.metadata.version('vllm')}...")
|
| 263 |
+
llm = LLM(
|
| 264 |
+
model=args.model,
|
| 265 |
+
max_model_len=args.max_model_len,
|
| 266 |
+
limit_mm_per_prompt={"audio": 1},
|
| 267 |
+
gpu_memory_utilization=args.gpu_memory_utilization,
|
| 268 |
+
)
|
| 269 |
+
# skip_special_tokens=False keeps <asr_text>, which separates the detected language from the text.
|
| 270 |
+
sampling_params = SamplingParams(temperature=0.0, max_tokens=args.max_tokens, skip_special_tokens=False)
|
| 271 |
+
prompt = build_prompt(llm.get_tokenizer(), args)
|
| 272 |
+
logger.info(f"Prompt: {prompt!r}")
|
| 273 |
+
|
| 274 |
+
summary_path = output_dir / "summary.jsonl"
|
| 275 |
+
total_audio_s = 0.0
|
| 276 |
+
start_time = time.time()
|
| 277 |
+
for batch_start in range(0, len(todo), args.batch_files):
|
| 278 |
+
batch = todo[batch_start : batch_start + args.batch_files]
|
| 279 |
+
logger.info(f"Batch {batch_start // args.batch_files + 1}: {len(batch)} file(s)")
|
| 280 |
+
results = transcribe_batch(llm, sampling_params, prompt, batch, args, input_dir, output_dir)
|
| 281 |
+
with open(summary_path, "a", encoding="utf-8") as summary_file:
|
| 282 |
+
for result in results:
|
| 283 |
+
summary_file.write(json.dumps(result) + "\n")
|
| 284 |
+
total_audio_s += sum(r["duration_s"] for r in results)
|
| 285 |
+
|
| 286 |
+
elapsed = time.time() - start_time
|
| 287 |
+
logger.info("=" * 50)
|
| 288 |
+
logger.info(f"Transcribed {len(todo)} file(s), {total_audio_s / 60:.1f} min of audio, in {elapsed:.1f}s")
|
| 289 |
+
logger.info(f" RTFx (load + chunk + transcribe): {total_audio_s / elapsed:.0f}x realtime")
|
| 290 |
+
logger.info(f" Output: {output_dir} Summary: {summary_path}")
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
if __name__ == "__main__":
|
| 294 |
+
main()
|