base_stt

Base class for Whisper-based speech-to-text services.

This module provides common functionality for services implementing the Whisper API interface, including language mapping, metrics generation, and error handling.

class pipecat.services.whisper.base_stt.BaseWhisperSTTSettings(model: str | None | NotGiven = <factory>, extra: dict[str, ~typing.Any]=<factory>, language: Language | str | None | NotGiven = <factory>, prompt: str | None | NotGiven = <factory>, temperature: float | None | NotGiven = <factory>)[source]

Bases: STTSettings

Settings for BaseWhisperSTTService.

Parameters:
  • prompt – Optional text to guide the model’s style or continue a previous segment.

  • temperature – Sampling temperature between 0 and 1.

pipecat.services.whisper.base_stt.language_to_whisper_language(language: Language) → str[source]

Maps pipecat Language enum to Whisper API language codes.

Language support for Whisper API. Docs: https://platform.openai.com/docs/guides/speech-to-text#supported-languages

Parameters:

language – A Language enum value representing the input language.

Returns:

The corresponding service language code. If language is not in the verified mapping, falls back to the base language code (e.g., en from en-US) and logs a warning (via resolve_language(..., use_base_code=True)).

class pipecat.services.whisper.base_stt.BaseWhisperSTTService(*, model: str | None = None, api_key: str | None = None, base_url: str | None = None, http_client: Any | None = None, language: Language | None = None, prompt: str | None = None, temperature: float | None = None, include_prob_metrics: bool = False, push_empty_transcripts: bool = False, settings: BaseWhisperSTTSettings | None = None, ttfs_p99_latency: float | None = 1.0, **kwargs)[source]

Bases: SegmentedSTTService

Base class for Whisper-based speech-to-text services.

Provides common functionality for services implementing the Whisper API interface, including metrics generation and error handling.

Settings

alias of BaseWhisperSTTSettings

__init__(*, model: str | None = None, api_key: str | None = None, base_url: str | None = None, http_client: Any | None = None, language: Language | None = None, prompt: str | None = None, temperature: float | None = None, include_prob_metrics: bool = False, push_empty_transcripts: bool = False, settings: BaseWhisperSTTSettings | None = None, ttfs_p99_latency: float | None = 1.0, **kwargs)[source]

Initialize the Whisper STT service.

Parameters:
  • model –

    Name of the Whisper model to use.

    Deprecated since version 0.0.105: Use settings=BaseWhisperSTTService.Settings(model=...) instead. Will be removed in 2.0.0.

  • api_key – Service API key. Defaults to None.

  • base_url – Service API base URL. Defaults to None.

  • http_client – Custom async HTTP client for API requests, e.g. one with a longer request timeout. Prefer openai.DefaultAsyncHttpxClient, which keeps the SDK’s connection limits and redirect handling; a bare client uses its own defaults instead. The SDK’s HTTP client family follows the installed openai version, so build any Timeout you pass it from that same family. Defaults to None, which lets the SDK build its own client.

  • language –

    Language of the audio input.

    Deprecated since version 0.0.105: Use settings=BaseWhisperSTTService.Settings(language=...) instead. Will be removed in 2.0.0.

  • prompt –

    Optional text to guide the model’s style or continue a previous segment.

    Deprecated since version 0.0.105: Use settings=BaseWhisperSTTService.Settings(prompt=...) instead. Will be removed in 2.0.0.

  • temperature –

    Sampling temperature between 0 and 1.

    Deprecated since version 0.0.105: Use settings=BaseWhisperSTTService.Settings(temperature=...) instead. Will be removed in 2.0.0.

  • include_prob_metrics – If True, enables probability metrics in API response. Each service implements this differently (see child classes). Defaults to False.

  • push_empty_transcripts – If true, allow empty TranscriptionFrame frames to be pushed downstream instead of discarding them. This is intended for situations where VAD fires even though the user did not speak. In these cases, it is useful to know that nothing was transcribed so that the agent can resume speaking, instead of waiting longer for a transcription. Defaults to False.

  • settings – Runtime-updatable settings. When provided alongside deprecated parameters, settings values 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.

Raises:

ValueError – If the service is for a provider other than OpenAI and api_key is empty.

can_generate_metrics() → bool[source]

Whether this service can generate processing metrics.

Returns:

True, as this service supports metric generation.

Return type:

bool

language_to_service_language(language: Language) → str | None[source]

Convert from pipecat Language to service language code.

Parameters:

language – The Language enum value to convert.

Returns:

The corresponding service language code, or None if not supported.

async run_stt(audio: bytes) → AsyncGenerator[Frame, None][source]

Transcribe audio data to text.

Parameters:

audio – Raw audio data to transcribe.

Yields:

Frame –

Either a TranscriptionFrame containing the transcribed text

or an ErrorFrame if transcription fails.

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 STTService drops 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.

async start_stt_usage_metrics(usage: STTUsage)

Start STT usage metrics collection.

Parameters:

usage – Usage information for the STT operation.

async stop_ttfb_metrics(*, end_time: float | None = None)

Stop time-to-first-byte metrics collection and push results.

Parameters:

end_time – Optional timestamp to use as the end time. If None, uses the current time.