stt

Moonshine speech-to-text service with locally-downloaded ONNX models.

Moonshine is a small, fast ASR family that runs on the CPU via ONNX Runtime – no GPU and no API key. This module transcribes audio segments with a locally-downloaded Moonshine model (downloaded once on first use and cached).

pipecat.services.moonshine.stt.language_to_moonshine_language(language: Language) → str[source]

Convert a pipecat Language to a Moonshine language code.

Moonshine publishes one model per language, keyed by base ISO code, so regional variants (Language.ES_MX) resolve to their base code ("es").

Parameters:

language – The Language enum value to convert.

Returns:

The Moonshine language code.

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

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

class pipecat.services.moonshine.stt.Model(*values)[source]

Bases: StrEnum

Well-known Moonshine model architectures.

Pass a member (or the equivalent string) as MoonshineSTTService.Settings’s model. The larger models (SMALL_STREAMING, MEDIUM_STREAMING) ship only in streaming form, but transcribe a whole segment in batch just the same.

Which architectures exist depends on the language: English publishes the widest range and is the only language with MEDIUM_STREAMING, while most others ship one or two models. An architecture unavailable for the configured language falls back to the best one published for it.

Parameters:
  • TINY – Smallest and fastest, lowest accuracy.

  • BASE – Good size/accuracy balance.

  • TINY_STREAMING – Streaming-capable tiny.

  • BASE_STREAMING – Streaming-capable base.

  • SMALL_STREAMING – Larger and more accurate than base (the default).

  • MEDIUM_STREAMING – Largest, most accurate.

TINY = 'tiny'
BASE = 'base'
TINY_STREAMING = 'tiny-streaming'
BASE_STREAMING = 'base-streaming'
SMALL_STREAMING = 'small-streaming'
MEDIUM_STREAMING = 'medium-streaming'
class pipecat.services.moonshine.stt.MoonshineSTTSettings(model: str | None | NotGiven = <factory>, extra: dict[str, Any]=<factory>, language: Language | str | None | NotGiven = <factory>)[source]

Bases: STTSettings

Settings for MoonshineSTTService.

Parameters:
  • model – Moonshine model architecture, as a Model or the equivalent string (e.g. Model.SMALL_STREAMING or "small-streaming"). Defaults to Model.SMALL_STREAMING.

  • language – Language for transcription. Moonshine publishes models for Arabic, Chinese, English, German, Japanese, Korean, Spanish, Tagalog, Ukrainian, and Vietnamese; regional variants resolve to their base code.

class pipecat.services.moonshine.stt.MoonshineSTTService(*, settings: MoonshineSTTSettings | None = None, **kwargs)[source]

Bases: SegmentedSTTService

Transcribe audio with a locally-downloaded Moonshine ONNX model.

Runs on the CPU via ONNX Runtime, so it needs no GPU and no API key. The model downloads once on first use and is cached. Each VAD-segmented utterance is transcribed in a single batch call (transcribe_without_streaming); any model works, including the streaming-capable ones. Segments are resampled to the 16 kHz the model reads.

Models are language-specific, so a language change reloads the model. Arabic, Chinese, Japanese, Korean and Ukrainian decode at the raised token rate Moonshine documents for them, so long utterances are not truncated. They are MIT-licensed in every language and size, except the legacy non-streaming models for languages other than English (TINY and BASE), which are under the non-commercial Moonshine Community License (https://www.moonshine.ai/license); Moonshine’s LICENSE enumerates them.

Settings

alias of MoonshineSTTSettings

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 Moonshine reads.

__init__(*, settings: MoonshineSTTSettings | None = None, **kwargs)[source]

Initialize the Moonshine STT service.

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

  • **kwargs – Additional arguments passed to SegmentedSTTService.

can_generate_metrics() → bool[source]

Indicate whether this service can generate metrics.

Returns:

True, as this service supports metric generation.

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

Convert a pipecat language into a Moonshine language code.

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

Transcribe audio data using Moonshine.

Parameters:

audio – Raw 16-bit signed PCM mono audio at 16 kHz.

Yields:

Frame – A TranscriptionFrame with the transcribed text.

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.