mirror of
https://github.com/ndarilek/tts-rs.git
synced 2024-11-17 15:29:36 +00:00
Nolan Darilek
7b4fb8dae4
I'd previously attempted to normalize everything to `u8`, but this had some drawbacks: * It failed to account for some synthesis drivers defining normal as mid-range, while most define it very low. * It didn't track the normal value for a given synthesizer. * There was no clean way to map a curve between the minimum, normal, and maximum rates. Here we track the minimum, normal, and maximum values of rate, pitch, and volume. Sanity checks are done on set. Also, as a further proof-of-concept, all properties are now implemented for the WinRT driver.
48 lines
1.6 KiB
Rust
48 lines
1.6 KiB
Rust
use std::io;
|
|
|
|
use tts::*;
|
|
|
|
fn main() -> Result<(), Error> {
|
|
env_logger::init();
|
|
let mut tts = TTS::default()?;
|
|
tts.speak("Hello, world.", false)?;
|
|
let Features { rate, .. } = tts.supported_features();
|
|
if rate {
|
|
let original_rate = tts.get_rate()?;
|
|
tts.speak(format!("Current rate: {}", original_rate), false)?;
|
|
tts.set_rate(tts.max_rate())?;
|
|
tts.speak("This is very fast.", false)?;
|
|
tts.set_rate(tts.min_rate())?;
|
|
tts.speak("This is very slow.", false)?;
|
|
tts.set_rate(tts.normal_rate())?;
|
|
tts.speak("This is the normal rate.", false)?;
|
|
tts.set_rate(original_rate)?;
|
|
}
|
|
let Features { pitch, .. } = tts.supported_features();
|
|
if pitch {
|
|
let original_pitch = tts.get_pitch()?;
|
|
tts.set_pitch(tts.max_pitch())?;
|
|
tts.speak("This is high-pitch.", false)?;
|
|
tts.set_pitch(tts.min_pitch())?;
|
|
tts.speak("This is low pitch.", false)?;
|
|
tts.set_pitch(tts.normal_pitch())?;
|
|
tts.speak("This is normal pitch.", false)?;
|
|
tts.set_pitch(original_pitch)?;
|
|
}
|
|
let Features { volume, .. } = tts.supported_features();
|
|
if volume {
|
|
let original_volume = tts.get_volume()?;
|
|
tts.set_volume(tts.max_volume())?;
|
|
tts.speak("This is loud!", false)?;
|
|
tts.set_volume(tts.min_volume())?;
|
|
tts.speak("This is quiet.", false)?;
|
|
tts.set_volume(tts.normal_volume())?;
|
|
tts.speak("This is normal volume.", false)?;
|
|
tts.set_volume(original_volume)?;
|
|
}
|
|
tts.speak("Goodbye.", false)?;
|
|
let mut _input = String::new();
|
|
io::stdin().read_line(&mut _input)?;
|
|
Ok(())
|
|
}
|