stt

FunASR speech-to-text service with locally-downloaded models.

This module implements speech-to-text using locally-run FunASR models such as SenseVoice. SenseVoice is a multilingual model (Chinese, Cantonese, English, Japanese, Korean and more) with leading Chinese accuracy and non-autoregressive (fast) inference, making it a strong fully-local STT option for voice agents.

pipecat.services.funasr.stt.language_to_funasr_language(language: Language | str | None) → str[source]

Map a language value to a SenseVoice language code.

Parameters:

language – A pipecat language, raw language code, or None for auto-detection.

Returns:

A SenseVoice language code (e.g. "zh"), or "auto".

pipecat.services.funasr.stt.funasr_language_to_frame_language(language: str | None) → Language | None[source]

Map a FunASR language code back to a pipecat Language when possible.

class pipecat.services.funasr.stt.FunASRSTTSettings(model: str | None | NotGiven = <factory>, extra: dict[str, Any]=<factory>, language: Language | str | None | NotGiven = <factory>, use_itn: bool | None | NotGiven = <factory>)[source]

Bases: STTSettings

Settings for FunASRSTTService.

model and language are inherited from STTSettings.

Parameters:

use_itn – Apply inverse text normalization (e.g. “nine” -> “9”).

class pipecat.services.funasr.stt.FunASRSTTService(*, device: str = 'cpu', settings: FunASRSTTSettings | None = None, **kwargs)[source]

Bases: SegmentedSTTService

Speech-to-text using a locally-downloaded FunASR model (e.g. SenseVoice).

Transcribes VAD-segmented speech with a local FunASR model. SenseVoice is multilingual (Chinese, Cantonese, English, Japanese, Korean, …) with strong Chinese accuracy and fast non-autoregressive inference.

Segments are resampled to the 16 kHz the model reads.

Settings

alias of FunASRSTTSettings

property wants_wav_segments: bool

Receive segments as raw 16-bit PCM, which the model reads directly.

property segment_sample_rate: int

Receive segments at 16 kHz, the rate FunASR reads.

__init__(*, device: str = 'cpu', settings: FunASRSTTSettings | None = None, **kwargs)[source]

Initialize the FunASR STT service.

Parameters:
  • device – Inference device, "cpu" or "cuda".

  • settings – Runtime-updatable settings (model, language, use_itn).

  • **kwargs – Additional arguments passed to SegmentedSTTService.

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

Convert a pipecat language into a FunASR language code.

can_generate_metrics() → bool[source]

Indicate that this service can generate processing metrics.

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

Transcribe an audio segment with FunASR.

Parameters:

audio – Raw audio bytes in 16-bit signed PCM format (16 kHz mono).

Yields:

Frame –

A TranscriptionFrame with the recognized 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.