Usage guide
Setup, environment variables, and Python/JavaScript/Go usage examples.
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
AssemblyAI API key. Falls back to the
ASSEMBLYAI_API_KEY environment variable when omitted.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.BCP-47 language code for transcription, e.g.
"en-US", "fr"ใ"de". Only relevant when language_detection is False. Defaults to "en-US".Sample rate (Hz) of the incoming audio. Must match the actual capture rate, typically
48000. Defaults to 48000.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.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".When
True (default), AssemblyAI returns punctuated, cased transcript segments aligned to speaker turns rather than raw word-level partials.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.Minimum silence duration (ms) required to confirm an end-of-turn when confidence exceeds the threshold. Defaults to
560 ms.Maximum silence (ms) before a turn is force-ended regardless of confidence. Defaults to
2400 ms.List of domain-specific words or phrases to boost recognition accuracy (e.g.
["Cartesia", "Deepgram"]). Defaults to None (empty list, no boosting).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.Override the AssemblyAI WebSocket endpoint URL. Useful for proxies or self-hosted deployments. Defaults to
None (uses the AssemblyAI production endpoint).aclose
emit
The event to emit.
off
The event the handler was registered for.
The handler to remove.
on
callback is omitted.
The event to listen for.
The handler to invoke when the event is emitted. If
None, a decorator is returned that registers the decorated function.The registered callback when
callback is provided, otherwise a decorator that registers and returns the function it wraps.on_stt_transcript
An async callable that receives each
STTResponse.process_audio
Raw audio bytes to transcribe.
Optional language code to guide recognition.
stream_transcribe
An async iterator yielding raw audio byte chunks.
STTResponse: Transcription events produced as audio is consumed.