Fix stopping when paused in speechd

This commit is contained in:
Kovid Goyal 2024-08-31 15:29:10 +05:30
parent 2ecab362ad
commit fa124ab696
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 20 additions and 15 deletions

View File

@ -48,8 +48,7 @@ class MainWindow(MainWindow):
self.marked_text = marked_text self.marked_text = marked_text
self.play_action = pa = QAction('Play') self.play_action = pa = QAction('Play')
pa.setShortcut(QKeySequence(Qt.Key.Key_Space)) pa.setShortcut(QKeySequence(Qt.Key.Key_Space))
pa.setCheckable(True) pa.triggered.connect(self.toggled)
pa.toggled.connect(self.toggled)
self.toolbar.addAction(pa) self.toolbar.addAction(pa)
self.stop_action = sa = QAction('Stop') self.stop_action = sa = QAction('Stop')
sa.setShortcut(QKeySequence(Qt.Key.Key_Escape)) sa.setShortcut(QKeySequence(Qt.Key.Key_Escape))
@ -79,18 +78,20 @@ class MainWindow(MainWindow):
else: else:
self.play_action.setChecked(True) self.play_action.setChecked(True)
self.stop_action.setEnabled(state in (QTextToSpeech.State.Speaking, QTextToSpeech.State.Synthesizing, QTextToSpeech.State.Paused)) self.stop_action.setEnabled(state in (QTextToSpeech.State.Speaking, QTextToSpeech.State.Synthesizing, QTextToSpeech.State.Paused))
if self.tts.state is QTextToSpeech.State.Paused:
self.play_action.setText('Resume')
elif self.tts.state is QTextToSpeech.State.Speaking:
self.play_action.setText('Pause')
else:
self.play_action.setText('Play')
def toggled(self): def toggled(self):
if self.play_action.isChecked():
self.play_action.setText('Pause')
if self.tts.state is QTextToSpeech.State.Paused: if self.tts.state is QTextToSpeech.State.Paused:
self.tts.resume() self.tts.resume()
elif self.tts.state in (QTextToSpeech.State.Ready, QTextToSpeech.State.Error): elif self.tts.state is QTextToSpeech.State.Speaking:
self.tts.speak_marked_text(self.marked_text)
else:
if self.tts.state in (QTextToSpeech.State.Speaking, QTextToSpeech.State.Synthesizing):
self.tts.pause() self.tts.pause()
self.play_action.setText('Play') else:
self.tts.speak_marked_text(self.marked_text)
def saying(self, first, last): def saying(self, first, last):
c = self.display.textCursor() c = self.display.textCursor()

View File

@ -76,6 +76,10 @@ class SpeechdTTSBackend(TTSBackend):
def stop(self) -> None: def stop(self) -> None:
self._last_mark = self._last_text = '' self._last_mark = self._last_text = ''
if self._ssip_client is not None: if self._ssip_client is not None:
if self._status['paused'] and self._status['synthesizing']:
self._status = {'synthesizing': False, 'paused': False}
self._set_state(QTextToSpeech.State.Ready)
else:
try: try:
self._ssip_client.stop() self._ssip_client.stop()
except Exception as e: except Exception as e: