examples/c++/README.md
This is a minimal, platform independent example of using the C++ interface to the Moonshine Voice Library.
To use this you'll first need to download a prebuilt version of the library, or build it yourself using cmake in core/ if you're on a platform without a prebuilt version.
The library files are available as part of our releases on GitHub. Look for the most recent version, and you should see a file called moonshine-voice-_.tgz, where _ is your platform. Download and extract that archive, placing the resulting folder in this examples/c++ directory.
For example, on MacOS you can download and extract the library with:
cd examples/c++
curl -O -L https://github.com/moonshine-ai/moonshine/releases/download/v0.0.59/moonshine-voice-macos-arm64.tar.gz
tar xzf moonshine-voice-macos-arm64.tar.gz
The archive contains a .a or .lib archive (depending on your platform) inside the lib folder. This is the static library you'll need to link against. There are also two headers, one for the low-level C API, and another for the higher-level C++ framework that's built on top of it.
Since this is a generic C++ example, I'll show the simplest possible build command lines on some common platforms. You should replace moonshine-voice-* with the name of the library you downloaded.
g++ transcriber.cpp \
-Imoonshine-voice-linux-x86_64/include \
-Lmoonshine-voice-linux-x86_64/lib \
-lmoonshine \
-o transcriber
g++ text-to-speech.cpp \
-Imoonshine-voice-linux-x86_64/include \
-Lmoonshine-voice-linux-x86_64/lib \
-lmoonshine \
-o text-to-speech
export LD_LIBRARY_PATH=`pwd`/moonshine-voice-linux-x86_64/lib
g++ transcriber.cpp \
-Imoonshine-voice-macos-arm64/include \
-Lmoonshine-voice-macos-arm64/lib \
-lmoonshine \
-o transcriber \
-framework CoreFoundation \
-framework Foundation
g++ text-to-speech.cpp \
-Imoonshine-voice-macos-arm64/include \
-Lmoonshine-voice-macos-arm64/lib \
-lmoonshine \
-o text-to-speech \
-framework CoreFoundation \
-framework Foundation
g++ transcriber.cpp \
-Imoonshine-voice-macos-x86_64/include \
-Lmoonshine-voice-macos-x86_64/lib \
-lmoonshine \
-o transcriber \
-framework CoreFoundation \
-framework Foundation
You should now have an executable called transcriber in this folder. To test it, run ./transcriber and you should see some transcription results. You can try different models and inputs using --model-path, --model-arch, and --wav-path.