Python SDK
The underlying models are defined in Keras, so we can run using PyTorch, TensorFlow, or JAX backends. We also offer models converted to ONNX, which can be run using the ONNX runtime, and in CTranslate2 format, which often offers the lowest latency.
Keras
To get started, install the main pip package:
pip install useful-moonshine@git+https://github.com/moonshine-ai/moonshine.git
To run the provided inference code, you have to instruct Keras to use the PyTorch backend by setting an environment variable:
export KERAS_BACKEND=torch
To run with the TensorFlow backend, run the following to install Moonshine and set the environment variable:
pip install useful-moonshine[tensorflow]@git+https://github.com/moonshine-ai/moonshine.git
export KERAS_BACKEND=tensorflow
To run with the JAX backend, run the following:
pip install useful-moonshine[jax]@git+https://github.com/moonshine-ai/moonshine.git
export KERAS_BACKEND=jax
Use useful-moonshine[jax-cuda]
for JAX on GPU
ONNX
You need to install a slightly different pip
package to run ONNX:
pip install useful-moonshine-onnx@git+https://git@github.com/moonshine-ai/moonshine.git#subdirectory=moonshine-onnx
We quantize the ONNX models, so they offer the smallest file sizes (26MB for tiny, 57MB for base).
Testing
This command should transcribe a test audio file included with the package:
python3 -c "import moonshine; print(moonshine.transcribe(moonshine.ASSETS_DIR / 'beckett.wav', 'moonshine/tiny'))"
If you’re using the ONNX package, you’ll need to import moonshine as moonshine_onnx
, but otherwise the interface is identical.
python3 -c "import moonshine_onnx as moonshine; print(moonshine.transcribe(moonshine.ASSETS_DIR / 'beckett.wav', 'moonshine/tiny'))"
In both cases the expected output is:
['Ever tried ever failed, no matter try again, fail again, fail better.']