From f5f11b7cdfe21cc41b50cd8edca156c7d1455d6c Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Tue, 22 Sep 2020 14:51:59 -0500 Subject: [PATCH] Switch to using MediaPlaybackItem as WinRT utterance ID. --- src/backends/winrt.rs | 13 ++----------- src/lib.rs | 7 +++++-- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/backends/winrt.rs b/src/backends/winrt.rs index 32fb219..f558c91 100644 --- a/src/backends/winrt.rs +++ b/src/backends/winrt.rs @@ -1,7 +1,4 @@ #[cfg(windows)] -use std::sync::Mutex; - -use lazy_static::lazy_static; use log::{info, trace}; use tts_winrt_bindings::windows::media::core::MediaSource; @@ -24,10 +21,6 @@ pub struct WinRT { playback_list: MediaPlaybackList, } -lazy_static! { - static ref NEXT_UTTERANCE_ID: Mutex = Mutex::new(0); -} - impl WinRT { pub fn new() -> std::result::Result { info!("Initializing WinRT backend"); @@ -83,13 +76,11 @@ impl Backend for WinRT { self.reinit_player()?; } } - self.playback_list.items()?.append(item)?; + self.playback_list.items()?.append(&item)?; if !self.is_speaking()? { self.player.play()?; } - let mut utterance_id = NEXT_UTTERANCE_ID.lock().unwrap(); - *utterance_id += 1; - Ok(Some(UtteranceId::WinRT(*utterance_id))) + Ok(Some(UtteranceId::WinRT(item))) } fn stop(&mut self) -> std::result::Result<(), Error> { diff --git a/src/lib.rs b/src/lib.rs index 2d494cf..fc0558a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,6 +23,9 @@ use libc::c_char; use objc::{class, msg_send, sel, sel_impl}; use thiserror::Error; +#[cfg(windows)] +use tts_winrt_bindings::windows::media::playback::MediaPlaybackItem; + mod backends; pub enum Backends { @@ -40,14 +43,14 @@ pub enum Backends { AvFoundation, } -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq)] pub enum UtteranceId { #[cfg(target_os = "linux")] SpeechDispatcher(i32), #[cfg(target_arch = "wasm32")] Web(u64), #[cfg(windows)] - WinRT(u64), + WinRT(MediaPlaybackItem), } pub struct Features {