stt
ElevenLabs speech-to-text service implementation.
This module provides integration with ElevenLabs’ Speech-to-Text API for transcription using segmented audio processing. The service uploads audio files and receives transcription results directly.
- pipecat.services.elevenlabs.stt.language_to_elevenlabs_language(language: Language) str[source]
Convert a Language enum to ElevenLabs language code.
- Parameters:
language – The Language enum value to convert.
- Returns:
The corresponding service language code. If
languageis not in the verified mapping, falls back to its base language’s code (en-USbecomeseng) and logs a warning (viaresolve_language(..., use_base_code=True)).
- class pipecat.services.elevenlabs.stt.CommitStrategy(*values)[source]
Bases:
StrEnumCommit strategies for transcript segmentation.
- MANUAL = 'manual'
- VAD = 'vad'
- class pipecat.services.elevenlabs.stt.ElevenLabsSTTSettings(model: str | None | NotGiven = <factory>, extra: dict[str, ~typing.Any]=<factory>, language: Language | str | None | NotGiven = <factory>, tag_audio_events: bool | None | NotGiven = <factory>, keyterms: list[str] | None | NotGiven = <factory>, no_verbatim: bool | None | NotGiven = <factory>, diarize: bool | None | NotGiven = <factory>, speaker_format: str | None | NotGiven = <factory>)[source]
Bases:
STTSettingsSettings for ElevenLabsSTTService.
- Parameters:
tag_audio_events – Whether to include audio events like (laughter), (coughing) in the transcription.
keyterms – List of key terms or phrases to bias transcription towards.
no_verbatim – Whether to drop filler words, false starts and non-speech sounds from the transcript. Supported by
scribe_v2only.diarize – Whether to annotate which speaker is talking. Each contiguous speaker run of a segment is emitted as its own frame with ElevenLabs’ speaker id (e.g.
"speaker_0") asspeaker.label.speaker_format – Optional format string for diarized speaker runs. Use
{speaker}for the speaker label,{text}for the transcript text, and{speaker_number}for the speaker’s order of first appearance in the session (1,2, …), e.g."{speaker}: {text}". IfNone, transcript text is not modified.
- class pipecat.services.elevenlabs.stt.ElevenLabsRealtimeSTTSettings(model: str | None | NotGiven = <factory>, extra: dict[str, ~typing.Any]=<factory>, language: Language | str | None | NotGiven = <factory>, keyterms: list[str] | None | NotGiven = <factory>, no_verbatim: bool | None | NotGiven = <factory>, vad_silence_threshold_secs: float | None | NotGiven = <factory>, vad_threshold: float | None | NotGiven = <factory>, min_speech_duration_ms: int | None | NotGiven = <factory>, min_silence_duration_ms: int | None | NotGiven = <factory>, secondary_languages: list[str] | None | NotGiven = <factory>, filter_background_audio: bool | None | NotGiven = <factory>)[source]
Bases:
STTSettingsSettings for ElevenLabsRealtimeSTTService.
See
ElevenLabsRealtimeSTTService.InputParamsfor detailed descriptions.- Parameters:
keyterms – List of key terms or phrases to bias transcription towards.
no_verbatim – Whether to drop filler words, false starts and non-speech sounds from the transcript.
vad_silence_threshold_secs – Seconds of silence before VAD commits (0.3-3.0).
vad_threshold – VAD sensitivity (0.1-0.9, lower is more sensitive).
min_speech_duration_ms – Minimum speech duration for VAD (50-2000ms).
min_silence_duration_ms – Minimum silence duration for VAD (50-2000ms).
secondary_languages – ISO-639-1 or ISO-639-3 language codes to consider.
filter_background_audio – Whether ElevenLabs filters out background audio before transcription.
- class pipecat.services.elevenlabs.stt.ElevenLabsSTTService(*, api_key: str, aiohttp_session: ClientSession, base_url: str = 'https://api.elevenlabs.io', model: str | None = None, sample_rate: int | None = None, params: InputParams | None = None, settings: ElevenLabsSTTSettings | None = None, ttfs_p99_latency: float | None = 2.01, **kwargs)[source]
Bases:
SegmentedSTTServiceSpeech-to-text service using ElevenLabs’ file-based API.
This service uses ElevenLabs’ Speech-to-Text API to perform transcription on audio segments. It inherits from SegmentedSTTService to handle audio buffering and speech detection. The service uploads audio files to ElevenLabs and receives transcription results directly.
- Settings
alias of
ElevenLabsSTTSettings
- class InputParams(*, language: Language | None = None, tag_audio_events: bool = True)[source]
Bases:
BaseModelConfiguration parameters for ElevenLabs STT API.
Deprecated since version 0.0.105: Use
settings=ElevenLabsSTTService.Settings(...)instead. Will be removed in 2.0.0.- Parameters:
language – Target language for transcription.
tag_audio_events – Whether to include audio events like (laughter), (coughing), in the transcription.
- __init__(*, api_key: str, aiohttp_session: ClientSession, base_url: str = 'https://api.elevenlabs.io', model: str | None = None, sample_rate: int | None = None, params: InputParams | None = None, settings: ElevenLabsSTTSettings | None = None, ttfs_p99_latency: float | None = 2.01, **kwargs)[source]
Initialize the ElevenLabs STT service.
- Parameters:
api_key – ElevenLabs API key for authentication.
aiohttp_session – aiohttp ClientSession for HTTP requests.
base_url – Base URL for ElevenLabs API.
model –
Model ID for transcription.
Deprecated since version 0.0.105: Use
settings=ElevenLabsSTTService.Settings(model=...)instead. Will be removed in 2.0.0.sample_rate – Audio sample rate in Hz. If not provided, uses the pipeline’s rate.
params –
Configuration parameters for the STT service.
Deprecated since version 0.0.105: Use
settings=ElevenLabsSTTService.Settings(...)instead. Will be removed in 2.0.0.settings – Runtime-updatable settings. When provided alongside deprecated parameters,
settingsvalues take precedence.ttfs_p99_latency – P99 latency from speech end to final transcript in seconds. Override for your deployment. See https://github.com/pipecat-ai/stt-benchmark
**kwargs – Additional arguments passed to SegmentedSTTService.
- can_generate_metrics() bool[source]
Check if the service can generate processing metrics.
- Returns:
True, as ElevenLabs STT service supports metrics generation.
- language_to_service_language(language: Language) str | None[source]
Convert a Language enum to ElevenLabs service-specific language code.
- Parameters:
language – The language to convert.
- Returns:
The ElevenLabs-specific language code, or None if not supported.
- async run_stt(audio: bytes) AsyncGenerator[Frame | None, None][source]
Transcribe an audio segment using ElevenLabs’ STT API.
- Parameters:
audio – Raw audio bytes in WAV format (already converted by base class).
- Yields:
Frame – TranscriptionFrame containing the transcribed text, or ErrorFrame on failure.
Note
The audio is already in WAV format from the SegmentedSTTService. Only non-empty transcriptions are yielded.
- async push_frame(frame: Frame, direction: FrameDirection = FrameDirection.DOWNSTREAM)
Push a frame, marking a TranscriptionFrame finalized when its segment is the latest.
Once the user speaks again, the transcript of an earlier segment covers only the words before they resumed, so it isn’t finalized, the same way
STTServicedrops a pending finalize when the user starts speaking. When a segment’s transcript arrives as several diarized TranscriptionFrames (one per speaker run), only the last one can be.- Parameters:
frame – The frame to push.
direction – The direction of frame flow in the pipeline.
- pipecat.services.elevenlabs.stt.audio_format_from_sample_rate(sample_rate: int) str[source]
Get the appropriate audio format string for a given sample rate.
- Parameters:
sample_rate – The audio sample rate in Hz.
- Returns:
The ElevenLabs audio format string.
- class pipecat.services.elevenlabs.stt.ElevenLabsRealtimeSTTService(*, api_key: str, base_url: str = 'api.elevenlabs.io', commit_strategy: CommitStrategy = CommitStrategy.MANUAL, model: str | None = None, sample_rate: int | None = None, include_timestamps: bool = False, enable_logging: bool = False, include_language_detection: bool = False, params: InputParams | None = None, settings: ElevenLabsRealtimeSTTSettings | None = None, ttfs_p99_latency: float | None = 0.41, **kwargs)[source]
Bases:
WebsocketSTTServiceSpeech-to-text service using ElevenLabs’ Realtime WebSocket API.
This service uses ElevenLabs’ Realtime Speech-to-Text API to perform transcription with ultra-low latency. It supports both partial (interim) and committed (final) transcripts, and can use either manual commit control or automatic Voice Activity Detection (VAD) for segment boundaries.
By default, uses manual commit strategy where Pipecat’s VAD controls when to commit transcript segments, providing consistency with other STT services.
- Settings
alias of
ElevenLabsRealtimeSTTSettings
- class InputParams(*, language_code: str | None = None, commit_strategy: CommitStrategy = CommitStrategy.MANUAL, vad_silence_threshold_secs: float | None = None, vad_threshold: float | None = None, min_speech_duration_ms: int | None = None, min_silence_duration_ms: int | None = None, include_timestamps: bool = False, enable_logging: bool = False, include_language_detection: bool = False)[source]
Bases:
BaseModelConfiguration parameters for ElevenLabs Realtime STT API.
Deprecated since version 0.0.105: Use
settings=ElevenLabsRealtimeSTTService.Settings(...)instead. Will be removed in 2.0.0.- Parameters:
language_code – ISO-639-1 or ISO-639-3 language code. Leave None for auto-detection.
commit_strategy – How to segment speech - manual (Pipecat VAD) or vad (ElevenLabs VAD).
vad_silence_threshold_secs – Seconds of silence before VAD commits (0.3-3.0). Only used when commit_strategy is VAD. None uses ElevenLabs default.
vad_threshold – VAD sensitivity (0.1-0.9, lower is more sensitive). Only used when commit_strategy is VAD. None uses ElevenLabs default.
min_speech_duration_ms – Minimum speech duration for VAD (50-2000ms). Only used when commit_strategy is VAD. None uses ElevenLabs default.
min_silence_duration_ms – Minimum silence duration for VAD (50-2000ms). Only used when commit_strategy is VAD. None uses ElevenLabs default.
include_timestamps – Whether to include word-level timestamps in transcripts.
enable_logging – Whether to enable logging on ElevenLabs’ side.
include_language_detection – Whether to include language detection in transcripts.
- commit_strategy: CommitStrategy
- __init__(*, api_key: str, base_url: str = 'api.elevenlabs.io', commit_strategy: CommitStrategy = CommitStrategy.MANUAL, model: str | None = None, sample_rate: int | None = None, include_timestamps: bool = False, enable_logging: bool = False, include_language_detection: bool = False, params: InputParams | None = None, settings: ElevenLabsRealtimeSTTSettings | None = None, ttfs_p99_latency: float | None = 0.41, **kwargs)[source]
Initialize the ElevenLabs Realtime STT service.
- Parameters:
api_key – ElevenLabs API key for authentication.
base_url – Base URL for ElevenLabs WebSocket API.
commit_strategy – How to segment speech —
CommitStrategy.MANUAL(Pipecat VAD) orCommitStrategy.VAD(ElevenLabs VAD). Defaults toCommitStrategy.MANUAL.model –
Model ID for transcription.
Deprecated since version 0.0.105: Use
settings=ElevenLabsRealtimeSTTService.Settings(model=...)instead. Will be removed in 2.0.0.sample_rate – Audio sample rate in Hz. If not provided, uses the pipeline’s rate.
include_timestamps – Whether to include word-level timestamps in transcripts.
enable_logging – Whether to enable logging on ElevenLabs’ side.
include_language_detection – Whether to include language detection in transcripts.
params –
Configuration parameters for the STT service.
Deprecated since version 0.0.105: Use
settings=ElevenLabsRealtimeSTTService.Settings(...)instead. Will be removed in 2.0.0.settings – Runtime-updatable settings. When provided alongside deprecated parameters,
settingsvalues take precedence.ttfs_p99_latency – P99 latency from speech end to final transcript in seconds. Override for your deployment. See https://github.com/pipecat-ai/stt-benchmark
**kwargs – Additional arguments passed to WebsocketSTTService.
- can_generate_metrics() bool[source]
Check if the service can generate processing metrics.
- Returns:
True, as ElevenLabs Realtime STT service supports metrics generation.
- language_to_service_language(language: Language) str | None[source]
Convert a Language enum to ElevenLabs service-specific language code.
- Parameters:
language – The language to convert.
- Returns:
The ElevenLabs-specific language code, or None if not supported.
- property send_sample_rate: int
the input rate, or 16 kHz if ElevenLabs doesn’t take it.
- Returns:
The sample rate in Hz.
- Type:
Get the rate audio is sent at
- async setup(setup: FrameProcessorSetup)[source]
Set up the service and connect.
- Parameters:
setup – Configuration object containing setup parameters.
- async process_frame(frame: Frame, direction: FrameDirection)[source]
Process incoming frames and handle speech events.
- Parameters:
frame – The frame to process.
direction – Direction of frame flow in the pipeline.
- async run_stt(audio: bytes) AsyncGenerator[Frame | None, None][source]
Process audio data for speech-to-text transcription.
- Parameters:
audio – Raw audio bytes to transcribe.
- Yields:
None - transcription results are handled via WebSocket responses.
- async push_frame(frame: Frame, direction: FrameDirection = FrameDirection.DOWNSTREAM)
Push a frame downstream, tracking TranscriptionFrame timestamps for TTFB.
Stores the timestamp of each TranscriptionFrame for TTFB calculation. If the frame is marked as finalized (via request_finalize/confirm_finalize), reports TTFB immediately and cancels any pending timeout. Otherwise, TTFB is reported after a timeout.
- Parameters:
frame – The frame to push.
direction – The direction to push the frame.