55# Julien Cochuyt
66
77from enum import IntEnum
8- from typing import TYPE_CHECKING
8+ from typing import Callable , TYPE_CHECKING
99import weakref
1010import garbageHandler
11- from .speech import (
12- speak ,
13- getTextInfoSpeech ,
14- SpeakTextInfoState ,
15- speakObject ,
16- )
1711from logHandler import log
1812import config
1913import controlTypes
2620from .speechWithoutPauses import SpeechWithoutPauses
2721
2822from .types import (
23+ SpeechSequence ,
2924 _flattenNestedSequences ,
3025)
3126
3227if TYPE_CHECKING :
3328 import NVDAObjects
29+ from .speech import (
30+ getTextInfoSpeech ,
31+ SpeakTextInfoState ,
32+ speakObject ,
33+ )
3434
3535
3636class CURSOR (IntEnum ):
@@ -41,18 +41,37 @@ class CURSOR(IntEnum):
4141SayAllHandler = None
4242
4343
44- def initialize ():
44+ def initialize (
45+ speakFunc : Callable [[SpeechSequence ], None ],
46+ speakObject : 'speakObject' ,
47+ getTextInfoSpeech : 'getTextInfoSpeech' ,
48+ SpeakTextInfoState : 'SpeakTextInfoState' ,
49+ ):
4550 global SayAllHandler
46- SayAllHandler = _SayAllHandler (SpeechWithoutPauses (speakFunc = speak ))
51+ SayAllHandler = _SayAllHandler (
52+ SpeechWithoutPauses (speakFunc = speakFunc ),
53+ speakObject ,
54+ getTextInfoSpeech ,
55+ SpeakTextInfoState ,
56+ )
4757
4858
4959class _SayAllHandler :
50- def __init__ (self , speechWithoutPausesInstance : SpeechWithoutPauses ):
60+ def __init__ (
61+ self ,
62+ speechWithoutPausesInstance : SpeechWithoutPauses ,
63+ speakObject : 'speakObject' ,
64+ getTextInfoSpeech : 'getTextInfoSpeech' ,
65+ SpeakTextInfoState : 'SpeakTextInfoState' ,
66+ ):
5167 self .lastSayAllMode = None
5268 self .speechWithoutPausesInstance = speechWithoutPausesInstance
5369 #: The active say all manager.
5470 #: This is a weakref because the manager should be allowed to die once say all is complete.
5571 self ._getActiveSayAll = lambda : None # noqa: Return None when called like a dead weakref.
72+ self ._speakObject = speakObject
73+ self ._getTextInfoSpeech = getTextInfoSpeech
74+ self ._makeSpeakTextInfoState = SpeakTextInfoState
5675
5776 def stop (self ):
5877 '''
@@ -115,7 +134,11 @@ def next(self):
115134 return
116135 # Call this method again when we start speaking this object.
117136 callbackCommand = CallbackCommand (self .next , name = "say-all:next" )
118- speakObject (obj , reason = controlTypes .OutputReason .SAYALL , _prefixSpeechCommand = callbackCommand )
137+ SayAllHandler ._speakObject (
138+ obj ,
139+ reason = controlTypes .OutputReason .SAYALL ,
140+ _prefixSpeechCommand = callbackCommand
141+ )
119142
120143 def stop (self ):
121144 self .walker = None
@@ -158,7 +181,7 @@ def __init__(self, handler: _SayAllHandler, cursor: CURSOR):
158181 self .reader = api .getReviewPosition ()
159182 # #10899: SayAll profile can't be activated earlier because they may not be anything to read
160183 self .trigger .enter ()
161- self .speakTextInfoState = SpeakTextInfoState (self .reader .obj )
184+ self .speakTextInfoState = SayAllHandler . _makeSpeakTextInfoState (self .reader .obj )
162185 self .numBufferedLines = 0
163186
164187 def nextLine (self ):
@@ -207,7 +230,7 @@ def _onLineReached(obj=self.reader.obj, state=state):
207230 # and insert the lineReached callback at the very beginning of the sequence.
208231 # _linePrefix on speakTextInfo cannot be used here
209232 # As it would be inserted in the sequence after all initial control starts which is too late.
210- speechGen = getTextInfoSpeech (
233+ speechGen = SayAllHandler . _getTextInfoSpeech (
211234 self .reader ,
212235 unit = textInfos .UNIT_READINGCHUNK ,
213236 reason = controlTypes .OutputReason .SAYALL ,
0 commit comments