> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zeroruntime.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Assemblyai

> Python API reference for the assemblyai speech-to-text plugin.

<Card title="Usage guide" icon="book" href="/plugins/stt/assemblyai" horizontal>
  Setup, environment variables, and Python/JavaScript/Go usage examples.
</Card>

## AssemblyAISTT

AssemblyAI real-time streaming speech-to-text via WebSocket.

Uses the AssemblyAI Streaming Speech-to-Text API (WebSocket) with built-in
end-of-turn detection, key-term boosting, and optional automatic language
detection.

### Constructor

```python theme={null}
AssemblyAISTT(*, api_key: 'str | None' = None, speech_model: 'AssemblyAISTTModel | str' = 'universal-streaming-english', language: 'str' = 'en-US', input_sample_rate: 'int' = 48000, output_sample_rate: 'int' = 16000, encoding: 'str' = 'pcm_s16le', format_turns: 'bool' = True, end_of_turn_confidence_threshold: 'float' = 0.4, min_end_of_turn_silence_when_confident: 'int' = 560, max_turn_silence: 'int' = 2400, keyterms_prompt: 'Optional[List[str]]' = None, language_detection: 'bool' = False, base_url: 'str | None' = None) -> 'None'
```

<ParamField path="api_key" type="str | None">
  AssemblyAI API key. Falls back to the `ASSEMBLYAI_API_KEY` environment variable when omitted.
</ParamField>

<ParamField path="speech_model" type="AssemblyAISTTModel | str" default="universal-streaming-english">
  Streaming model to use. Defaults to `"universal-streaming-english"` (English-only, lowest latency). Use `"universal-streaming"` for multilingual recognition across English, Spanish, German, French, Portuguese, and Italian. Accepts any `AssemblyAISTTModel` enum value or a raw string.
</ParamField>

<ParamField path="language" type="str" default="en-US">
  BCP-47 language code for transcription, e.g. `"en-US"`, `"fr"`、`"de"`. Only relevant when `language_detection` is `False`. Defaults to `"en-US"`.
</ParamField>

<ParamField path="input_sample_rate" type="int" default="48000">
  Sample rate (Hz) of the incoming audio. Must match the actual capture rate, typically `48000`. Defaults to `48000`.
</ParamField>

<ParamField path="output_sample_rate" type="int" default="16000">
  Sample rate (Hz) used when sending audio to AssemblyAI. The audio is resampled from `input_sample_rate` to this value before transmission. AssemblyAI accepts `8000`–`48000` Hz. Defaults to `16000`.
</ParamField>

<ParamField path="encoding" type="str" default="pcm_s16le">
  PCM encoding format of the audio stream. Must be `"pcm_s16le"` (16-bit signed little-endian, the AssemblyAI default) or `"pcm_mulaw"` (8-bit µ-law). Defaults to `"pcm_s16le"`.
</ParamField>

<ParamField path="format_turns" type="bool" default="True">
  When `True` (default), AssemblyAI returns punctuated, cased transcript segments aligned to speaker turns rather than raw word-level partials.
</ParamField>

<ParamField path="end_of_turn_confidence_threshold" type="float" default="0.4">
  Confidence score `[0.0, 1.0]` above which the model considers a pause as an end-of-turn event. Lower values trigger turns sooner. Defaults to `0.4`.
</ParamField>

<ParamField path="min_end_of_turn_silence_when_confident" type="int" default="560">
  Minimum silence duration (ms) required to confirm an end-of-turn when confidence exceeds the threshold. Defaults to `560` ms.
</ParamField>

<ParamField path="max_turn_silence" type="int" default="2400">
  Maximum silence (ms) before a turn is force-ended regardless of confidence. Defaults to `2400` ms.
</ParamField>

<ParamField path="keyterms_prompt" type="Optional[List[str]]">
  List of domain-specific words or phrases to boost recognition accuracy (e.g. `["Cartesia", "Deepgram"]`). Defaults to `None` (empty list, no boosting).
</ParamField>

<ParamField path="language_detection" type="bool" default="False">
  When `True`, AssemblyAI automatically detects the spoken language per utterance and returns language metadata. Only supported by the multilingual `"universal-streaming"` model. Overrides `language`. Defaults to `False`.
</ParamField>

<ParamField path="base_url" type="str | None">
  Override the AssemblyAI WebSocket endpoint URL. Useful for proxies or self-hosted deployments. Defaults to `None` (uses the AssemblyAI production endpoint).
</ParamField>

### aclose

```python theme={null}
def aclose(self) -> 'None'
```

Release any resources held by the provider.

### emit

```python theme={null}
def emit(self, event: 'T', *args: 'Any') -> 'None'
```

Emit an event, invoking all registered handlers with the given arguments.

Handlers are called in registration order. Coroutine handlers are
scheduled on the running event loop. If the emitter is closed, the call
is a no-op.

<ParamField path="event" type="T" required>
  The event to emit.
</ParamField>

### off

```python theme={null}
def off(self, event: 'T', callback: 'Callable[..., Any]') -> 'None'
```

Remove a previously registered handler for an event.

If the handler is not registered for the event, the call is a no-op.

<ParamField path="event" type="T" required>
  The event the handler was registered for.
</ParamField>

<ParamField path="callback" type="Callable[..., Any]" required>
  The handler to remove.
</ParamField>

### on

```python theme={null}
def on(self, event: 'T', callback: 'Callable[..., Any] | None' = None) -> 'Callable[..., Any]'
```

Register a handler for an event.

Can be used directly by passing a callback, or as a decorator when
`callback` is omitted.

<ParamField path="event" type="T" required>
  The event to listen for.
</ParamField>

<ParamField path="callback" type="Callable[..., Any] | None">
  The handler to invoke when the event is emitted. If `None`, a decorator is returned that registers the decorated function.
</ParamField>

<ResponseField name="returns" type="Callable[..., Any]">
  The registered callback when `callback` is provided, otherwise a decorator that registers and returns the function it wraps.
</ResponseField>

### on\_stt\_transcript

```python theme={null}
def on_stt_transcript(self, callback: 'Callable[[STTResponse], Awaitable[None]]') -> 'None'
```

Register the coroutine invoked when a transcription event is produced.

<ParamField path="callback" type="Callable[[STTResponse], Awaitable[None]]" required>
  An async callable that receives each `STTResponse`.
</ParamField>

### process\_audio

```python theme={null}
def process_audio(self, audio_frames: 'bytes', language: 'Optional[str]' = None, **kwargs: 'Any') -> 'None'
```

Process a chunk of audio for transcription.

Implementations should consume the audio frames and emit transcription
results through the registered transcript callback.

<ParamField path="audio_frames" type="bytes" required>
  Raw audio bytes to transcribe.
</ParamField>

<ParamField path="language" type="Optional[str]">
  Optional language code to guide recognition.
</ParamField>

### stream\_transcribe

```python theme={null}
def stream_transcribe(self, audio_stream: 'AsyncIterator[bytes]', **kwargs: 'Any') -> 'AsyncIterator[STTResponse]'
```

Transcribe a continuous audio stream.

<ParamField path="audio_stream" type="AsyncIterator[bytes]" required>
  An async iterator yielding raw audio byte chunks.
</ParamField>

<ResponseField name="returns" type="AsyncIterator[STTResponse]">
  STTResponse: Transcription events produced as audio is consumed.
</ResponseField>

***

## AssemblyAISTTModel

```python theme={null}
AssemblyAISTTModel = typing.Literal['universal-streaming-english', 'universal-streaming-multilingual']
```
