Closed FerrisWasTaken closed 2 years ago
The speech calls aren't blocking. You need that loop in the end to keep the program from exiting.
use tts::*;
fn main() -> Result<(), Error> {
let mut tts = Tts::default()?;
tts.speak("Hello, world.", false)?;
let Features { voice, .. } = tts.supported_features();
if voice {
let voices = tts.voices()?;
println!("Available voices:\n===");
for v in &voices {
println!("{:?}", v);
}
let Features { get_voice, .. } = tts.supported_features();
let original_voice = if get_voice { tts.voice()? } else { None };
for v in &voices {
tts.set_voice(v)?;
tts.speak(format!("This is {}.", v.name()), false)?;
}
if let Some(original_voice) = original_voice {
tts.set_voice(&original_voice)?;
}
}
tts.speak("Goodbye.", false)?;
Ok(())
}
doesnt work. Can you send a minimal working example?
You've still got nothing to keep your program from exiting before everything speaks.
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)?;
No, it wouldn't, these calls are non-blocking and you've still got nothing to keep the program from exiting.
Why did you remove this? This is what's needed.
letmut_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")] { letrunloop: id= unsafe{ NSRunLoop::currentRunLoop() }; unsafe{ let: () = msg_send![run_loop, run]; } } io::stdin().read_line(&mut_input)?;
The code is after stripping the macos parts
but when i strip it down to
No sound is generated NOTE: I have speechd installed on Linux.