Safe FFI bindings around the Vosk API Speech Recognition library.
```rust // Simplified version of examples/read_wav.rs
// Normally you would not want to hardcode the audio samples let samples = vec![100, -2, 700, 30, 4, 5]; let model_path = "/path/to/model";
let model = Model::new(model_path).unwrap(); let mut recognizer = Recognizer::new(&model, 16000.0).unwrap();
recognizer.setmaxalternatives(10); recognizer.setwords(true); recognizer.setpartial_words(true);
for sample in samples.chunks(100) { recognizer.acceptwaveform(sample); println!("{:#?}", recognizer.partialresult()); }
println!("{:#?}", recognizer.final_result().multiple().unwrap()); ```
The Vosk-API dynamic libraries have to be discoverable by the rust linker (static libraries are not available). Download the zip file for your platform here and:
Do either of the following:
RUSTFLAGS
environment variable to provide the path to the variables like so:
RURSTFLAGS=-L/path/to/the/libraries
cargo:rustc-link-search
or cargo:rustc-link-lib
.Although both approaches are equivalent, the latter is more practical as it does not require the developer to remember a terminal command.
PATH
environment variable.Do either of the following:
/usr/local/lib
or /usr/lib
.LIBRARY_PATH
environment variable to the directory where you saved the libraries, lik soThe libraries also have to be discoverable by the executable at runtime. You will have to follow one of the approaches in the same section you chose in compilation
For both approaches, you will need to copy the libraries to the root of the executable
(target/<cargo profile name>
by default). It is recommended that you use a tool such as
cargo-make to automate moving the libraries
from another, more practical, directory to the destination during build.
If you added your libraries to a directory in your PATH
, no extra steps are needed as long as that is also the case for the target machine.
LD_LIBRARY_PATH
environment variable, like so: LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/the/libraries
.
Note that this directory does not have to be the same added to LIBRARY_PATH
in the compilation step.