Constants
Version
Header file version. Pass this to
moonshine_load_transcriber_from_files() to ensure compatibility.Format: MAJOR * 10000 + MINOR * 100 + PATCH- Version 2.0.0 = 20000
- Version 2.3.7 = 20307
Model Architectures
Tiny model (26M parameters, 12.66% WER for English)
Base model (58M parameters, 10.07% WER for English)
Tiny streaming model (34M parameters, 12.00% WER for English)
Base streaming model (58M parameters)
Small streaming model (123M parameters, 7.84% WER for English)
Medium streaming model (245M parameters, 6.65% WER for English)
Error Codes
Operation completed successfully
Unknown error occurred
Invalid transcriber or stream handle
Invalid function argument
Flags
Force stream analysis even if less than 200ms of new audio has been added
Intent Recognition Model Architectures
Gemma 300M embedding model for intent recognition
Data Structures
transcriber_option_t
Option name
Option value as a string
transcript_line_t
UTF-8 encoded transcription text
Raw audio data for this segment (16kHz float PCM, -1.0 to 1.0)
Number of audio samples in audio_data
Time offset from start of stream in seconds
Duration of the segment in seconds
Stable 64-bit identifier for this line (remains constant across updates)
Streaming only: 1 if speaker has finished this segment, 0 if still speaking
Streaming only: 1 if line changed since last
moonshine_transcribe_stream() callStreaming only: 1 if line was newly added since last call
Streaming only: 1 if text changed since last call
1 if speaker_id has been calculated
Randomly-generated 64-bit identifier for the speaker (for diarization)
Order in which this speaker appeared in the transcript (0 = first speaker)
Streaming only: Latency of last transcription in milliseconds
transcript_t
Array of transcript lines in chronological order
Number of lines in the transcript
moonshine_intent_callback
User data pointer passed to
moonshine_register_intent()The registered trigger phrase that matched
The actual utterance that was recognized
Similarity score between 0 and 1
Transcriber Functions
moonshine_get_version
Library version in format
MAJOR * 10000 + MINOR * 100 + PATCHThis may differ from
MOONSHINE_HEADER_VERSION if a newer shared library is loaded.moonshine_error_to_string
Error code from an API call
Human-readable error description
moonshine_transcript_to_string
Transcript to convert
String representation (valid until next call to this function)
moonshine_load_transcriber_from_files
Directory containing model files:
encoder_model.ortdecoder_model_merged.orttokenizer.bin
Model architecture (e.g.,
MOONSHINE_MODEL_ARCH_BASE_STREAMING)Array of custom options (can be NULL)
Number of options in the array
Should be
MOONSHINE_HEADER_VERSION for compatibilityNon-negative transcriber handle on success, negative error code on failure
moonshine_load_transcriber_from_memory
Binary data for encoder model
Size of encoder model data in bytes
Binary data for decoder model
Size of decoder model data in bytes
Binary data for tokenizer
Size of tokenizer data in bytes
Model architecture constant
Array of custom options (can be NULL)
Number of options
Should be
MOONSHINE_HEADER_VERSIONNon-negative transcriber handle on success, negative error code on failure
moonshine_free_transcriber
Handle returned by
moonshine_load_transcriber_from_files() or moonshine_load_transcriber_from_memory()moonshine_transcribe_without_streaming
Transcriber handle
PCM audio data array (values between -1.0 and 1.0)
Number of samples in audio_data
Sample rate in Hz (16000 recommended)
Reserved for future use (pass 0)
Pointer to receive transcript result
MOONSHINE_ERROR_NONE (0) on success, error code on failureThe transcript data is owned by the transcriber and valid until the next call or until the transcriber is freed.
Streaming Functions
moonshine_create_stream
Transcriber handle
Reserved (pass 0)
Non-negative stream handle on success, negative error code on failure
moonshine_free_stream
Transcriber handle
Stream handle to free
MOONSHINE_ERROR_NONE on success, error code on failuremoonshine_start_stream
Transcriber handle
Stream handle
MOONSHINE_ERROR_NONE on success, error code on failureClears any previous transcript data. Call this after audio input discontinuities (e.g., when user unmutes).
moonshine_stop_stream
Transcriber handle
Stream handle
MOONSHINE_ERROR_NONE on success, error code on failureAny active lines will be marked as complete. Call
moonshine_transcribe_stream() after stopping to get final results.moonshine_transcribe_add_audio_to_stream
Transcriber handle
Stream handle
PCM audio samples (values between -1.0 and 1.0)
Number of samples
Sample rate in Hz
Reserved (pass 0)
MOONSHINE_ERROR_NONE on success, error code on failureThis function only buffers audio and does not perform transcription. Call
moonshine_transcribe_stream() to get results. Safe to call from time-critical threads.moonshine_transcribe_stream
Transcriber handle
Stream handle
Bitwise OR of flags:
MOONSHINE_FLAG_FORCE_UPDATE: Force analysis even if < 200ms of new audio
Pointer to receive updated transcript
MOONSHINE_ERROR_NONE on success, error code on failureBy default, full analysis only occurs if 200ms+ of new audio has been added. Use
MOONSHINE_FLAG_FORCE_UPDATE to override this throttling.Intent Recognition Functions
moonshine_create_intent_recognizer
Path to directory containing embedding model files
Model architecture (currently only
MOONSHINE_EMBEDDING_MODEL_ARCH_GEMMA_300M supported)Model quantization: “fp32”, “fp16”, “q8”, “q4”, “q4f16” (NULL defaults to “q4”)
Minimum similarity score (0.0-1.0) to trigger intent (default 0.7)
Non-negative recognizer handle on success, negative error code on failure
moonshine_free_intent_recognizer
Intent recognizer handle
moonshine_register_intent
Intent recognizer handle
Phrase to match (e.g., “Turn on the lights”)
Function to call when intent is triggered
User data passed to callback (can be NULL)
MOONSHINE_ERROR_NONE on success, error code on failuremoonshine_unregister_intent
Intent recognizer handle
Trigger phrase to remove
MOONSHINE_ERROR_NONE on success, error code on failuremoonshine_process_utterance
Intent recognizer handle
Utterance to match against registered intents
1 if intent recognized, 0 if not, negative error code on failure
moonshine_set_intent_threshold
Intent recognizer handle
New threshold (0.0-1.0)
MOONSHINE_ERROR_NONE on success, error code on failuremoonshine_get_intent_threshold
Intent recognizer handle
Current threshold (>= 0) on success, negative error code on failure
moonshine_get_intent_count
Intent recognizer handle
Number of intents (>= 0) on success, negative error code on failure
moonshine_clear_intents
Intent recognizer handle
MOONSHINE_ERROR_NONE on success, error code on failureStreaming Guarantees
When using streaming transcription, the library provides these guarantees:- Lines are never removed - only added
- Only the last line may be incomplete - all others are finalized
- Line IDs are stable - use them to track lines across updates
- Empty strings indicate detected speech with no transcription
- Line indexes are stable references - remember
line_countto process only new lines - Speaker IDs are set when confident - or when line completes
Best Practices
Memory Management
Performance
- Use 16kHz audio to avoid resampling overhead
- For streaming, call
moonshine_transcribe_stream()at intervals matching your latency requirements (e.g., every 500ms) - Add audio in whatever chunk sizes your audio source provides - the library handles buffering
- Use multiple streams on one transcriber to share model resources across audio sources
Error Handling
See Also
C API Overview
High-level concepts and architecture
Python API
Higher-level Python bindings (recommended)