From 15f28c9af4f93f6013874e351ee53de968b39fb8 Mon Sep 17 00:00:00 2001 From: Bear-03 <64696287+Bear-03@users.noreply.github.com> Date: Thu, 21 Jul 2022 01:25:14 +0200 Subject: [PATCH 1/4] Derive common traits for Gender and Voice --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 76c7b94..8a8df57 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -648,13 +648,13 @@ impl Drop for Tts { } } -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum Gender { Male, Female, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct Voice { pub(crate) id: String, pub(crate) name: String, From 748f07138dfd05b8a91086ef80f6f2aff00904ff Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Thu, 21 Jul 2022 18:34:22 -0500 Subject: [PATCH 2/4] Bump version and dependency. --- Cargo.toml | 4 ++-- src/backends/winrt.rs | 25 ++++++++++++++----------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 361d164..41e605a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tts" -version = "0.22.4" +version = "0.22.5" authors = ["Nolan Darilek "] repository = "https://github.com/ndarilek/tts-rs" description = "High-level Text-To-Speech (TTS) interface" @@ -28,7 +28,7 @@ env_logger = "0.9" [target.'cfg(windows)'.dependencies] tolk = { version = "0.5", optional = true } -windows = { version = "0.38", features = ["alloc", "Foundation", "Foundation_Collections", "Media_Core", "Media_Playback", "Media_SpeechSynthesis", "Storage_Streams"] } +windows = { version = "0.39", features = ["Foundation", "Foundation_Collections", "Media_Core", "Media_Playback", "Media_SpeechSynthesis", "Storage_Streams"] } [target.'cfg(target_os = "linux")'.dependencies] speech-dispatcher = { version = "0.13", default-features = false } diff --git a/src/backends/winrt.rs b/src/backends/winrt.rs index ceb5f00..d3a349a 100644 --- a/src/backends/winrt.rs +++ b/src/backends/winrt.rs @@ -84,7 +84,7 @@ impl WinRt { backend_to_speech_synthesizer.insert(bid, synth.clone()); drop(backend_to_speech_synthesizer); let bid_clone = bid; - player.MediaEnded(TypedEventHandler::new( + player.MediaEnded(&TypedEventHandler::new( move |sender: &Option, _args| { if let Some(sender) = sender { let backend_to_media_player = BACKEND_TO_MEDIA_PLAYER.lock().unwrap(); @@ -108,14 +108,14 @@ impl WinRt { tts.Options()?.SetSpeakingRate(utterance.rate.into())?; tts.Options()?.SetAudioPitch(utterance.pitch.into())?; tts.Options()?.SetAudioVolume(utterance.volume.into())?; - tts.SetVoice(utterance.voice.clone())?; - let stream = tts - .SynthesizeTextToStreamAsync(utterance.text.as_str())? - .get()?; + tts.SetVoice(&utterance.voice)?; + let text = &utterance.text; + let stream = + tts.SynthesizeTextToStreamAsync(&text.into())?.get()?; let content_type = stream.ContentType()?; let source = - MediaSource::CreateFromStream(stream, content_type)?; - sender.SetSource(source)?; + MediaSource::CreateFromStream(&stream, &content_type)?; + sender.SetSource(&source)?; sender.Play()?; if let Some(callback) = callbacks.utterance_begin.as_mut() { callback(utterance.id); @@ -193,10 +193,13 @@ impl Backend for WinRt { self.synth.Options()?.SetSpeakingRate(self.rate.into())?; self.synth.Options()?.SetAudioPitch(self.pitch.into())?; self.synth.Options()?.SetAudioVolume(self.volume.into())?; - let stream = self.synth.SynthesizeTextToStreamAsync(text)?.get()?; + let stream = self + .synth + .SynthesizeTextToStreamAsync(&text.into())? + .get()?; let content_type = stream.ContentType()?; - let source = MediaSource::CreateFromStream(stream, content_type)?; - self.player.SetSource(source)?; + let source = MediaSource::CreateFromStream(&stream, &content_type)?; + self.player.SetSource(&source)?; self.player.Play()?; let mut callbacks = CALLBACKS.lock().unwrap(); let callbacks = callbacks.get_mut(&self.id).unwrap(); @@ -319,7 +322,7 @@ impl Backend for WinRt { for v in SpeechSynthesizer::AllVoices()? { let vid: String = v.Id()?.try_into()?; if vid == voice.id { - self.voice = v.clone(); + self.voice = v; return Ok(()); } } From 7cf80fb64d817b8e34f5f4479f7850cffc1921a5 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Fri, 22 Jul 2022 10:08:13 -0500 Subject: [PATCH 3/4] WinRT: Correctly set voice for case where no utterances are in queue. Fixes #29 --- src/backends/winrt.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backends/winrt.rs b/src/backends/winrt.rs index d3a349a..70d765f 100644 --- a/src/backends/winrt.rs +++ b/src/backends/winrt.rs @@ -193,6 +193,7 @@ impl Backend for WinRt { self.synth.Options()?.SetSpeakingRate(self.rate.into())?; self.synth.Options()?.SetAudioPitch(self.pitch.into())?; self.synth.Options()?.SetAudioVolume(self.volume.into())?; + self.synth.SetVoice(&self.voice)?; let stream = self .synth .SynthesizeTextToStreamAsync(&text.into())? From f404e180e41275e43d6ea3afd2834cd8f86d126a Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Fri, 22 Jul 2022 10:13:32 -0500 Subject: [PATCH 4/4] Bump version. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 41e605a..37edeb7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tts" -version = "0.22.5" +version = "0.23.0" authors = ["Nolan Darilek "] repository = "https://github.com/ndarilek/tts-rs" description = "High-level Text-To-Speech (TTS) interface"