#speech-recognition #recognizer #stt #api-bindings #toolkit #true

vosk

Safe wrapper around the Vosk API Speech Recognition Toolkit

2 unstable releases

0.2.0 Oct 1, 2022
0.1.0 Jun 29, 2022

#383 in Audio

Download history 59/week @ 2023-11-20 46/week @ 2023-11-27 31/week @ 2023-12-04 39/week @ 2023-12-11 82/week @ 2023-12-18 29/week @ 2023-12-25 20/week @ 2024-01-01 47/week @ 2024-01-08 62/week @ 2024-01-15 95/week @ 2024-01-22 130/week @ 2024-01-29 63/week @ 2024-02-05 69/week @ 2024-02-12 79/week @ 2024-02-19 117/week @ 2024-02-26 113/week @ 2024-03-04

388 downloads per month
Used in marek_vosk_speech_recogni…

MIT license

44KB
567 lines

Vosk

Latest release Documentation MIT Build Status

Safe FFI bindings around the Vosk API Speech Recognition Toolkit.

Usage

// 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.set_max_alternatives(10);
recognizer.set_words(true);
recognizer.set_partial_words(true);

for sample in samples.chunks(100) {
    recognizer.accept_waveform(sample);
    println!("{:#?}", recognizer.partial_result());
}

println!("{:#?}", recognizer.final_result().multiple().unwrap());

Setup

Compilation

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:

  • Use the RUSTFLAGS environment variable to provide the path to the variables like so: RUSTFLAGS=-L/path/to/the/libraries
  • Create a build script and provide cargo with the path to the libraries with 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.

Windows-only

  • Move the libraries to a directory in your PATH environment variable.

Linux-only

Do either of the following:

  • Move them to /usr/local/lib or /usr/lib.
  • Set the LIBRARY_PATH environment variable to the directory containing the libraries.

Execution

The 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.

Windows-only

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.

Linux-only

  • If you followed option 1 in the compilation section: No extra steps are needed as long as the target machine also has the libraries in one of the mentioned directories.
  • If you followed option 2: You will need to add the directory containing the libraries to the LD_LIBRARY_PATH environment variable. Note that this directory does not have to be the same added to LIBRARY_PATH in the compilation step.

Dependencies

~0.7–1.4MB
~33K SLoC