Example Structure
Examples are organized by platform in theexamples/ directory:
- Android - Mobile transcription app
- C++ - Cross-platform minimal example
- iOS - Native iOS transcription app
- macOS - Desktop applications
- Python - Various transcription and intent recognition examples
- Raspberry Pi - IoT and robotics examples
- Windows - Command-line transcriber
Python Examples
Python examples demonstrate the core features of Moonshine Voice and are located inexamples/python/.
Basic Transcription
File:examples/python/basic_transcription.py
This example demonstrates both streaming and non-streaming transcription:
- Non-streaming mode: Transcribe a complete audio file offline
- Streaming mode: Process audio chunks in real-time with live updates
- Implements custom
TranscriptEventListenerto handle events - Shows how to use
load_wav_file()to load audio data
Microphone Transcription
File:examples/python/mic_transcription.py
Real-time transcription from your microphone:
- Uses
MicTranscriberfor automatic microphone integration - Implements terminal-aware output (interactive vs. non-interactive)
- Shows real-time text updates as you speak
- Handles line completion and text updates
Intent Recognition
File:examples/python/intent_recognition.py
Voice command recognition using semantic matching:
- Demonstrates
IntentRecognizerfor natural language commands - Uses embedding models for fuzzy phrase matching
- Registers multiple intents with custom handlers
- Shows confidence scores for matches
- “Turn on the lights” / “Switch on the lights”
- “What’s the weather like?” / “Weather forecast”
- “Set a timer” / “Start a timer for 5 minutes”
Platform-Specific Examples
Android
Location:examples/android/Transcriber/
Full Android application demonstrating:
- Integration with Android Studio and Gradle
- Maven package integration
- Real-time microphone transcription
- Native Android UI with RecyclerView for transcript display
iOS
Location:examples/ios/Transcriber/
Native iOS app featuring:
- Swift integration using Swift Package Manager
- SwiftUI interface
- Real-time microphone transcription
- Model file bundling in app resources
macOS
Two examples demonstrating different approaches:Basic Transcription
Location:examples/macos/BasicTranscription/
- Command-line tool for transcribing audio files
- Shows Swift Package Manager integration
Mic Transcription
Location:examples/macos/MicTranscription/
- Real-time microphone transcription for macOS
- Native audio input handling
Windows
Location:examples/windows/cli-transcriber/
Command-line transcriber for Windows:
- Visual Studio project (.vcxproj)
- C++ implementation using the high-level API
- Includes
download-lib.batscript to fetch pre-built libraries
C++ (Cross-Platform)
Location:examples/c++/
Minimal, platform-independent example:
- Uses the C++ header-only API (
moonshine-cpp.h) - Shows basic transcription workflow
- Demonstrates linking with pre-built libraries
- Works on Linux, macOS, and Windows
- No platform-specific dependencies
- Simple build with g++ or clang++
- Links against static library (.a or .lib)
Raspberry Pi
Location:examples/raspberry-pi/my-dalek/
File: my-dalek.py
Robotics voice control example:
- Voice commands for robot movement (forward, backward, left, right)
- Intent recognition with natural language variations
- Designed for Raspberry Pi with USB microphone
- Demonstrates IoT device integration
- “Move forward” / “Go ahead” / “Advance”
- “Turn left” / “Go left”
- “Exterminate” / “Kill all humans” (for fun!)
Common Patterns
All examples demonstrate these key patterns:- Model Loading: Download and load appropriate models for your language
- Event Listeners: Implement
TranscriptEventListenerfor handling transcription updates - Audio Input: Feed audio data from files, microphones, or other sources
- Session Management: Start/stop sessions to control transcription lifecycle
Getting Started
- Choose the platform/language that matches your project
- Download the example archive or clone the repository
- Follow the platform-specific setup instructions
- Run the example to verify it works
- Adapt the code for your application
Next Steps
- Add the library to your own app
- Learn about the API
- Build from source for customization