Crates.io | cmudict-fast |
lib.rs | cmudict-fast |
version | 0.8.0 |
source | src |
created_at | 2021-02-26 01:02:05.440236 |
updated_at | 2021-02-27 00:58:54.274206 |
description | An updated and improved fork of the library for using the CMUSphinx pronunciation dictionary |
homepage | https://github.com/BenjaminHinchliff/cmudict-fast |
repository | https://github.com/BenjaminHinchliff/cmudict-fast.git |
max_upload_size | |
id | 360763 |
size | 3,808,687 |
This is a fork of the original rust library for getting pronunciations from the CMUSphinx pronunciation dictionary.
:warning: 0.6.0 onward is not api compatible with the original crate. 0.5.0 or before is mostly api compatible but notably doesn't have the download utility function.
cmudict_core
and cmudict
into one cratefailure
crate to thiserror
based errorsThe last of those changes is where the name comes from - as a result of the entire dictionary being loaded into volitile memory, each individual lookup is much faster than the original crate (should be O(1) on average with worst case O(n)). Of course, there's the downside that it takes longer to createthe object and uses more memory, but for the application I initially created this for the lookup time was essential.
To use in your rust
project, add the following to your Cargo.toml
:
[dependencies]
cmudict-fast = "0.8"
To use the dictionary, you have to get an instance of the Cmudict
struct:
use cmudict_fast::Cmudict;
fn main() {
let dict = Cmudict::new("./path/to/a/cmudict/file").expect("Couldn't make Cmudict");
}
You can retrieve the pronunciation for a word like this:
use cmudict_fast::Cmudict;
fn main() {
let dict = Cmudict::new("path/to/cmudict").expect("Couldn't get/make Cmudict");
let word = dict.get("apple").unwrap().pronunciation();
println!("{:?}", word); // &[Symbol::AE(Stress::Primary), Symbol::P, Symbol::AH(Stress::None), Symbol::L]
}