Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions source/sayAllHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# This file may be used under the terms of the GNU General Public License, version 2 or later.
# For more details see: https://www.gnu.org/licenses/gpl-2.0.html

from typing import Optional
import weakref
import garbageHandler
import speech
Expand All @@ -17,9 +18,6 @@
from speech.commands import CallbackCommand, EndUtteranceCommand


speakWithoutPauses = speech.SpeechWithoutPauses(speakFunc=speech.speak).speakWithoutPauses


CURSOR_CARET = 0
CURSOR_REVIEW = 1

Expand All @@ -28,6 +26,18 @@
#: This is a weakref because the manager should be allowed to die once say all is complete.
_activeSayAll = lambda: None # Return None when called like a dead weakref.


def getSpeechWithoutPauses() -> "speech.SpeechWithoutPauses":
"""Returns an instance of `speech.SpeechWithoutPauses` which should be used for say all
creating it if necessary."""
if getSpeechWithoutPauses.speechWithoutPausesInstance is None:
getSpeechWithoutPauses.speechWithoutPausesInstance = speech.SpeechWithoutPauses(speakFunc=speech.speak)
return getSpeechWithoutPauses.speechWithoutPausesInstance


getSpeechWithoutPauses.speechWithoutPausesInstance: Optional["speech.SpeechWithoutPauses"] = None


def stop():
active = _activeSayAll()
if active:
Expand Down Expand Up @@ -154,7 +164,7 @@ def nextLine(self):
if isinstance(self.reader.obj, textInfos.DocumentWithPageTurns):
# Once the last line finishes reading, try turning the page.
cb = CallbackCommand(self.turnPage, name="say-all:turnPage")
speakWithoutPauses([cb, EndUtteranceCommand()])
getSpeechWithoutPauses().speakWithoutPauses([cb, EndUtteranceCommand()])
else:
self.finish()
return
Expand Down Expand Up @@ -186,7 +196,7 @@ def _onLineReached(obj=self.reader.obj, state=state):
seq = list(speech._flattenNestedSequences(speechGen))
seq.insert(0, cb)
# Speak the speech sequence.
spoke = speakWithoutPauses(seq)
spoke = getSpeechWithoutPauses().speakWithoutPauses(seq)
# Update the textInfo state ready for when speaking the next line.
self.speakTextInfoState = state.copy()

Expand All @@ -208,7 +218,7 @@ def _onLineReached(obj=self.reader.obj, state=state):
else:
# We don't want to buffer too much.
# Force speech. lineReached will resume things when speech catches up.
speakWithoutPauses(None)
getSpeechWithoutPauses().speakWithoutPauses(None)
# The first buffered line has now started speaking.
self.numBufferedLines -= 1

Expand Down Expand Up @@ -245,7 +255,7 @@ def finish(self):
# we might switch synths too early and truncate the final speech.
# We do this by putting a CallbackCommand at the start of a new utterance.
cb = CallbackCommand(self.stop, name="say-all:stop")
speakWithoutPauses([
getSpeechWithoutPauses().speakWithoutPauses([
EndUtteranceCommand(),
cb,
EndUtteranceCommand()
Expand Down
5 changes: 1 addition & 4 deletions source/speech/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def cancelSpeech():
# Import only for this function to avoid circular import.
import sayAllHandler
sayAllHandler.stop()
_speakWithoutPauses.reset()
sayAllHandler.getSpeechWithoutPauses().reset()
if beenCanceled:
return
elif speechMode==speechMode_off:
Expand Down Expand Up @@ -2534,9 +2534,6 @@ def _getSpeech(
return finalSpeechSequence


_speakWithoutPauses = SpeechWithoutPauses(speakFunc=speak)


#: The singleton _SpeechManager instance used for speech functions.
#: @type: L{manager.SpeechManager}
_manager = manager.SpeechManager()
Expand Down