1
2
3
4
5
6
7 from collections import OrderedDict
8 import _espeak
9 import Queue
10 import threading
11 import languageHandler
12 from synthDriverHandler import SynthDriver,VoiceInfo,BooleanSynthSetting
13 import speech
14 from logHandler import log
17 name = "espeak"
18 description = "eSpeak"
19
20 supportedSettings=(
21 SynthDriver.VoiceSetting(),
22 SynthDriver.VariantSetting(),
23 SynthDriver.RateSetting(),
24
25
26 BooleanSynthSetting("rateBoost",_("Rate boos&t")),
27 SynthDriver.PitchSetting(),
28 SynthDriver.InflectionSetting(),
29 SynthDriver.VolumeSetting(),
30 )
31
32 @classmethod
35
47
50
51 - def speak(self,speechSequence):
52 defaultLanguage=self._language
53 textList=[]
54 langChanged=False
55 for item in speechSequence:
56 if isinstance(item,basestring):
57 s=unicode(item)
58
59
60 s.translate({ord(u'\01'):None,ord(u'<'):u'<',ord(u'>'):u'>'})
61 textList.append(s)
62 elif isinstance(item,speech.IndexCommand):
63 textList.append("<mark name=\"%d\" />"%item.index)
64 elif isinstance(item,speech.CharacterModeCommand):
65 textList.append("<say-as type=\"spell-out\">" if item.state else "</say-as>")
66 elif isinstance(item,speech.LangChangeCommand):
67 if langChanged:
68 textList.append("</voice>")
69 textList.append("<voice xml:lang=\"%s\">"%(item.lang if item.lang else defaultLanguage).replace('_','-'))
70 langChanged=True
71 elif isinstance(item,speech.SpeechCommand):
72 log.debugWarning("Unsupported speech command: %s"%item)
73 else:
74 log.error("Unknown speech: %s"%item)
75 if langChanged:
76 textList.append("</voice>")
77 text=u"".join(textList)
78 _espeak.speak(text)
79
82
85
86 _rateBoost = False
87 RATE_BOOST_MULTIPLIER = 3
88
91
93 if enable == self._rateBoost:
94 return
95 rate = self.rate
96 self._rateBoost = enable
97 self.rate = rate
98
104
110
114
118
122
126
129
132
139
141 curVoice=getattr(self,'_voice',None)
142 if curVoice: return curVoice
143 curVoice = _espeak.getCurrentVoice()
144 if not curVoice:
145 return ""
146 return curVoice.identifier.split('+')[0]
147
154
157
160
163
167
169 return OrderedDict((ID,VoiceInfo(ID, name)) for ID, name in self._variantDict.iteritems())
170