speech-dispatcher-rs/speech-dispatcher/examples/list_voices.rs
Malloc Voidstar 143147036c
Add support for listing voices
Rebased on top of the result changes.
2022-01-10 18:26:02 -08:00

30 lines
1.1 KiB
Rust

use speech_dispatcher::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let connection = Connection::open("list_voices", "list_voices", "list_voices", Mode::Threaded)?;
let modules = connection.list_output_modules()?;
println!("Modules available: {:?}", modules);
for module in modules.into_iter() {
if connection.set_output_module(&module).is_ok() {
println!("Listing voices for module {}", module);
} else {
println!("Failed to set output module to {}", module);
continue;
};
let voices = connection.list_synthesis_voices()?;
for voice in voices.into_iter() {
if let Some(variant) = voice.variant.as_deref() {
println!(
" Name: {} / Language: {} / Variant: {}",
voice.name, voice.language, variant
);
} else {
println!(" Name: {} / Language: {}", voice.name, voice.language);
}
}
}
// Use connection.set_synthesis_voice(voice.name) to set the voice to use.
Ok(())
}