Prerequisites
- C++ compiler with C++17 support (GCC, Clang, or MSVC)
- CMake 3.15 or higher
- Git
- Python 3.8+ (for language bindings)
Getting the Source Code
Clone the repository:Building the Core Library
The core engine is written in C++ with a C interface for easy integration with other languages.Using CMake
build directory.
Running Tests
All tests expect to be run from thetest-assets folder. Use the provided scripts:
Linux/macOS:
Build Configuration
You can customize the build with CMake options:Building Language Bindings
Moonshine Voice provides native bindings for multiple languages built on top of the C interface.Python
The Python package includes:- C extension module wrapping the core library
- High-level Python API
- Helper utilities for audio processing
python/
Build and install locally:
Swift (iOS/macOS)
Swift bindings use Swift Package Manager. Location:swift/
The Swift package includes:
- Native Swift API wrapping the C interface
- Platform-specific optimizations for Apple Silicon
- Integration with Apple’s audio frameworks
Android (Java/Kotlin)
Android bindings are built with Gradle and published to Maven. Location:android/
Build the Android library:
C++ Header-Only API
The C++ API is a header-only library providing a higher-level interface than the C API. Location:core/moonshine-cpp.h
No separate build is required - just include the header in your project:
Building All Platforms
The release build script builds artifacts for all supported platforms:- Builds the core library for each platform
- Creates language bindings for Python, Swift, and Android
- Packages artifacts for distribution
- Generates checksums and metadata
Platform-Specific Notes
Linux
libmoonshine.a- Static librarylibmoonshine.so- Shared library (if enabled)- Test executables
macOS
- CoreFoundation
- Foundation
Windows
Use Visual Studio or the Visual Studio Build Tools:Android
Use Android NDK for cross-compilation:- Android SDK
- Android NDK r21 or higher
- Gradle 7.0+
iOS
Build using Xcode or Swift Package Manager:Dependencies
ONNX Runtime
The only major external dependency is ONNX Runtime. Pre-built libraries are included incore/third-party/onnxruntime/lib/ for:
- Linux (x86_64, ARM)
- macOS (x86_64, ARM64)
- Windows (x64)
- iOS (ARM64)
- Android (ARM, ARM64, x86, x86_64)
- Download or build ONNX Runtime for your platform
- Place the library files in
core/third-party/onnxruntime/lib/<platform>/ - Update CMake to link against your custom build
Other Dependencies
The core library has minimal dependencies:- Standard C++17 library
- ONNX Runtime
- Platform-specific system libraries (CoreFoundation on macOS, etc.)
Porting to New Platforms
To port Moonshine Voice to a new platform:-
Build the Core Library: Start with the CMake build. You’ll need:
- C++17 compiler
- ONNX Runtime for your platform
-
Link Against the C API: Use the C interface in
core/moonshine-c-api.h:- All functions have C linkage
- Most languages can call C functions
- Reference other language bindings as examples
-
Create Language Bindings (optional):
- Wrap the C API in your target language
- Provide idiomatic interfaces
- Handle memory management and callbacks
- Test: Run the core tests and create platform-specific tests
Debugging
Debug Builds
Build with debug symbols:Enable Logging
Set transcriber options to enable verbose logging:GDB/LLDB Debugging
Debug the C++ core:Save Audio Input
Debug audio processing by saving input:Contributing
If you’ve made improvements or bug fixes:- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request to github.com/moonshine-ai/moonshine
Next Steps
- Explore examples using the library
- Learn about the API
- Join the community for help