2019-09-10 15:41:28 +00:00
|
|
|
use std::io;
|
2018-12-15 15:56:13 +00:00
|
|
|
|
2020-08-12 14:49:51 +00:00
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
use cocoa_foundation::base::id;
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
use cocoa_foundation::foundation::NSRunLoop;
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
use objc::{msg_send, sel, sel_impl};
|
|
|
|
|
2019-03-25 16:34:30 +00:00
|
|
|
use tts::*;
|
2018-12-14 19:35:49 +00:00
|
|
|
|
2020-05-18 20:01:28 +00:00
|
|
|
fn main() -> Result<(), Error> {
|
2018-12-14 19:35:49 +00:00
|
|
|
env_logger::init();
|
2021-03-31 15:40:42 +00:00
|
|
|
let mut tts = Tts::default()?;
|
2020-09-23 15:12:51 +00:00
|
|
|
let Features {
|
|
|
|
utterance_callbacks,
|
|
|
|
..
|
|
|
|
} = tts.supported_features();
|
|
|
|
if utterance_callbacks {
|
2020-11-03 17:03:55 +00:00
|
|
|
tts.on_utterance_begin(Some(Box::new(|utterance| {
|
2020-09-23 15:12:51 +00:00
|
|
|
println!("Started speaking {:?}", utterance)
|
2020-09-25 16:08:19 +00:00
|
|
|
})))?;
|
2020-11-03 17:03:55 +00:00
|
|
|
tts.on_utterance_end(Some(Box::new(|utterance| {
|
2020-09-23 15:12:51 +00:00
|
|
|
println!("Finished speaking {:?}", utterance)
|
2020-09-25 16:08:19 +00:00
|
|
|
})))?;
|
2020-11-03 17:03:55 +00:00
|
|
|
tts.on_utterance_stop(Some(Box::new(|utterance| {
|
2020-10-08 14:06:48 +00:00
|
|
|
println!("Stopped speaking {:?}", utterance)
|
|
|
|
})))?;
|
2020-09-23 15:12:51 +00:00
|
|
|
}
|
2020-11-02 19:30:39 +00:00
|
|
|
let Features { is_speaking, .. } = tts.supported_features();
|
|
|
|
if is_speaking {
|
|
|
|
println!("Are we speaking? {}", tts.is_speaking()?);
|
|
|
|
}
|
2018-12-30 17:13:48 +00:00
|
|
|
tts.speak("Hello, world.", false)?;
|
2019-03-25 16:34:30 +00:00
|
|
|
let Features { rate, .. } = tts.supported_features();
|
|
|
|
if rate {
|
|
|
|
let original_rate = tts.get_rate()?;
|
|
|
|
tts.speak(format!("Current rate: {}", original_rate), false)?;
|
Clean up speech synthesis properties, and implement everything for WinRT.
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.
2020-05-18 23:12:59 +00:00
|
|
|
tts.set_rate(tts.max_rate())?;
|
2019-03-25 16:34:30 +00:00
|
|
|
tts.speak("This is very fast.", false)?;
|
Clean up speech synthesis properties, and implement everything for WinRT.
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.
2020-05-18 23:12:59 +00:00
|
|
|
tts.set_rate(tts.min_rate())?;
|
2019-03-25 16:34:30 +00:00
|
|
|
tts.speak("This is very slow.", false)?;
|
Clean up speech synthesis properties, and implement everything for WinRT.
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.
2020-05-18 23:12:59 +00:00
|
|
|
tts.set_rate(tts.normal_rate())?;
|
|
|
|
tts.speak("This is the normal rate.", false)?;
|
2019-03-25 16:34:30 +00:00
|
|
|
tts.set_rate(original_rate)?;
|
|
|
|
}
|
|
|
|
let Features { pitch, .. } = tts.supported_features();
|
|
|
|
if pitch {
|
|
|
|
let original_pitch = tts.get_pitch()?;
|
Clean up speech synthesis properties, and implement everything for WinRT.
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.
2020-05-18 23:12:59 +00:00
|
|
|
tts.set_pitch(tts.max_pitch())?;
|
2019-03-25 16:34:30 +00:00
|
|
|
tts.speak("This is high-pitch.", false)?;
|
Clean up speech synthesis properties, and implement everything for WinRT.
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.
2020-05-18 23:12:59 +00:00
|
|
|
tts.set_pitch(tts.min_pitch())?;
|
2019-03-25 16:34:30 +00:00
|
|
|
tts.speak("This is low pitch.", false)?;
|
Clean up speech synthesis properties, and implement everything for WinRT.
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.
2020-05-18 23:12:59 +00:00
|
|
|
tts.set_pitch(tts.normal_pitch())?;
|
|
|
|
tts.speak("This is normal pitch.", false)?;
|
2019-03-25 16:34:30 +00:00
|
|
|
tts.set_pitch(original_pitch)?;
|
|
|
|
}
|
|
|
|
let Features { volume, .. } = tts.supported_features();
|
|
|
|
if volume {
|
|
|
|
let original_volume = tts.get_volume()?;
|
Clean up speech synthesis properties, and implement everything for WinRT.
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.
2020-05-18 23:12:59 +00:00
|
|
|
tts.set_volume(tts.max_volume())?;
|
2019-03-25 16:34:30 +00:00
|
|
|
tts.speak("This is loud!", false)?;
|
Clean up speech synthesis properties, and implement everything for WinRT.
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.
2020-05-18 23:12:59 +00:00
|
|
|
tts.set_volume(tts.min_volume())?;
|
2019-03-25 16:34:30 +00:00
|
|
|
tts.speak("This is quiet.", false)?;
|
Clean up speech synthesis properties, and implement everything for WinRT.
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.
2020-05-18 23:12:59 +00:00
|
|
|
tts.set_volume(tts.normal_volume())?;
|
|
|
|
tts.speak("This is normal volume.", false)?;
|
2019-03-25 16:34:30 +00:00
|
|
|
tts.set_volume(original_volume)?;
|
|
|
|
}
|
2018-12-30 17:13:48 +00:00
|
|
|
tts.speak("Goodbye.", false)?;
|
2019-09-10 15:41:28 +00:00
|
|
|
let mut _input = String::new();
|
2020-09-23 15:33:30 +00:00
|
|
|
// The below is only needed to make the example run on MacOS because there is no NSRunLoop in this context.
|
|
|
|
// It shouldn't be needed in an app or game that almost certainly has one already.
|
2020-08-12 14:49:51 +00:00
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
{
|
|
|
|
let run_loop: id = unsafe { NSRunLoop::currentRunLoop() };
|
|
|
|
unsafe {
|
|
|
|
let _: () = msg_send![run_loop, run];
|
|
|
|
}
|
|
|
|
}
|
2019-09-10 15:41:28 +00:00
|
|
|
io::stdin().read_line(&mut _input)?;
|
2018-12-30 17:13:48 +00:00
|
|
|
Ok(())
|
2018-12-14 19:35:49 +00:00
|
|
|
}
|