Transcriber class is the core of Moonshine Voice, handling the speech-to-text pipeline including voice activity detection, audio segmentation, and transcription.
Class Definition
Constructor Parameters
Path to the directory containing model files (encoder_model.ort, decoder_model_merged.ort, tokenizer.bin)
Model architecture to use. Options:
ModelArch.TINY- 26M parameters, fastestModelArch.BASE- 58M parameters, balancedModelArch.TINY_STREAMING- 34M parameters, streaming supportModelArch.SMALL_STREAMING- 123M parameters, streaming supportModelArch.MEDIUM_STREAMING- 245M parameters, highest accuracy
How often (in seconds) to run transcription updates. Lower values provide more frequent updates but use more CPU.
Advanced configuration options as string key-value pairs:
Methods
transcribe_without_streaming
Transcribe pre-recorded audio without streaming.Audio samples as mono PCM floats between -1.0 and 1.0
Sample rate in Hz. The library will resample to 16kHz internally.
Reserved for future use
Transcript object with finalized transcription lines
start
Begin a new streaming transcription session.add_audio().
stop
End the current streaming session.add_audio
Add audio data to the active stream.Mono PCM audio samples as floats (-1.0 to 1.0). Can be any chunk size.
Sample rate of the input audio
update_transcription
Manually trigger a transcription update.Use
Transcriber.MOONSHINE_FLAG_FORCE_UPDATE to bypass the 200ms cacheTranscript object
create_stream
Create an additional stream for processing multiple audio sources.Reserved for future use
Override the transcriber’s default update interval for this stream
Stream object
add_listener
Register an event listener for transcription events.Object implementing the event listener protocol with methods:
on_line_started(event: LineStarted)on_line_updated(event: LineUpdated)on_line_text_changed(event: LineTextChanged)on_line_completed(event: LineCompleted)on_error(event: Error)
remove_listener
Remove a registered event listener.Context Manager Support
TheTranscriber class supports Python’s context manager protocol:
Example: File Transcription
Example: Streaming with Events
See Also
- MicTranscriber - Microphone integration
- Stream - Multi-stream API
- Events - Event types and listeners
- Data Structures - Transcript and TranscriptLine