mirror of
https://github.com/ndarilek/tts-rs.git
synced 2024-11-22 22:59:37 +00:00
Add example that exposes WinRT issue where speech doubles in some circumstances.
This commit is contained in:
parent
29c0a8463e
commit
2343523bb6
43
examples/99bottles.rs
Normal file
43
examples/99bottles.rs
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
use std::io;
|
||||||
|
use std::{thread, time};
|
||||||
|
|
||||||
|
#[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};
|
||||||
|
|
||||||
|
use tts::*;
|
||||||
|
|
||||||
|
fn main() -> Result<(), Error> {
|
||||||
|
env_logger::init();
|
||||||
|
let mut tts = TTS::default()?;
|
||||||
|
let Features {
|
||||||
|
utterance_callbacks,
|
||||||
|
..
|
||||||
|
} = tts.supported_features();
|
||||||
|
let mut bottles = 99;
|
||||||
|
while bottles > 0 {
|
||||||
|
tts.speak(format!("{} bottles of beer on the wall,", bottles), false)?;
|
||||||
|
tts.speak(format!("{} bottles of beer,", bottles), false)?;
|
||||||
|
tts.speak("Take one down, pass it around", false)?;
|
||||||
|
tts.speak("Give us a bit to drink this...", false)?;
|
||||||
|
let time = time::Duration::from_secs(5);
|
||||||
|
thread::sleep(time);
|
||||||
|
bottles -= 1;
|
||||||
|
tts.speak(format!("{} bottles of beer on the wall,", bottles), false)?;
|
||||||
|
}
|
||||||
|
let mut _input = String::new();
|
||||||
|
// 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.
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
{
|
||||||
|
let run_loop: id = unsafe { NSRunLoop::currentRunLoop() };
|
||||||
|
unsafe {
|
||||||
|
let _: () = msg_send![run_loop, run];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
io::stdin().read_line(&mut _input)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user