Transcribe audio
Source on GitHub: the workflows/transcribe-audio folder, with its README and its workflow file.
Transcribes a list of audio or video files with whisper.cpp. Each file is converted to 16 kHz mono WAV with FFmpeg and transcribed in its own pair of tasks, all files at the same time, into plain text and SubRip, WebVTT and JSON subtitles. A last step gathers each file's text and subtitles into one Parquet file.
| Step | Task definition | Compute |
|---|---|---|
| Fetch the whisper.cpp model | swaleio/hf-download | cpu-4 |
| For each file: convert it to 16 kHz mono WAV | swaleio/ffmpeg | cpu-4 |
| For each file: transcribe it | swaleio/whisper-cpp | a100-1 |
Gather the transcripts into transcripts.parquet | swaleio/duckdb | cpu-4 |
The Compute column gives each step's compute type, the compute its tasks are allocated.
Every step is its own task. whisper.cpp also runs on a CPU compute type, many
times slower; give the transcribe task cpu-16 and a smaller model, such as
ggml-base.en.bin, to transcribe without a GPU.
Inputs
| Input | Default | Description |
|---|---|---|
media_urls | three poems read for LibriVox | The files, as a JSON array of URLs or workspace paths. |
whisper_model | ggml-large-v3-turbo-q5_0.bin | Model file in ggerganov/whisper.cpp. |
language | auto | Two-letter language code, or auto to detect it. |
Output
transcripts.parquet on the workspace, with each file's source, text and
srt, and every transcript format in transcripts/.
Run it
You need the CLI, logged in to your account, and a project to add the workflow to; Getting started sets them up.
-
Save the file under The workflow file as
workflow.yaml, and add it to a project:swale workflow create --project-name my-project --file workflow.yamlThe command prints
Workflow created:followed by the workflow's ID. -
Start a run with the workflow's ID:
swale workflow run start --project-name my-project --workflow-id <workflow-id>Each input you leave out takes its default from Inputs, and
--input <name>=<value>gives it another value.
Create and manage workflows covers the other ways to add a workflow, Start and manage workflow runs how to follow a run, and View and stream task logs how to read its tasks' logs.
The workflow file
Workflow definition syntax describes each key in it.
name: Transcribe audio
description: Transcribes a list of audio or video files with whisper.cpp, one task per file, into text and subtitles, and collects the transcripts into one Parquet file.
compute_type: cpu-4
inputs:
media_urls:
description: The audio or video files, as a JSON array of URLs or workspace paths; anything FFmpeg reads.
default: '["https://archive.org/download/spc140_1502_librivox/spc140_blackvulture_wt_64kb.mp3", "https://archive.org/download/spc140_1502_librivox/spc140_gethsemane_db_64kb.mp3", "https://archive.org/download/spc140_1502_librivox/spc140_fromonewhostays_ss_64kb.mp3"]'
whisper_model:
description: File name of the whisper.cpp model in ggerganov/whisper.cpp on the Hugging Face Hub.
default: ggml-large-v3-turbo-q5_0.bin
language:
description: Spoken language as a two-letter code, or auto.
default: auto
entry_point: main
blocks:
main:
tasks:
fetch_model:
name: Fetch whisper model
uses: swaleio/hf-download
args:
repo: ggerganov/whisper.cpp
include: ${{inputs.whisper_model}}
dest: ${{env.WORKFLOW_STORAGE}}/whisper
each_file:
name: Transcribe each file
start_on:
- fetch_model
for_each:
items: ${{inputs.media_urls}}
block: transcribe_one
collect:
name: Collect transcripts
uses: swaleio/duckdb
start_on:
- each_file
args:
sql: |
CREATE TABLE transcripts AS
WITH sources AS (
SELECT unnest(from_json($$${{inputs.media_urls}}$$, '["VARCHAR"]')) AS source,
generate_subscripts(from_json($$${{inputs.media_urls}}$$, '["VARCHAR"]'), 1) - 1 AS item)
SELECT s.source, txt.content AS text, srt.content AS srt
FROM sources s
JOIN read_text('${{env.WORKFLOW_STORAGE}}/transcripts/*.txt') txt
ON regexp_extract(txt.filename, '(\d+)\.txt$', 1)::INT = s.item
JOIN read_text('${{env.WORKFLOW_STORAGE}}/transcripts/*.srt') srt
ON regexp_extract(srt.filename, '(\d+)\.srt$', 1)::INT = s.item
ORDER BY s.item;
SELECT source, left(trim(text), 80) AS beginning FROM transcripts;
COPY transcripts TO '${{env.WORKFLOW_STORAGE}}/transcripts.parquet' (FORMAT parquet);
transcribe_one:
tasks:
to_wav:
name: Convert to 16 kHz WAV
uses: swaleio/ffmpeg
args:
script: |
set -euo pipefail
mkdir -p "$WORKFLOW_STORAGE/wav" "$WORKFLOW_STORAGE/transcripts"
ffmpeg -hide_banner -loglevel error -i "${{tasks.each_file.for_each.item}}" \
-vn -ac 1 -ar 16000 -c:a pcm_s16le "$WORKFLOW_STORAGE/wav/${{tasks.each_file.for_each.index}}.wav"
transcribe:
name: Transcribe
uses: swaleio/whisper-cpp
compute_type: a100-1
start_on:
- to_wav
args:
model: ${{env.WORKFLOW_STORAGE}}/whisper/${{inputs.whisper_model}}
audio: ${{env.WORKFLOW_STORAGE}}/wav/${{tasks.each_file.for_each.index}}.wav
output_prefix: ${{env.WORKFLOW_STORAGE}}/transcripts/${{tasks.each_file.for_each.index}}
language: ${{inputs.language}}
Licenses of the defaults
- Model: ggerganov/whisper.cpp, MIT.
- Recordings: from LibriVox Short Poetry Collection 140, public domain.