Crates.io | vosk |
lib.rs | vosk |
version | |
source | src |
created_at | 2022-06-29 17:42:37.539507 |
updated_at | 2024-10-27 20:19:13.131426 |
description | Safe wrapper around the Vosk API Speech Recognition Toolkit |
homepage | |
repository | https://github.com/Bear-03/vosk-rs |
max_upload_size | |
id | 615597 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Safe FFI bindings around the Vosk API Speech Recognition Toolkit.
// 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());
The Vosk-API libraries have to be discoverable by the rust linker. Download the zip file containing the dynamic libraries for your platform here. For iOS development you have to use static libraries. Get the static libraries from the vosk-api team.
Do either of the following:
RUSTFLAGS
environment variable to provide the path to the variables like so:
RUSTFLAGS=-L/path/to/the/libraries
with cargo:rustc-link-search
or cargo:rustc-link-lib
.PATH
environment variable./usr/local/lib
, /usr/lib
or set the LIBRARY_PATH
environment variable to the directory containing the libraries.Although the approaches are equivalent, using a build script is more convenient because it does not require the developer to remember a terminal command or change anything outside the project scope.
staticlib
.cargo:rustc-link-search=
and cargo:rustc-link-lib=static=
.In real-world scenarios, one will use Rust to cross compile a library (e.g. Android and iOS). Therefore, we need both cdylib
as well as the staticlib
as crate-type. If you compile as usual with cargo build (e.g.: cargo build --target aarch64-apple-ios --release
) it will not work, because cargo tries to build the dylib as well. Fortunately, since rust 1.64. there is a new option for rustc in the stable channel. Because of this, the following will work: cargo rustc --crate-type staticlib --lib --target aarch64-apple-ios --release
Executables compiled with a dynamic lib must have access to the vosk library at runtime. Executables compiled with a statically compiled library do not.
Do either of the following:
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: Move the libraries to a directory in your PATH
environment variable.
Linux: Move them to /usr/local/lib
, /usr/lib
or set the LD_LIBRARY_PATH
environment variable to the directory containing the libraries. Note: LD_LIBRARY_PATH
is not the same as LIBRARY_PATH
mentioned in the compilation step.
Enable Bitcode
to no for your targetAccelerate Framework
from the iOS SDK to your project