Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AI Builder Club Skills extract words

From Leeroopedia
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

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")

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment