Standalone C++ implementation of Moonshine ASR with ONNXRuntime and no other dependencies.
Moonshine ASR is an Automatic Speech Recognition (ASR) system implemented in C++ using ONNX Runtime. This project provides a standalone implementation that can be built and run on various platforms.
- CMake 3.15 or higher
- A C++17 compatible compiler
- ONNX Runtime for the building OS will be fetched in build time.
-
Open a PowerShell terminal.
-
Navigate to the root directory of the project.
-
Run the build script:
.\scripts\build.ps1 -BuildType Release
-
Open a terminal.
-
Navigate to the root directory of the project.
-
Run the build script:
./scripts/build.sh
-
Create a build directory:
mkdir -p build cd build
-
Configure the project with CMake:
cmake -DCMAKE_BUILD_TYPE=Release ..
-
Build the project:
cmake --build .
-
Install the project:
cmake --install . --prefix ../dist
After building you should have a folder like so (e.g. on Windows):
./dist
├───bin
│ moonshine_example.exe
│ moonshine_live.exe
│ onnxruntime.dll
│ onnxruntime_providers_shared.dll
│
├───include
│ └───moonshine
│ moonshine.hpp
│
└───lib
│ moonshine.lib
│ onnxruntime.dll
│ onnxruntime_providers_shared.dll
│
└───cmake
└───moonshine
moonshine-config-version.cmake
moonshine-config.cmake
moonshine-targets-release.cmake
moonshine-targets.cmake
Which will allow you to link against moonshine.cpp with a CMake find_package()
.
The project includes two example applications:
moonshine_example
: File-based transcriptionmoonshine_live
: Real-time microphone transcription (requires SDL2)
Build the project with examples enabled:
.\scripts\build.ps1 -BuildType Release -BuildExamples
Transcribe audio from a WAV file:
.\dist\bin\moonshine_example.exe <models_dir> <wav_file>
Replace <models_dir> with the directory containing your ONNX models and <wav_file> with the path to a WAV file.
Example:
.\dist\bin\moonshine_example.exe models\ example.wav
Real-time transcription from microphone input:
.\dist\bin\moonshine_live.exe <models_dir>
Example:
.\dist\bin\moonshine_live.exe models\
Press ESC or q to stop recording and exit.
To use Moonshine ASR as a library in your C++ project, follow these steps:
-
Build and install the Moonshine ASR library as described in the Build Instructions.
-
Link against the installed library in your CMake project:
cmake_minimum_required(VERSION 3.15) project(my_project) # Find the Moonshine package find_package(Moonshine REQUIRED) add_executable(my_project main.cpp) # Link against the Moonshine library target_link_libraries(my_project PRIVATE Moonshine::moonshine)
-
Include the Moonshine header in your source code:
#include <moonshine.hpp> int main() { MoonshineModel model("path/to/models"); // Use the model... return 0; }
This project is based on the Moonshine ASR system: https://github.com/usefulsensors/moonshine. Special thanks to the Moonshine team for their contributions.
This project is licensed under the MIT License. See the LICENSE file for details.