1
0
mirror of https://github.com/ndarilek/tts-rs.git synced 2024-11-22 18:29:38 +00:00

Fix double-speaking bug for good, hopefully.

This commit is contained in:
Nolan Darilek 2020-11-11 10:27:03 -06:00
parent e1791c7046
commit 6a706f36ab
3 changed files with 44 additions and 3 deletions

View File

@ -15,7 +15,7 @@ fn main() -> Result<(), Error> {
let mut tts = TTS::default()?;
let mut bottles = 99;
while bottles > 0 {
tts.speak(format!("{} bottles of beer on the wall,", bottles), true)?;
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)?;

35
examples/ramble.rs Normal file
View File

@ -0,0 +1,35 @@
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 mut phrase = 1;
loop {
tts.speak(format!("Phrase {}", phrase), false);
let time = time::Duration::from_secs(5);
thread::sleep(time);
phrase += 1;
}
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(())
}

View File

@ -4,7 +4,7 @@ use std::sync::Mutex;
use lazy_static::lazy_static;
use log::{info, trace};
use winrt::ComInterface;
use winrt::*;
use tts_winrt_bindings::windows::media::playback::{
CurrentMediaPlaybackItemChangedEventArgs, MediaPlaybackItem, MediaPlaybackList,
@ -60,7 +60,10 @@ impl WinRT {
*backend_id += 1;
let mut backend_to_media_player = BACKEND_TO_MEDIA_PLAYER.lock().unwrap();
backend_to_media_player.insert(bid, player.clone());
player.media_ended(TypedEventHandler::new(|sender, _args| {
player.media_ended(TypedEventHandler::new(|sender: &MediaPlayer, _args| {
let source = sender.source()?;
let source: MediaPlaybackList = source.try_into()?;
source.items()?.clear()?;
let backend_to_media_player = BACKEND_TO_MEDIA_PLAYER.lock().unwrap();
let id = backend_to_media_player.iter().find(|v| v.1 == sender);
if let Some(id) = id {
@ -80,6 +83,9 @@ impl WinRT {
backend_to_playback_list.insert(bid, playback_list.clone());
playback_list.current_item_changed(TypedEventHandler::new(
|sender: &MediaPlaybackList, args: &CurrentMediaPlaybackItemChangedEventArgs| {
println!("Changed");
println!("{:?}, {:?}", args.old_item()?, args.new_item()?);
//sender.items()?.clear()?;
let backend_to_playback_list = BACKEND_TO_PLAYBACK_LIST.lock().unwrap();
let id = backend_to_playback_list.iter().find(|v| v.1 == sender);
if let Some(id) = id {