Crates.io | rustruut |
lib.rs | rustruut |
version | 0.0.4 |
created_at | 2025-09-18 09:15:40.478898+00 |
updated_at | 2025-09-23 20:20:09.408344+00 |
description | Text-to-IPA converter and phonetic translator for Rust, powered by the Goruut phonemization engine |
homepage | |
repository | |
max_upload_size | |
id | 1844449 |
size | 112,762 |
Like goruut except in Rust
cargo run --example usage
cargo test
use rustruut::{DependencyInjection, Phonemizer, models::requests::PhonemizeSentence};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let di = DependencyInjection::new();
let phonemizer = Phonemizer::new(di);
let req = PhonemizeSentence {
ipa_flavors: Vec::new(),
language: "EnglishAmerican".to_string(),
languages: Vec::new(),
sentence: "fast racing car".to_string(),
is_reverse: false,
split_sentences: false,
};
let resp = phonemizer.sentence(req)?;
println!("{}", resp.words.iter().map(|w| &w.phonetic).collect::<Vec<_>>().join(" "));
// Prints: fˈæst ɹˈeɪsɪŋ kˈɑɹ
// Now, convert it back
let req_reverse = PhonemizeSentence {
is_reverse: true,
..req
};
let resp_reverse = phonemizer.sentence(req_reverse)?;
println!("{}", resp_reverse.words.iter().map(|w| &w.phonetic).collect::<Vec<_>>().join(" "));
// Prints: fast racing car
Ok(())
}
ℹ️ For English, we recommend using
EnglishBritish
orEnglishAmerican
instead ofEnglish
. These dialect-specific models use high-quality Kokoro Misaki dictionaries and produce better results, especially for reversing IPA back to text.
let req = PhonemizeSentence {
language: "Uyghur".to_string(),
sentence: "قىزىل گۈل ئاتا".to_string(),
is_reverse: false,
// ... other fields
};
// Prints: qizil gyl ʔɑtɑ
// Now, convert it back
let req_reverse = PhonemizeSentence {
is_reverse: true,
// ... other fields same as above
};
// Prints: قىزىل گۈل ئاتا
The quality of translation varies across the 136 supported languages.
Use comma (,
) separated languages in languages
field. The first language is the preferred language:
let req = PhonemizeSentence {
languages: vec!["EnglishBritish".to_string(), "Slovak".to_string()],
sentence: "hello world ahojte notindictionary!!!!".to_string(),
// ... other fields
};
// Prints: həlˈoʊ wˈɜɹld aɦɔjcɛ ŋətandəktɪnˈɑːɪ!!!!
let req = PhonemizeSentence {
language: "EnglishBritish".to_string(),
sentence: "100 bottles".to_string(),
// ... other fields
};
// Prints: wˈʌn hˈʌndɹəd bˈɒtəlz
let req = PhonemizeSentence {
language: "Hebrew3".to_string(),
sentence: "השרים ביקשו מהשרים לפתוח את הדלתות של בית השרים.".to_string(),
// ... other fields
};
// Prints: hasaʁˈim bikʃˈu mehasaʁˈim liftˈoaχ ʔˈat hadlatˈot ʃˈel bˈet hasaʁˈim.
Punctuation handling is controlled through the response processing. Use the render_response_with_punct
function to include or exclude punctuation:
fn render_response_with_punct(resp: &PhonemizeSentenceResponse) -> String {
resp.words
.iter()
.map(|w| format!("{}{}{}", w.pre_punct, w.phonetic, w.post_punct))
.collect::<Vec<_>>()
.join(" ")
}
// For no punctuation, use only the phonetic field
resp.words.iter().map(|w| &w.phonetic).collect::<Vec<_>>().join(" ")
Not possible currently (TODO)
Possible but need explain (TODO)
Not possible currently (TODO)
Instead of normal DI use this:
// build DI with defaults (home folder implementations)
let di = DependencyInjection::with_parts(
di::default_impls::DummyPolicy::default(),
di::default_impls::DummyIpaFlavor::default(),
di::default_impls::DummyDict::default(),
di::default_impls::DummyApi::default(),
di::custom_impls::CustomFolder::default(),
);