Installation
Add Package Dependency
In Xcode, add the Moonshine Swift package:
- Right-click on the file view sidebar
- Choose “Add Package Dependencies…” from the menu
- Paste
https://github.com/moonshine-ai/moonshine-swift/into the search box - Select moonshine-swift and click “Add Package”
The package uses Swift Package Manager (SPM) and is auto-updated from GitHub.
Add Model Files
Download model files and add them to your app bundle:Then add the model files to your Xcode project:
- Drag the model folder into Xcode
- Ensure “Copy items if needed” is checked
- Add to target in the deployment phase
Quick Start Example
Download and try the pre-built example:Basic Implementation
SwiftUI Transcription App
Here’s a complete example of a SwiftUI app with live transcription:File Transcription
Transcribe audio files without streaming:Model Architectures
Swift supports these model architectures via theModelArch enum:
- tiny - Smallest, fastest (26M parameters)
- tinyStreaming - Small with streaming support (34M parameters)
- base - Good balance (58M parameters)
- smallStreaming - High accuracy with streaming (123M parameters)
- mediumStreaming - Best accuracy (245M parameters)
Supported Languages
Load models for different languages:Event-Driven Interface
Moonshine uses events to notify your app of transcription updates:Event Guarantees
lineStartedcalled exactly once per segmentlineCompletedcalled exactly once per segment (after lineStarted)lineTextChangedcalled zero or more times between start and completion- Only one line active at a time per stream
- Each line has a unique 64-bit
lineId - Line data never changes after
lineCompleted
Performance Considerations
Model Size vs Accuracy
| Model | Size | WER | iPhone 12 Latency |
|---|---|---|---|
| Tiny | 26MB | 12.66% | ~30ms |
| Tiny Streaming | 34MB | 12.00% | ~25ms |
| Base | 58MB | 10.07% | ~40ms |
| Small Streaming | 123MB | 7.84% | ~60ms |
| Medium Streaming | 245MB | 6.65% | ~90ms |
Optimization Tips
- Use streaming models for real-time applications (lower latency)
- Bundle only needed models to reduce app size
- Test on actual devices - simulator performance differs significantly
- Adjust update_interval to balance responsiveness vs CPU usage
Common Issues
Microphone Permission Denied
Model Not Found
Ensure model files are:- Added to Xcode project
- Included in target’s “Copy Bundle Resources” build phase
- Accessible via
Bundle.main.path()
Build Errors
If you encounter build errors:- Clean build folder (Cmd+Shift+K)
- Delete derived data
- Verify package is properly resolved
- Check minimum iOS deployment target (iOS 14+)
Example Projects
The repository includes complete examples:- Transcriber - Full SwiftUI app with live microphone transcription
- Located in
examples/ios/Transcriber/
Next Steps
API Reference
Detailed Swift API documentation
Models
Available models and architectures
macOS Guide
Using Moonshine on macOS
Examples
More iOS examples