# Audio and Video Transcription

> Automatic Speech Recognition over audio and video streams using faster-whisper (CTranslate2-backed Whisper).

Source: https://docs.sommatic.ai/en/nodes/ai.transcribe/

- Slug: `ai.transcribe`
- Family: AI
- Version: 1.0.0
- Status: Available
- Execution: async

Automatic Speech Recognition over audio and video streams using faster-whisper (CTranslate2-backed Whisper).

Single-pass decoding on CPU with configurable model size, beam width, and language hint. Suitable for utility-grade transcription of meetings, voicemails, and short-form media. For speaker diarization, 100+ locales, or custom vocabulary, use `connectors.microsoft.azure.speech`.

**Features:**
- **Model selection:** `tiny`, `base` (default), or `small`. Larger models increase accuracy at the cost of latency and memory.
- **Beam search:** Configurable beam size; beam > 1 improves transcription quality on noisy input at a linear cost.
- **Language:** ISO 639-1 hint (`es`, `en`, `pt`, ...) or auto-detection from the first 30 seconds of audio.
- **Word timestamps:** Optional per-segment timestamps for subtitle generation, chaptering, or evidence anchoring.
- **Input formats:** mp3, wav, m4a, ogg, flac, mp4, mov, webm. Container demuxing and PCM resampling to 16 kHz handled internally via ffmpeg.
- **Silent input handling:** Emits port `empty` when Voice Activity Detection finds no speech in the stream.

## Configuration

- `model_size` (string, optional): CPU-friendly model sizes. Larger requires more memory and time. Default: `base`. Allowed values: `tiny`, `base`, `small`.
- `language` (string, optional): Language hint (e.g., es, en, pt). Leave empty to auto-detect.
- `word_timestamps` (boolean, optional): Emit per-segment timestamps in the output. Default: `false`.
- `beam_size` (number, optional): Higher values improve quality at the cost of speed. Default: `1`.

Its configuration shows the shared execution settings, but this node does not apply retries (`retryOnFail`, `maxTries`) yet. `continueOnFail` is not applied by any node.

## Output ports

- `extracted` (default): Transcribed
- `empty`: No Speech
- `error`: Error

## Input contract

- `content_base64` (string, optional): Audio/video content base64-encoded.
- `file_path` (string, optional): Alternative: local file path.

## Output contract

- `text` (string, optional): Full transcribed text.
- `chars` (number, optional)
- `empty` (boolean, optional)
- `method` (string, optional)
- `metadata` (object, optional)
- `segments` (array, optional)

## In expressions

What a later node can read from this node's output with `$("Audio and Video Transcription").item.json.<path>` (write your node's label instead of `Audio and Video Transcription`). **Editor** marks the paths the workflow editor suggests under Previous Nodes (the output contract); **Worker** marks the paths the worker really returns through `extracted`, from the output shown in Ports.

- `$("Audio and Video Transcription").item.json.text` (string) = `"Hello, this is a reminder about tomorrow’s d…"`: Full transcribed text.
- `$("Audio and Video Transcription").item.json.chars` (number) = `59`
- `$("Audio and Video Transcription").item.json.empty` (boolean) = `false`
- `$("Audio and Video Transcription").item.json.method` (string) = `"faster-whisper-base"`
- `$("Audio and Video Transcription").item.json.metadata` (object) = `{…}`
- `$("Audio and Video Transcription").item.json.segments` (array) = `[…] (1)`
- `$("Audio and Video Transcription").item.json.metadata.language` (string) = `"en"` (Not suggested by the editor)
- `$("Audio and Video Transcription").item.json.metadata.language_probability` (number) = `0.98` (Not suggested by the editor)
- `$("Audio and Video Transcription").item.json.metadata.duration_seconds` (number) = `4.2` (Not suggested by the editor)
- `$("Audio and Video Transcription").item.json.metadata.segments_count` (number) = `1` (Not suggested by the editor)


## How it works

Transcribes audio or video on CPU with faster-whisper (int8) and returns the full text, the detected language and, when `word_timestamps` is on, timed segments.

1. Resolves the node config: expressions in config keys are evaluated against the run; the incoming item is used as-is.
2. Reads `content_base64` or `file_path` from the config first, then from the incoming item. If neither is present it returns `error`.
3. In Python, an existing `file_path` is used directly; otherwise the base64 bytes are written to a temporary file.
4. Loads the Whisper model `model_size` (default `base`) and transcribes with `language` (empty = auto-detect), `beam_size` (default 1) and `word_timestamps`.
5. Joins the segment texts with spaces into `text`. `segments` is filled only when `word_timestamps` is `true`.
6. Python failures return `error`; an empty transcript returns `empty`; anything else `extracted`.

## In a workflow

### Node

```json
{
  "node_id": "node-transcribe",
  "label": "Transcribe voicemail",
  "operator_slug": "ai.transcribe",
  "operator_version": "1.0.0",
  "config": {
    "model_size": "base",
    "language": "en",
    "word_timestamps": true,
    "beam_size": 1,
    "execution": {
      "timeout_ms": 900000
    }
  }
}
```

### Envelope

```json
{
  "ok": true,
  "port": "extracted",
  "data": {
    "text": "Hello, this is a reminder about tomorrow’s delivery window.",
    "chars": 59,
    "empty": false,
    "method": "faster-whisper-base",
    "metadata": {
      "language": "en",
      "language_probability": 0.98,
      "duration_seconds": 4.2,
      "segments_count": 1
    },
    "segments": [
      {
        "start": 0,
        "end": 4.1,
        "text": "Hello, this is a reminder about tomorrow’s delivery window."
      }
    ]
  }
}
```

## Output ports (behaviour in the code)

### `extracted`

The transcript has text.

```json
{
  "text": "Hello, this is a reminder about tomorrow’s delivery window.",
  "chars": 59,
  "empty": false,
  "method": "faster-whisper-base",
  "metadata": {
    "language": "en",
    "language_probability": 0.98,
    "duration_seconds": 4.2,
    "segments_count": 1
  },
  "segments": [
    {
      "start": 0,
      "end": 4.1,
      "text": "Hello, this is a reminder about tomorrow’s delivery window."
    }
  ]
}
```

### `empty`

The model returned no text (silence or no speech). Same shape with `text: ""`.

```json
{
  "text": "",
  "chars": 0,
  "empty": true,
  "method": "faster-whisper-base",
  "metadata": {
    "language": "en",
    "language_probability": 0.41,
    "duration_seconds": 12,
    "segments_count": 0
  },
  "segments": []
}
```

### `error`

The input is missing or the script fails. `data` is `{ error }` or `{ error, stderr }`.

```json
{
  "error": "Python timed out after 900000ms",
  "stderr": ""
}
```

## Behaviour in the code

- `word_timestamps`: When `true`, `segments` lists `{ start, end, text }` per segment, in seconds. Word-level timings are not returned. When `false`, `segments` is `[]`.
- `language`: ISO 639-1 hint. Leave it empty to auto-detect; the detected code is in `metadata.language`.
- `execution.timeout_ms`: Timeout of the Python run. When unset the code uses 900000 ms (15 min); the schema shows 300000.
- `content_base64 / file_path`: Not declared in the config schema, but read from the config before the incoming item. Use them to point at a file with an expression, e.g. `{{ $json.attachment.content_base64 }}`.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `Either content_base64 or file_path is required.` | `error` | Neither the config nor the incoming item has `content_base64` or `file_path`. Map the file from the previous node. |
| `Either content_base64 or file_path is required` | `error` | Raised by the Python script when `file_path` does not exist on the orchestrator host. Data also carries `stderr`. |
| `<faster-whisper or decoder error>` | `error` | The file cannot be decoded as audio or video, or the model could not be loaded on the host. |
| `Python timed out after <timeout_ms>ms` | `error` | The script exceeded `execution.timeout_ms`. Raise it or process fewer pages. |
| `Python runtime not available (ENOENT)` | `error` | No Python interpreter is available on the orchestrator host. |

## Notes and limits

- Each run is a new Python process, so the model is loaded on every run; larger `model_size` values add memory and start-up time.
- No voice activity filter is configured: `empty` means the model produced no text, not that a VAD step found silence.
- No speaker diarization and no custom vocabulary.
- `file_path` is a path on the orchestrator host. `content_base64` wins when both are present.
- The extraction runs in a Python subprocess. On first use the orchestrator creates a virtual environment and installs the pinned requirements, which can take minutes; later runs reuse it.
- The Python result is limited to 50 MB of output; above it the node leaves through `error`.
- The engine does not apply `execution.retryOnFail`, `maxTries`, `waitBetweenTries` or `continueOnFail` to this node. Handle failures by wiring the `error` port.


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "ai.transcribe",
  "name": "Audio and Video Transcription",
  "category": "ai",
  "version": "1.0.0",
  "description": "Automatic Speech Recognition over audio and video streams using faster-whisper (CTranslate2-backed Whisper).\n\n  Single-pass decoding on CPU with configurable model size, beam width, and language hint. Suitable for utility-grade transcription of meetings, voicemails, and short-form media. For speaker diarization, 100+ locales, or custom vocabulary, use `connectors.microsoft.azure.speech`.\n\n  **Features:**\n  - **Model selection:** `tiny`, `base` (default), or `small`. Larger models increase accuracy at the cost of latency and memory.\n  - **Beam search:** Configurable beam size; beam > 1 improves transcription quality on noisy input at a linear cost.\n  - **Language:** ISO 639-1 hint (`es`, `en`, `pt`, ...) or auto-detection from the first 30 seconds of audio.\n  - **Word timestamps:** Optional per-segment timestamps for subtitle generation, chaptering, or evidence anchoring.\n  - **Input formats:** mp3, wav, m4a, ogg, flac, mp4, mov, webm. Container demuxing and PCM resampling to 16 kHz handled internally via ffmpeg.\n  - **Silent input handling:** Emits port `empty` when Voice Activity Detection finds no speech in the stream.",
  "capabilities": [
    "asr",
    "speech-to-text",
    "audio",
    "video",
    "transcription"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "model_size": {
        "type": "string",
        "title": "Whisper Model Size",
        "enum": [
          "tiny",
          "base",
          "small"
        ],
        "default": "base",
        "description": "CPU-friendly model sizes. Larger requires more memory and time."
      },
      "language": {
        "type": "string",
        "title": "Language (ISO 639-1)",
        "description": "Language hint (e.g., es, en, pt). Leave empty to auto-detect."
      },
      "word_timestamps": {
        "type": "boolean",
        "title": "Word Timestamps",
        "default": false,
        "description": "Emit per-segment timestamps in the output."
      },
      "beam_size": {
        "type": "number",
        "title": "Beam Size",
        "default": 1,
        "description": "Higher values improve quality at the cost of speed."
      },
      "execution": {
        "type": "object",
        "title": "Execution Settings",
        "properties": {
          "alwaysOutputData": {
            "type": "boolean",
            "title": "Always Output Data",
            "description": "Always output data, even on error (if configured).",
            "default": false
          },
          "retryOnFail": {
            "type": "boolean",
            "title": "Retry On Fail",
            "description": "Retry the execution if it fails.",
            "default": false
          },
          "maxTries": {
            "type": "integer",
            "title": "Max Retries",
            "description": "Number of retries.",
            "default": 3,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "waitBetweenTries": {
            "type": "integer",
            "title": "Wait Between Retries (ms)",
            "default": 1000,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "continueOnFail": {
            "type": "boolean",
            "title": "Continue On Fail",
            "description": "Do not crash workflow on error.",
            "default": false
          },
          "timeout_ms": {
            "type": "integer",
            "title": "Timeout (ms)",
            "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
            "default": 300000
          }
        }
      }
    }
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "content_base64": {
        "type": "string",
        "description": "Audio/video content base64-encoded."
      },
      "file_path": {
        "type": "string",
        "description": "Alternative: local file path."
      }
    }
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "text": {
        "type": "string",
        "description": "Full transcribed text."
      },
      "chars": {
        "type": "number"
      },
      "empty": {
        "type": "boolean"
      },
      "method": {
        "type": "string"
      },
      "metadata": {
        "type": "object"
      },
      "segments": {
        "type": "array"
      }
    }
  },
  "ports": [
    {
      "port_id": "extracted",
      "label": "Transcribed",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "empty",
      "label": "No Speech",
      "is_default": false,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "tags": [
    "ai",
    "asr",
    "audio",
    "video",
    "whisper",
    "transcription"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://me.veripass.com/sommatic",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "model_size": {
      "type": "string",
      "title": "Whisper Model Size",
      "enum": [
        "tiny",
        "base",
        "small"
      ],
      "default": "base",
      "description": "CPU-friendly model sizes. Larger requires more memory and time."
    },
    "language": {
      "type": "string",
      "title": "Language (ISO 639-1)",
      "description": "Language hint (e.g., es, en, pt). Leave empty to auto-detect."
    },
    "word_timestamps": {
      "type": "boolean",
      "title": "Word Timestamps",
      "default": false,
      "description": "Emit per-segment timestamps in the output."
    },
    "beam_size": {
      "type": "number",
      "title": "Beam Size",
      "default": 1,
      "description": "Higher values improve quality at the cost of speed."
    },
    "execution": {
      "type": "object",
      "title": "Execution Settings",
      "properties": {
        "alwaysOutputData": {
          "type": "boolean",
          "title": "Always Output Data",
          "description": "Always output data, even on error (if configured).",
          "default": false
        },
        "retryOnFail": {
          "type": "boolean",
          "title": "Retry On Fail",
          "description": "Retry the execution if it fails.",
          "default": false
        },
        "maxTries": {
          "type": "integer",
          "title": "Max Retries",
          "description": "Number of retries.",
          "default": 3,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "waitBetweenTries": {
          "type": "integer",
          "title": "Wait Between Retries (ms)",
          "default": 1000,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "continueOnFail": {
          "type": "boolean",
          "title": "Continue On Fail",
          "description": "Do not crash workflow on error.",
          "default": false
        },
        "timeout_ms": {
          "type": "integer",
          "title": "Timeout (ms)",
          "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
          "default": 300000
        }
      }
    }
  }
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "content_base64": {
      "type": "string",
      "description": "Audio/video content base64-encoded."
    },
    "file_path": {
      "type": "string",
      "description": "Alternative: local file path."
    }
  }
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "text": {
      "type": "string",
      "description": "Full transcribed text."
    },
    "chars": {
      "type": "number"
    },
    "empty": {
      "type": "boolean"
    },
    "method": {
      "type": "string"
    },
    "metadata": {
      "type": "object"
    },
    "segments": {
      "type": "array"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "extracted",
    "label": "Transcribed",
    "is_default": true,
    "supports_condition": true
  },
  {
    "port_id": "empty",
    "label": "No Speech",
    "is_default": false,
    "supports_condition": true
  },
  {
    "port_id": "error",
    "label": "Error",
    "is_default": false,
    "supports_condition": false
  }
]
```
