Skip to content

About

Audio, video and PDF to text with Cloudflare Workers AI, Groq or Gemini, a local engine fallback and a spend cap.

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

transcribe

Transcribe local audio and video to Markdown or extract text from digital PDFs. Media can use Cloudflare Workers AI, a local engine, Groq or Gemini. PDFs are processed locally with PyMuPDF.

Install

Install Python 3.12 or later and put ffmpeg and ffprobe on PATH (for example, apt-get install ffmpeg on Debian). From the checkout:

python3 -m pip install .

With uv, use uv tool install . for an isolated installation. transcribe doctor --json reports the version, tools and provider setup. transcribe selftest runs offline fixtures.

Usage

transcribe sample.ogg -l es -c "Workshop vocabulary" --dry-run --json
transcribe sample.ogg --provider local --text
transcribe ./samples -r --dry-run --json
transcribe sample.pdf --out sample.md --json
transcribe sample.mp4 --timestamps

A plain media run uses the configured provider chain. Use --dry-run to preview files, durations, chunks and estimated spend before uploading. PDF extraction reads the text already present in the document. Scanned or protected pages produce an incomplete Markdown file with the affected pages identified.

--out accepts a directory or a Markdown filename for a single source. Default filenames use the source name and a hash. Finished matching outputs are skipped. --force preserves the old version with a .prevN suffix. The metadata header records the source digest, engine and completion status. Treat that header as local data if it contains private paths or hints.

--text prints one transcript to stdout and still writes the Markdown. When the source name is private (a phone number, a person), point --out at a private temporary directory you delete afterwards: --text then leaves nothing in the default data directory, and the Markdown name and header stay in that directory. --allow-empty makes a recording without speech a result (exit 0, nothing written, empty stdout under --text) instead of exit 1:

tmp=$(mktemp -d) && transcribe call.m4a --text --allow-empty --out "$tmp"; rm -rf "$tmp"

--timestamps produces timed Markdown and an SRT alongside it with a provider that supports timing. The local command returns plain text. --json writes one schema-version-2 envelope. Progress goes to stderr.

Providers and configuration

Environment variables override the optional config at ${XDG_CONFIG_HOME:-~/.config}/transcribe/config. That file holds non-secret settings. The environment and the optional dotenv file named by TRANSCRIBE_ENV_FILE hold credentials. doctor reports setting names and resolved paths.

  • TRANSCRIBE_PROVIDERS or --provider sets the ordered chain. The default is cloudflare,local. --model requires exactly one provider.
  • Cloudflare uses the daily free allowance before the local monthly cap. Set TRANSCRIBE_CF_MONTHLY_CAP_USD=0 for free allowance only. The ledger covers runs sharing the same XDG state directory.
  • TRANSCRIBE_LOCAL_CMD runs an executable without a shell. Its {input} is a mono 16 kHz FLAC and it must write to {output}. An optional {language} receives the language hint.
  • Groq is opt-in. Set TRANSCRIBE_GROQ_KEYS to the environment variable names in rotation order or use GROQ_API_KEY. The client rotates away from refused or throttled keys and persists cooldowns in XDG state.
  • Gemini is opt-in. Use TRANSCRIBE_GEMINI_KEYS or GEMINI_API_KEY. It stream-copies pieces of compatible audio codecs, validates each response, and falls back by piece. Its timed output reflects the model's stamp granularity. TRANSCRIBE_GEMINI_MODELS lists the models best first (model[:rpm], default 5 requests a minute); a piece uses the best model that some key can still serve, and limits are tracked per key and model.
  • TRANSCRIBE_LANG sets the language hint for runs without --lang; it takes the same comma list (es,ro).
  • Gemini speed or quality: by default a request that is not answered within 10 + seconds/2 s (at most 300) steps down to the next model, and a model that misses it is skipped by every run for an hour. The big models can take 80-200 s for a 23 s clip, so background callers that want them use --patient or TRANSCRIBE_GEMINI_PATIENT=1: the deadline is max(600, 3 x seconds), a miss steps down for that piece only, and the shared hour-long skip is neither written nor obeyed.

Output and locks use the XDG data and cache directories. The spend ledger and cooldowns use the XDG state directory. Review the JSON billing status before retrying an upload with an unverified outcome.

Diagnostics

transcribe doctor --json is offline. With Groq selected, transcribe doctor --live --json makes a single model-catalogue GET without uploading media. transcribe selftest --live exercises local preview and PDF extraction.

  • 0 — Success, skipped output or preview
  • 1 — Local failure or incomplete output
  • 2 — Invalid arguments or missing input
  • 3 — Provider authentication failure
  • 4 — Provider rejection, schema change, unavailable connection or unverified upload
  • 5 — Rate limit, access block or budget refusal

Command reference

transcribe

 Usage: transcribe [OPTIONS] {paths}...

 Transcribe each audio/video to a markdown file (local PDFs extracted to text).

╭─ Arguments ──────────────────────────────────────────────────────────────────────────────────────╮
│ *    paths      <path>  Audio/video/PDF files or folders [required]                              │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Options ────────────────────────────────────────────────────────────────────────────────────────╮
│ --lang         -l      <str>               ISO language hint, e.g. es/ro/en; a comma list        │
│                                            (es,ro) for speakers who mix them (Gemini hint;       │
│                                            others auto-detect). Default: TRANSCRIBE_LANG         │
│ --context      -c      <str>               Names/jargon to bias spelling (≤224 tok)              │
│ --provider             <str>               Comma list overriding TRANSCRIBE_PROVIDERS (default   │
│                                            cloudflare,local): cloudflare, local, groq, gemini    │
│                                            (opt-in)                                              │
│ --model                <str>               Model id of the one provider named by --provider      │
│ --out          -o      <path>              Output dir, or FILE.md for one source. Defaults to    │
│                                            the XDG data directory.                               │
│ --jobs                 <int range> [x>=1]  Concurrent files (>= 1) [default: 1]                  │
│ --vad                                      Enable Cloudflare voice activity filtering            │
│ --recursive    -r                          Recurse into folders                                  │
│ --force                                    Re-process even if .md exists (previous kept as       │
│                                            .prevN, never deleted)                                │
│ --dry-run                                  List files, provider, durations, chunks, estimated    │
│                                            audio seconds and cost; no API call, no output        │
│                                            written                                               │
│ --json                                     Print one JSON envelope on stdout (progress goes to   │
│                                            stderr)                                               │
│ --text                                     One source: print only the transcript on stdout       │
│                                            (progress and errors go to stderr); the .md is still  │
│                                            written                                               │
│ --timestamps                               Audio/video: timestamps (hh:mm:ss per segment) in the │
│                                            .md plus a .srt subtitle file next to it              │
│ --patient                                  Gemini: wait up to max(600 s, 3x the audio) for the   │
│                                            best model instead of stepping down after ~10 s +     │
│                                            half the audio; for background callers. Default:      │
│                                            TRANSCRIBE_GEMINI_PATIENT=1                           │
│ --allow-empty                              A recording without speech is not an error: exit 0,   │
│                                            nothing written, empty stdout under --text            │
│ --help         -h                          Show this message and exit.                           │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯

 Output: $XDG_DATA_HOME/transcribe/{stem}__{sha256-12}.md (deterministic per source)
 --provider: cloudflare,local by default (Cloudflare under a local spend cap, then a local engine);
 groq (keys rotated, TRANSCRIBE_GROQ_KEYS) and gemini (keys rotated, TRANSCRIBE_GEMINI_KEYS; models
 in order, TRANSCRIBE_GEMINI_MODELS; 10-min pieces, stamped) only when named or set in
 TRANSCRIBE_PROVIDERS.
 --text: print just the transcript on stdout.
 --model: model id of the one provider named by --provider (for gemini it replaces the model
 chain).
 --context: names/jargon for spelling bias (≤224 tokens).
 --force: re-processes existing outputs and keeps the previous one as <output>.prevN — never
 deletes.
 Cost: a plain run uploads media to Cloudflare Workers AI within the spend cap
 (TRANSCRIBE_CF_MONTHLY_CAP_USD), else runs the local engine; sources with a finished output are
 skipped; --dry-run previews provider, seconds and cost without any API call.

 Health check: transcribe doctor [--live] [--json] (offline: ffmpeg, secret names, paths,
 cool-down, Cloudflare budget; --live adds one free Groq GET /models, no audio)

 Self-test: transcribe selftest [--live] (safe local checks only)

 Examples:
   transcribe audio.ogg -l es -c "Workshop vocabulary"
   transcribe ./folder -r -l es -c "context"
   transcribe informe.pdf

transcribe doctor

Usage: transcribe doctor [--live] [--json]

Offline setup report: tools, secret NAMES, Groq key states, auth_source, paths, cool-down, exit codes.
  --live  one GET /models call to Groq with the first usable key (no audio, not billed)
  --json  one JSON envelope on stdout

transcribe selftest

Usage: transcribe selftest [--live] [--json]

Run built-in offline checks. --live exercises real local PDF and preview commands.
  --json  one JSON envelope on stdout

Development

uv sync --locked
uv run --locked pytest
uv run --locked python scripts/command-inventory.py --check

Update the command reference with uv run --locked python scripts/command-inventory.py. The tests block network sockets. scripts/differential.py compares local PDF extraction with Poppler.

See the changelog, MIT license and security reporting instructions.

About

Audio, video and PDF to text with Cloudflare Workers AI, Groq or Gemini, a local engine fallback and a spend cap.

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages