3
3
# Author: David CM <dhf360@gmail.com> and others.
4
4
#synthDrivers/ibmeci.py
5
5
6
- import six , synthDriverHandler , speech , languageHandler , config , os , re
6
+ import six , synthDriverHandler , languageHandler , config , os , re
7
+ from synthDriverHandler import synthDoneSpeaking , SynthDriver , synthIndexReached , VoiceInfo
8
+
7
9
from collections import OrderedDict
8
10
from six import string_types
9
- from synthDriverHandler import SynthDriver ,VoiceInfo
10
11
from logHandler import log
12
+
11
13
from synthDrivers import _ibmeci
12
- from synthDrivers ._ibmeci import ECIVoiceParam
13
- from synthDrivers ._ibmeci import isIBM
14
+ from synthDrivers ._ibmeci import ECIVoiceParam , isIBM
15
+
16
+
17
+ # compatibility with nvda 2021.1 alpha versions.
18
+ try :
19
+ from speech .commands import BreakCommand , CharacterModeCommand , IndexCommand , LangChangeCommand , PitchCommand , RateCommand , VolumeCommand
20
+ except ImportError :
21
+ from speech import BreakCommand , CharacterModeCommand , IndexCommand , LangChangeCommand , PitchCommand , RateCommand , VolumeCommand
22
+
23
+ try :
24
+ from autoSettingsUtils .driverSetting import BooleanDriverSetting ,NumericDriverSetting
25
+ except ImportError :
26
+ from driverHandler import BooleanDriverSetting ,NumericDriverSetting
27
+
14
28
import addonHandler
15
29
addonHandler .initTranslation ()
16
30
17
- from driverHandler import BooleanDriverSetting ,NumericDriverSetting
18
- from synthDriverHandler import synthIndexReached , synthDoneSpeaking
19
31
20
32
minRate = 40
21
33
maxRate = 156
@@ -138,13 +150,13 @@ class SynthDriver(synthDriverHandler.SynthDriver):
138
150
BooleanDriverSetting ("shortpause" , _ ("&Shorten pauses" ), False ),
139
151
BooleanDriverSetting ("sendParams" , _ ("Always Send Current Speech Settings (enable to prevent some tags from sticking, disable for viavoice binary compatibility)" ), False ))
140
152
supportedCommands = {
141
- speech . IndexCommand ,
142
- speech . CharacterModeCommand ,
143
- speech . LangChangeCommand ,
144
- speech . BreakCommand ,
145
- speech . PitchCommand ,
146
- speech . RateCommand ,
147
- speech . VolumeCommand
153
+ IndexCommand ,
154
+ CharacterModeCommand ,
155
+ LangChangeCommand ,
156
+ BreakCommand ,
157
+ PitchCommand ,
158
+ RateCommand ,
159
+ VolumeCommand
148
160
}
149
161
supportedNotifications = {synthIndexReached , synthDoneSpeaking }
150
162
@@ -168,9 +180,9 @@ def __init__(self):
168
180
self .currentEncoding = "mbcs"
169
181
170
182
PROSODY_ATTRS = {
171
- speech . PitchCommand : ECIVoiceParam .eciPitchBaseline ,
172
- speech . VolumeCommand : ECIVoiceParam .eciVolume ,
173
- speech . RateCommand : ECIVoiceParam .eciSpeed ,
183
+ PitchCommand : ECIVoiceParam .eciPitchBaseline ,
184
+ VolumeCommand : ECIVoiceParam .eciVolume ,
185
+ RateCommand : ECIVoiceParam .eciSpeed ,
174
186
}
175
187
176
188
def speak (self ,speechSequence ):
@@ -183,9 +195,9 @@ def speak(self,speechSequence):
183
195
s = self .processText (item )
184
196
outlist .append ((_ibmeci .speak , (s ,)))
185
197
last = s
186
- elif isinstance (item ,speech . IndexCommand ):
198
+ elif isinstance (item ,IndexCommand ):
187
199
outlist .append ((_ibmeci .index , (item .index ,)))
188
- elif isinstance (item ,speech . LangChangeCommand ):
200
+ elif isinstance (item ,LangChangeCommand ):
189
201
l = None
190
202
if item .lang in langsAnnotations : l = langsAnnotations [item .lang ]
191
203
elif item .lang and item .lang [0 :2 ] in langsAnnotations : l = langsAnnotations [item .lang [0 :2 ]]
@@ -197,11 +209,11 @@ def speak(self,speechSequence):
197
209
else :
198
210
outlist .append ((_ibmeci .speak , (langsAnnotations [defaultLanguage ],)))
199
211
self .speakingLanguage = defaultLanguage
200
- elif isinstance (item ,speech . CharacterModeCommand ):
212
+ elif isinstance (item ,CharacterModeCommand ):
201
213
outlist .append ((_ibmeci .speak , (b"`ts1" if item .state else b"`ts0" ,)))
202
214
if item .state :
203
215
charmode = True
204
- elif isinstance (item ,speech . BreakCommand ):
216
+ elif isinstance (item ,BreakCommand ):
205
217
# taken from eloquence_threshold (https://github.com/pumper42nickel/eloquence_threshold)
206
218
# Eloquence doesn't respect delay time in milliseconds.
207
219
# Therefore we need to adjust waiting time depending on current speech rate
@@ -232,7 +244,7 @@ def speak(self,speechSequence):
232
244
outlist .append ((_ibmeci .speak , (b' `p%d ' % (pFactor ),)))
233
245
elif type (item ) in self .PROSODY_ATTRS :
234
246
val = max (0 , min (item .newValue , 100 ))
235
- if type (item ) == speech . RateCommand : val = self .percentToRate (val )
247
+ if type (item ) == RateCommand : val = self .percentToRate (val )
236
248
outlist .append ((_ibmeci .setProsodyParam , (self .PROSODY_ATTRS [type (item )], val )))
237
249
else :
238
250
log .error ("Unknown speech: %s" % item )
@@ -443,4 +455,4 @@ def _onDoneSpeaking(self): synthDoneSpeaking.notify(synth=self)
443
455
def resub (dct , s ):
444
456
for r in six .iterkeys (dct ):
445
457
s = r .sub (dct [r ], s )
446
- return s
458
+ return s
0 commit comments