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
Nonefor 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
Languagewhen 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:
STTSettingsSettings for
FunASRSTTService.modelandlanguageare inherited fromSTTSettings.- 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:
SegmentedSTTServiceSpeech-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.
- __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.
- 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
TranscriptionFramewith the recognized text, or an ErrorFrameif transcription fails.
- A
- 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.