Implementation:AI Builder Club Skills extract words
| Knowledge Sources | |
|---|---|
| Domains | Speech_Recognition, Video_Processing |
| Last Updated | 2026-10-24 00:00 GMT |
Overview
Concrete tool for extracting word-level timestamps from audio or video using MLX Whisper, provided by the karaoke-captions skill.
Description
The extract_words.py script wraps mlx_whisper.transcribe() with word-level timestamp extraction. It takes an audio or video file, runs MLX Whisper transcription on Apple Silicon, and emits a JSON file containing one entry per spoken word with start/end times rounded to two decimal places. This is the first stage of the karaoke captions pipeline — its output feeds directly into gen_ass for ASS subtitle generation.
Usage
Import or run this script when you need word-level timing data from spoken audio for karaoke-style caption generation. Requires Apple Silicon (MLX runtime).
Code Reference
Source Location
- Repository: AI Builder Club Skills
- File: skills/karaoke-captions/scripts/extract_words.py
Signature
def main():
"""CLI entry point for word timestamp extraction.
Args (via argparse):
input: str - Path to input audio or video file
output: str - Output JSON path (default: "words.json")
--model: str - HF repo or local model path
(default: "mlx-community/whisper-large-v3-turbo")
--language: str - Language code e.g. "en", "zh" (default: None = auto-detect)
Returns:
Writes words.json to disk. Exits on missing input or missing mlx_whisper.
"""
# Underlying API called:
mlx_whisper.transcribe(
str(input_path),
path_or_hf_repo=str(model), # e.g. "mlx-community/whisper-large-v3-turbo"
word_timestamps=True,
verbose=False,
language=str | None, # optional, e.g. "en"
) -> dict # {"segments": [{"words": [{"word", "start", "end"}]}]}
Import
# Run as a CLI script:
# python extract_words.py input.mp4 [output.json] [--model MODEL] [--language LANG]
# Or import the underlying library:
import mlx_whisper
result = mlx_whisper.transcribe(audio_path, path_or_hf_repo=model, word_timestamps=True)
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| input | str (file path) | Yes | Path to input audio or video file (e.g. input.mp4)
|
| output | str (file path) | No | Output JSON path (default: words.json)
|
| --model | str | No | HF repo or local model path (default: mlx-community/whisper-large-v3-turbo)
|
| --language | str | No | Language code, e.g. en, zh (default: auto-detect)
|
Outputs
| Name | Type | Description |
|---|---|---|
| words.json | JSON file | {"words": [{"word": str, "start": float, "end": float}, ...]} — word-level timestamps, rounded to 2 decimal places
|
Usage Examples
Basic Word Extraction
# Extract word timestamps from a video file
python extract_words.py input.mp4
# Output: words.json
# {"words": [{"word": "TERMS", "start": 1.23, "end": 1.55}, ...]}
With Language Hint and Custom Model
# Transcribe Chinese audio with a specific model
python extract_words.py interview.mp4 words_zh.json \
--model mlx-community/whisper-large-v3 \
--language zh
Programmatic Access to Underlying API
import mlx_whisper
result = mlx_whisper.transcribe(
"input.mp4",
path_or_hf_repo="mlx-community/whisper-large-v3-turbo",
word_timestamps=True,
verbose=False,
language="en",
)
words = []
for seg in result.get("segments", []):
for w in seg.get("words", []):
word_str = w.get("word", "").strip()
if word_str:
words.append({
"word": word_str,
"start": round(float(w["start"]), 2),
"end": round(float(w["end"]), 2),
})
print(f"Extracted {len(words)} words")