From 1526602ad8fb7d1fa95c36f1c4ed9094d520cad2 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Sun, 14 Jun 2020 18:56:01 -0500 Subject: [PATCH] Don't close `MediaPlayer` when stopping speech, and actually support interruption. --- src/backends/winrt.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/backends/winrt.rs b/src/backends/winrt.rs index 54ffb94..075fa08 100644 --- a/src/backends/winrt.rs +++ b/src/backends/winrt.rs @@ -12,7 +12,9 @@ import!( use log::{info, trace}; use windows::media::core::MediaSource; -use windows::media::playback::{MediaPlaybackItem, MediaPlaybackList, MediaPlaybackState, MediaPlayer}; +use windows::media::playback::{ + MediaPlaybackItem, MediaPlaybackList, MediaPlaybackState, MediaPlayer, +}; use windows::media::speech_synthesis::SpeechSynthesizer; use crate::{Backend, Error, Features}; @@ -57,6 +59,9 @@ impl Backend for WinRT { fn speak(&self, text: &str, interrupt: bool) -> std::result::Result<(), Error> { trace!("speak({}, {})", text, interrupt); + if interrupt { + self.stop()?; + } let stream = self.synth.synthesize_text_to_stream_async(text)?.get()?; let content_type = stream.content_type()?; let source = MediaSource::create_from_stream(stream, content_type)?; @@ -67,7 +72,7 @@ impl Backend for WinRT { fn stop(&self) -> std::result::Result<(), Error> { trace!("stop()"); - self.player.close()?; + self.player.pause()?; self.playback_list.items()?.clear()?; Ok(()) }