moonshine-zig

active

Zig bindings for the Moonshine library's C API

Overview

Zig bindings for Moonshine. See the github or their website for more information about their project. To put it simply, however, Moonshine is a library written primarily in C++ designed for interfacing with ASR and TTS models to create voice interfaces. TTS is more well-known and is Text To Speech. ASR is less well-known. ASR stands for Automatic Speech Recognition and it is a speech to text (stt) technology built using specialized machine learning techniques. Moonshine has several language APIs such as Python, Swift, – and C.

The C API can be imported directly into Zig by fetching translate-c tool into your project. Then, go to the github, and grab a copy of the file /core/moonshine-c-api.h, and translate it into a Zig module using build.zig. You would need onnxruntime library and you would need a matching version of libmoonshine. This is tedious work, though.

That’s where moonshine-zig comes in! These bindings are a fork of the moonshine code ported to the Zig build system, and with idiomatic Zig wrappers for the C API. So, you can import the project with zig fetch, and import the module in build.zig.

Noteworthy Limitations

Firstly, there are some binary blobs in the upstream Moonshine repository that are used for certain targets, and these were removed entirely from the bindings. The reasoning is that they are not relevant and more importantly the git lfs that they use is impractical for a Zig binding library to be fetched.

Secondly, these bindings are a practical tool for myself. While I am a passionate open-source developer, I created these bindings for my own project lavoz, and I am prioritizing the features that I use in that project. At the time of writing, those are the features needed for transcription using streaming. I do plan on completing the entire library with idiomatic Zig, but I am one developer working for free. Handwritten contributions by my fellow humans are welcome.

While the Zig bindings are limited, features that I have not gotten to yet can be accessed by the re-exported top-level c struct. If you have the time to write a wrapper for what you’re using, that would be helpful!