speech-dispatcher-rs/speech-dispatcher/examples/list_voices.rs

30 lines
1.0 KiB
Rust
Raw Normal View History

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);
2022-01-27 16:21:53 +00:00
for module in modules {
if connection.set_output_module(&module).is_ok() {
2022-01-27 16:21:53 +00:00
println!("Listing voices for module {module}");
} else {
2022-01-27 16:21:53 +00:00
println!("Failed to set output module to {module}");
continue;
};
let voices = connection.list_synthesis_voices()?;
2022-01-27 16:21:53 +00:00
for voice in voices {
if let Some(variant) = voice.variant {
println!(
2022-01-27 16:21:53 +00:00
" Name: {} / Language: {} / Variant: {variant}",
voice.name, voice.language
);
} else {
println!(" Name: {} / Language: {}", voice.name, voice.language);
}
}
}
// Use connection.set_synthesis_voice(voice) to set the voice to use.
Ok(())
}