1
0
mirror of https://github.com/ndarilek/tts-rs.git synced 2024-11-17 20:09:37 +00:00
tts-rs/examples/hello_world.rs

40 lines
1.2 KiB
Rust
Raw Normal View History

2018-12-15 15:56:13 +00:00
use std::u8;
use tts::*;
2018-12-14 19:35:49 +00:00
2018-12-30 17:13:48 +00:00
fn main() -> Result<(), std::io::Error> {
2018-12-14 19:35:49 +00:00
env_logger::init();
2018-12-30 17:13:48 +00:00
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(u8::MAX)?;
tts.speak("This is very fast.", false)?;
tts.set_rate(0)?;
tts.speak("This is very slow.", false)?;
tts.set_rate(original_rate)?;
}
let Features { pitch, .. } = tts.supported_features();
if pitch {
let original_pitch = tts.get_pitch()?;
tts.set_pitch(u8::MAX)?;
tts.speak("This is high-pitch.", false)?;
tts.set_pitch(0)?;
tts.speak("This is low pitch.", false)?;
tts.set_pitch(original_pitch)?;
}
let Features { volume, .. } = tts.supported_features();
if volume {
let original_volume = tts.get_volume()?;
tts.set_volume(u8::MAX)?;
tts.speak("This is loud!", false)?;
tts.set_volume(0)?;
tts.speak("This is quiet.", false)?;
tts.set_volume(original_volume)?;
}
2018-12-30 17:13:48 +00:00
tts.speak("Goodbye.", false)?;
Ok(())
2018-12-14 19:35:49 +00:00
}