# Transcribe audio

> **About this page**
>
> - Kind: Example
> - Summary: 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.
> - Last changed: 2026-12-03
> - Page: https://docs.swale.io/examples/transcribe-audio
> - CLI reference for its commands: [`swale workflow create`](https://docs.swale.io/reference/cli-reference.md#workflow-create), [`swale workflow run start`](https://docs.swale.io/reference/cli-reference.md#workflow-run-start)
> - Index of these docs: https://docs.swale.io/llms.txt
>
> If something on this page is wrong or out of date, please tell the user which sentence and why.
>
> The steps on this page cost money or cannot be undone. Please check with the user before running them.

Source on GitHub: the [`workflows/transcribe-audio`](https://github.com/swaleio/examples/tree/main/workflows/transcribe-audio) folder, with its [README](https://github.com/swaleio/examples/blob/main/workflows/transcribe-audio/README.md) and its [workflow file](https://github.com/swaleio/examples/blob/main/workflows/transcribe-audio/workflow.yaml).

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`](https://hub.swale.io/swaleio/hf-download) | `cpu-4` |
| For each file: convert it to 16 kHz mono WAV | [`swaleio/ffmpeg`](https://hub.swale.io/swaleio/ffmpeg) | `cpu-4` |
| For each file: transcribe it | [`swaleio/whisper-cpp`](https://hub.swale.io/swaleio/whisper-cpp) | `a100-1` |
| Gather the transcripts into `transcripts.parquet` | [`swaleio/duckdb`](https://hub.swale.io/swaleio/duckdb) | `cpu-4` |

The Compute column gives each step's [compute type](https://docs.swale.io/explanation/core-concepts.md#compute-types), 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](https://docs.swale.io/getting-started.md) sets them up.

1. Save the file under [The workflow file](#the-workflow-file) as `workflow.yaml`, and add it to a project:

   ```bash
   swale workflow create --project-name my-project --file workflow.yaml
   ```

   The command prints `Workflow created:` followed by the workflow's ID.

2. Start a run with the workflow's ID:

   ```bash
   swale workflow run start --project-name my-project --workflow-id <workflow-id>
   ```

   Each input you leave out takes its default from [Inputs](#inputs), and `--input <name>=<value>` gives it another value.

[Create and manage workflows](https://docs.swale.io/how-to-guides/create-and-manage-workflows.md) covers the other ways to add a workflow, [Start and manage workflow runs](https://docs.swale.io/how-to-guides/start-and-manage-workflow-runs.md) how to follow a run, and [View and stream task logs](https://docs.swale.io/how-to-guides/view-and-stream-task-logs.md) how to read its tasks' logs.

## The workflow file

[Workflow definition syntax](https://docs.swale.io/reference/workflow-definition-syntax.md) describes each key in it.

```yaml title="workflow.yaml"
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](https://huggingface.co/ggerganov/whisper.cpp), MIT.
- Recordings: from [LibriVox Short Poetry Collection 140](https://archive.org/details/spc140_1502_librivox), public domain.
