From 67498869f175709ccbbcdb29b76025f3a074d133 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 1 Sep 2024 20:28:47 +0530 Subject: [PATCH] And a stop/restart control when developing --- src/calibre/gui2/tts2/piper.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/tts2/piper.py b/src/calibre/gui2/tts2/piper.py index dafc8564a0..f661ac7b2a 100644 --- a/src/calibre/gui2/tts2/piper.py +++ b/src/calibre/gui2/tts2/piper.py @@ -213,7 +213,6 @@ class Piper(TTSBackend): self._audio_sink.stateChanged.disconnect() self._audio_sink.stop() sip.delete(self._audio_sink) - # self._audio_sink.stop() self._process.readyReadStandardError.disconnect() self._process.bytesWritten.disconnect() self._process.readyReadStandardOutput.disconnect() @@ -359,8 +358,8 @@ def develop(): # {{{ p = Piper() play_started = False def state_changed(s): - debug('TTS State:', s) nonlocal play_started + debug('TTS State:', s) if s is QTextToSpeech.State.Error: debug(p.error_message(), file=sys.stderr) app.exit(1) @@ -368,9 +367,11 @@ def develop(): # {{{ play_started = True elif s is QTextToSpeech.State.Ready: if play_started: + debug('Quitting on completion') app.quit() def input_ready(): + nonlocal play_started q = sys.stdin.buffer.read() if q in (b'\x03', b'\x1b'): app.exit(1) @@ -379,6 +380,11 @@ def develop(): # {{{ p.pause() elif p.state is QTextToSpeech.State.Paused: p.resume() + elif q == b'r': + debug('Stopping') + play_started = False + p.stop() + p.say(text) text = ( 'First, relatively short sentence. '