1
- # https://github.com/Mahmood-Taghavi
1
+ # -*- coding: UTF-8 -*-
2
+ #A part of Dual Voice for NVDA
3
+ #Copyright (C) 2015-2020 Seyed Mahmood Taghavi Shahri
4
+ #https://mahmood-taghavi.github.io/dual_voice/
5
+ #This file is covered by the GNU General Public License version 3.
6
+ #See the file COPYING for more details.
2
7
3
- #from collections import defaultdict
4
8
import wx
5
9
import gui
6
- # import addonHandler
7
- # addonHandler.initTranslation()
10
+ import addonHandler
11
+ addonHandler .initTranslation ()
8
12
import config
9
13
10
14
#import languageHandler
15
19
16
20
class DualVoiceLanguageSettingsDialog (gui .SettingsDialog ):
17
21
title = _ ('The "Dual Voice" settings' )
18
- _tempSecondVoice = ''
19
- _tempSecondRate = 50
20
- _tempSecondPitch = 50
21
- _tempSecondVolume = 100
22
- _tempSecondIsLatin = False
23
- _tempNonLatinPriority = False
24
- _tempConsiderContext = False
25
22
def __init__ (self , parent ):
26
23
super (DualVoiceLanguageSettingsDialog , self ).__init__ (parent )
27
- global _tempSecondVoice
28
- global _tempSecondRate
29
- global _tempSecondPitch
30
- global _tempSecondVolume
31
- global _tempSecondIsLatin
32
- global _tempNonLatinPriority
33
- global _tempConsiderContext
34
24
#_realtime.typingArea = "Alaki"
35
- if ("dual_sapi5" in speech .getSynth ().name ):
36
- #config.conf["dual_voice"]["tempSecondVoice"] = config.conf["dual_voice"]["sapi5SecondVoice"]
37
- _tempSecondVoice = config .conf ["dual_voice" ]["sapi5SecondVoice" ]
38
- _tempSecondRate = config .conf ["dual_voice" ]["sapi5SecondRate" ]
39
- _tempSecondPitch = config .conf ["dual_voice" ]["sapi5SecondPitch" ]
40
- _tempSecondVolume = config .conf ["dual_voice" ]["sapi5SecondVolume" ]
41
- _tempSecondIsLatin = config .conf ["dual_voice" ]["sapi5SecondIsLatin" ]
42
- _tempNonLatinPriority = config .conf ["dual_voice" ]["sapi5NonLatinPriority" ]
43
- _tempConsiderContext = config .conf ["dual_voice" ]["sapi5ConsiderContext" ]
44
25
45
26
def makeSettings (self , sizer ):
46
27
synthInfo = _ ('Your current speech synthesizer is the %. Please select the Dual Voice as the speech synthesizer in the NVDA speech settings.' )
@@ -51,14 +32,10 @@ def makeSettings(self, sizer):
51
32
else :
52
33
## find the primary voice and show it in a label
53
34
try :
54
- primaryVoiceID = config .conf ["speech" ]["dual_sapi5" ]["voice" ]
55
- index = _realtime .list_VoiceID .index (primaryVoiceID )
35
+ index = _realtime .list_VoiceID .index (_realtime .primaryVoiceID )
56
36
voiceName = _realtime .list_VoiceName [index ]
57
37
except :
58
- config .conf ["speech" ]["dual_sapi5" ]["voice" ] = _realtime .list_VoiceID [0 ]
59
- primaryVoiceID = config .conf ["speech" ]["dual_sapi5" ]["voice" ]
60
- index = _realtime .list_VoiceID .index (primaryVoiceID )
61
- voiceName = _realtime .list_VoiceName [index ]
38
+ voiceName = 'a voice without the required name attribute'
62
39
voiceInfo = _ ('You have selected % as the primary voice.' )
63
40
voiceInfo = voiceInfo .replace ('%' , voiceName )
64
41
infoLabel = wx .StaticText (self , label = voiceInfo )
@@ -70,15 +47,15 @@ def makeSettings(self, sizer):
70
47
sizer .Add (sVoicesLabel )
71
48
self ._sVoicesChoice = wx .Choice (self , choices = _realtime .list_VoiceName )
72
49
if ("dual_sapi5" in speech .getSynth ().name ):
73
- check = config . conf [ "dual_voice" ][ " sapi5SecondVoice" ] in _realtime .list_VoiceAttribName
50
+ check = _realtime . sapi5SecondVoice in _realtime .list_VoiceAttribName
74
51
if check :
75
- index = _realtime .list_VoiceAttribName .index (config . conf [ "dual_voice" ][ " sapi5SecondVoice" ] )
52
+ index = _realtime .list_VoiceAttribName .index (_realtime . sapi5SecondVoice )
76
53
self ._sVoicesChoice .SetSelection (index )
77
54
else :
78
55
#self._sVoicesChoice.SetSelection(0)
79
- check = config . conf [ "speech" ][ "dual_sapi5" ][ "voice" ] in _realtime .list_VoiceID
56
+ check = _realtime . primaryVoiceID in _realtime .list_VoiceID
80
57
if check :
81
- index = _realtime .list_VoiceID .index (config . conf [ "speech" ][ "dual_sapi5" ][ "voice" ] )
58
+ index = _realtime .list_VoiceID .index (_realtime . primaryVoiceID )
82
59
self ._sVoicesChoice .SetSelection (index )
83
60
else :
84
61
self ._sVoicesChoice .SetSelection (0 )
@@ -87,7 +64,7 @@ def makeSettings(self, sizer):
87
64
##
88
65
self ._secondIsLatinCheckBox = wx .CheckBox (self , label = _ ("&Use the secondary voice for reading Latin text instead of non-Latin." ))
89
66
if ("dual_sapi5" in speech .getSynth ().name ):
90
- self ._secondIsLatinCheckBox .SetValue (config . conf [ "dual_voice" ][ " sapi5SecondIsLatin" ] )
67
+ self ._secondIsLatinCheckBox .SetValue (_realtime . sapi5SecondIsLatin )
91
68
self ._secondIsLatinCheckBox .Bind (wx .EVT_CHECKBOX , self .onSIsLatinCheck )
92
69
sizer .Add (self ._secondIsLatinCheckBox )
93
70
##
@@ -96,33 +73,33 @@ def makeSettings(self, sizer):
96
73
self ._sRateSlider = wx .Slider (self , value = 50 , minValue = 0 , maxValue = 100 , style = wx .SL_HORIZONTAL )
97
74
self ._sRateSlider .Bind (wx .EVT_SLIDER , self .OnSRateSliderScroll )
98
75
if ("dual_sapi5" in speech .getSynth ().name ):
99
- self ._sRateSlider .SetValue (config . conf [ "dual_voice" ][ " sapi5SecondRate" ] )
76
+ self ._sRateSlider .SetValue (_realtime . sapi5SecondRate )
100
77
sizer .Add (self ._sRateSlider )
101
78
##
102
79
sPitchLabel = wx .StaticText (self , label = _ ("&Pitch:" ))
103
80
sizer .Add (sPitchLabel )
104
81
self ._sPitchSlider = wx .Slider (self , value = 50 , minValue = 0 , maxValue = 100 , style = wx .SL_HORIZONTAL )
105
82
self ._sPitchSlider .Bind (wx .EVT_SLIDER , self .OnSPitchSliderScroll )
106
83
if ("dual_sapi5" in speech .getSynth ().name ):
107
- self ._sPitchSlider .SetValue (config . conf [ "dual_voice" ][ " sapi5SecondPitch" ] )
84
+ self ._sPitchSlider .SetValue (_realtime . sapi5SecondPitch )
108
85
sizer .Add (self ._sPitchSlider )
109
86
##
110
87
sVolumeLabel = wx .StaticText (self , label = _ ("V&olume:" ))
111
88
sizer .Add (sVolumeLabel )
112
89
self ._sVolumeSlider = wx .Slider (self , value = 100 , minValue = 0 , maxValue = 100 , style = wx .SL_HORIZONTAL )
113
90
self ._sVolumeSlider .Bind (wx .EVT_SLIDER , self .OnSVolumeSliderScroll )
114
91
if ("dual_sapi5" in speech .getSynth ().name ):
115
- self ._sVolumeSlider .SetValue (config . conf [ "dual_voice" ][ " sapi5SecondVolume" ] )
92
+ self ._sVolumeSlider .SetValue (_realtime . sapi5SecondVolume )
116
93
sizer .Add (self ._sVolumeSlider )
117
94
##
118
95
self ._nonLatinPriorityCheckBox = wx .CheckBox (self , label = _ ("&Prioritize non-Latin text over Latin text." ))
119
96
if ("dual_sapi5" in speech .getSynth ().name ):
120
- self ._nonLatinPriorityCheckBox .SetValue (config . conf [ "dual_voice" ][ " sapi5NonLatinPriority" ] )
97
+ self ._nonLatinPriorityCheckBox .SetValue (_realtime . sapi5NonLatinPriority )
121
98
self ._nonLatinPriorityCheckBox .Bind (wx .EVT_CHECKBOX , self .nonLatinPriorityCheck )
122
99
sizer .Add (self ._nonLatinPriorityCheckBox )
123
- self ._considerContextCheckBox = wx .CheckBox (self , label = _ ("Read &numbers and punctuations based on context." ))
100
+ self ._considerContextCheckBox = wx .CheckBox (self , label = _ ("Read &numbers and punctuations based on their context." ))
124
101
if ("dual_sapi5" in speech .getSynth ().name ):
125
- self ._considerContextCheckBox .SetValue (config . conf [ "dual_voice" ][ " sapi5ConsiderContext" ] )
102
+ self ._considerContextCheckBox .SetValue (_realtime . sapi5ConsiderContext )
126
103
self ._considerContextCheckBox .Bind (wx .EVT_CHECKBOX , self .considerContextCheck )
127
104
sizer .Add (self ._considerContextCheckBox )
128
105
##
@@ -154,45 +131,54 @@ def onOk(self, event):
154
131
# Update Configurations
155
132
if ("dual_sapi5" in speech .getSynth ().name ):
156
133
_realtime .typingArea = self ._typingAreaTextCtrl .GetValue ()
134
+ config .conf ["dual_voice" ]["sapi5SecondVoice" ] = _realtime .sapi5SecondVoice
135
+ config .conf ["dual_voice" ]["sapi5SecondRate" ] = _realtime .sapi5SecondRate
136
+ config .conf ["dual_voice" ]["sapi5SecondPitch" ] = _realtime .sapi5SecondPitch
137
+ config .conf ["dual_voice" ]["sapi5SecondVolume" ] = _realtime .sapi5SecondVolume
138
+ config .conf ["dual_voice" ]["sapi5SecondIsLatin" ] = _realtime .sapi5SecondIsLatin
139
+ config .conf ["dual_voice" ]["sapi5NonLatinPriority" ] = _realtime .sapi5NonLatinPriority
140
+ config .conf ["dual_voice" ]["sapi5ConsiderContext" ] = _realtime .sapi5ConsiderContext
141
+
157
142
return super (DualVoiceLanguageSettingsDialog , self ).onOk (event )
158
143
159
144
def onCancel (self , event ):
160
145
# Restore Configurations
161
146
if ("dual_sapi5" in speech .getSynth ().name ):
162
- config .conf ["dual_voice" ]["sapi5SecondVoice" ] = _tempSecondVoice
163
- config .conf ["dual_voice" ]["sapi5SecondRate" ] = _tempSecondRate
164
- config .conf ["dual_voice" ]["sapi5SecondPitch" ] = _tempSecondPitch
165
- config .conf ["dual_voice" ]["sapi5SecondVolume" ] = _tempSecondVolume
166
- config .conf ["dual_voice" ]["sapi5SecondIsLatin" ] = _tempSecondIsLatin
167
- config .conf ["dual_voice" ]["sapi5NonLatinPriority" ] = _tempNonLatinPriority
168
- config .conf ["dual_voice" ]["sapi5ConsiderContext" ] = _tempConsiderContext
147
+ _realtime . sapi5SecondVoice = config .conf ["dual_voice" ]["sapi5SecondVoice" ]
148
+ _realtime . sapi5SecondRate = config .conf ["dual_voice" ]["sapi5SecondRate" ]
149
+ _realtime . sapi5SecondPitch = config .conf ["dual_voice" ]["sapi5SecondPitch" ]
150
+ _realtime . sapi5SecondVolume = config .conf ["dual_voice" ]["sapi5SecondVolume" ]
151
+ _realtime . sapi5SecondIsLatin = config .conf ["dual_voice" ]["sapi5SecondIsLatin" ]
152
+ _realtime . sapi5NonLatinPriority = config .conf ["dual_voice" ]["sapi5NonLatinPriority" ]
153
+ _realtime . sapi5ConsiderContext = config .conf ["dual_voice" ]["sapi5ConsiderContext" ]
169
154
return super (DualVoiceLanguageSettingsDialog , self ).onCancel (event )
170
155
171
156
172
157
def onSVoiceChange (self , event ):
173
158
if ("dual_sapi5" in speech .getSynth ().name ):
174
- config .conf ["dual_voice" ]["sapi5SecondVoice" ] = _realtime .list_VoiceAttribName [self ._sVoicesChoice .GetSelection ()]
159
+ _realtime .sapi5SecondVoice = _realtime .list_VoiceAttribName [self ._sVoicesChoice .GetSelection ()]
160
+ _realtime .problemisticSapi5SecondVoice = ''
175
161
176
162
def OnSRateSliderScroll (self , event ):
177
163
if ("dual_sapi5" in speech .getSynth ().name ):
178
- config . conf [ "dual_voice" ][ " sapi5SecondRate" ] = self ._sRateSlider .GetValue ()
164
+ _realtime . sapi5SecondRate = self ._sRateSlider .GetValue ()
179
165
180
166
def OnSPitchSliderScroll (self , event ):
181
167
if ("dual_sapi5" in speech .getSynth ().name ):
182
- config . conf [ "dual_voice" ][ " sapi5SecondPitch" ] = self ._sPitchSlider .GetValue ()
168
+ _realtime . sapi5SecondPitch = self ._sPitchSlider .GetValue ()
183
169
184
170
def OnSVolumeSliderScroll (self , event ):
185
171
if ("dual_sapi5" in speech .getSynth ().name ):
186
- config . conf [ "dual_voice" ][ " sapi5SecondVolume" ] = self ._sVolumeSlider .GetValue ()
172
+ _realtime . sapi5SecondVolume = self ._sVolumeSlider .GetValue ()
187
173
188
174
def onSIsLatinCheck (self , event ):
189
175
if ("dual_sapi5" in speech .getSynth ().name ):
190
- config . conf [ "dual_voice" ][ " sapi5SecondIsLatin" ] = self ._secondIsLatinCheckBox .GetValue ()
176
+ _realtime . sapi5SecondIsLatin = self ._secondIsLatinCheckBox .GetValue ()
191
177
192
178
def nonLatinPriorityCheck (self , event ):
193
179
if ("dual_sapi5" in speech .getSynth ().name ):
194
- config . conf [ "dual_voice" ][ " sapi5NonLatinPriority" ] = self ._nonLatinPriorityCheckBox .GetValue ()
180
+ _realtime . sapi5NonLatinPriority = self ._nonLatinPriorityCheckBox .GetValue ()
195
181
196
182
def considerContextCheck (self , event ):
197
183
if ("dual_sapi5" in speech .getSynth ().name ):
198
- config . conf [ "dual_voice" ][ " sapi5ConsiderContext" ] = self ._considerContextCheckBox .GetValue ()
184
+ _realtime . sapi5ConsiderContext = self ._considerContextCheckBox .GetValue ()
0 commit comments