1 #synthDrivers/nvdajp_jtalk.py
\r
2 # -*- coding: utf-8 -*-
\r
3 #A part of NonVisual Desktop Access (NVDA)
\r
4 #Copyright (C) 2006-2010 NVDA Contributors <http://www.nvda-project.org/>
\r
5 #This file is covered by the GNU General Public License.
\r
6 #See the file COPYING for more details.
\r
8 # nvdajp_jtalk (based on Open JTalk and libopenjtalk)
\r
9 # Copyright (C) 2010-2011 Takuya Nishimoto (nishimotz.com)
\r
10 # Copyright (C) 2013 Masamitsu Misono (043.jp)
\r
12 from synthDriverHandler import SynthDriver,VoiceInfo,BooleanSynthSetting
\r
13 from collections import OrderedDict
\r
14 from logHandler import log
\r
16 import synthDriverHandler
\r
17 import languageHandler
\r
18 from jtalk import _nvdajp_jtalk
\r
19 from jtalk._nvdajp_jtalk import VoiceProperty
\r
21 class SynthDriver(SynthDriver):
\r
22 """A Japanese synth driver for NVDAjp.
\r
24 name = "nvdajp_jtalk"
\r
25 description = "JTalk"
\r
27 SynthDriver.VoiceSetting(),
\r
28 SynthDriver.RateSetting(),
\r
29 BooleanSynthSetting("rateBoost",_("Rate boos&t")),
\r
30 SynthDriver.PitchSetting(),
\r
31 SynthDriver.InflectionSetting(),
\r
32 SynthDriver.VolumeSetting()
\r
40 self.voice_id = 'V2'
\r
43 self._inflection = 50
\r
44 self._rateBoost = False
\r
45 _nvdajp_jtalk.initialize()
\r
48 def speak(self,speechSequence):
\r
51 defaultLanguage = languageHandler.getLanguage()
\r
52 if defaultLanguage[:2] == 'ja': defaultLanguage = 'ja'
\r
53 lang = defaultLanguage
\r
55 for item in speechSequence:
\r
56 if isinstance(item,basestring):
\r
58 p.pitch = self._pitch
\r
59 p.inflection = self._inflection
\r
60 p.characterMode = spellState
\r
61 _nvdajp_jtalk.speak(unicode(item), currentLang, index=finalIndex, voiceProperty_=p)
\r
62 elif isinstance(item,speech.IndexCommand):
\r
63 finalIndex = item.index
\r
64 elif isinstance(item,speech.CharacterModeCommand):
\r
69 elif isinstance(item,speech.LangChangeCommand):
\r
70 lang = (item.lang if item.lang else defaultLanguage).replace('_','-')
\r
71 if lang[:2] == 'ja': lang = 'ja'
\r
73 elif isinstance(item,speech.SpeechCommand):
\r
74 log.debugWarning("Unsupported speech command: %s"%item)
\r
76 log.error("Unknown speech: %s"%item)
\r
79 _nvdajp_jtalk.stop()
\r
81 def pause(self,switch):
\r
82 _nvdajp_jtalk.pause(switch)
\r
84 def isSpeaking(self):
\r
85 return _nvdajp_jtalk.isSpeaking()
\r
87 def _get_rateBoost(self):
\r
88 return self._rateBoost
\r
90 def _set_rateBoost(self, enable):
\r
91 if enable == self._rateBoost:
\r
94 self._rateBoost = enable
\r
97 def terminate(self):
\r
98 _nvdajp_jtalk.terminate()
\r
100 # The current rate; ranges between 0 and 100
\r
101 def _get_rate(self):
\r
102 return _nvdajp_jtalk.get_rate(self._rateBoost)
\r
104 def _set_rate(self,rate):
\r
105 _nvdajp_jtalk.set_rate(int(rate), self._rateBoost)
\r
107 def _get_pitch(self):
\r
110 def _set_pitch(self,pitch):
\r
111 self._pitch = int(pitch)
\r
113 def _get_volume(self):
\r
114 return self._volume
\r
116 def _set_volume(self,volume_):
\r
117 self._volume = int(volume_)
\r
118 _nvdajp_jtalk.set_volume(self._volume)
\r
121 def _get_inflection(self):
\r
122 return self._inflection
\r
124 def _set_inflection(self,val):
\r
125 self._inflection = int(val)
\r
127 def _getAvailableVoices(self):
\r
128 log.debug("_getAvailableVoices called")
\r
129 voices = OrderedDict()
\r
130 for v in _nvdajp_jtalk._jtalk_voices:
\r
131 voices[v['id']] = VoiceInfo(v['id'], v['name'], v['lang'])
\r
134 def _get_voice(self):
\r
135 log.debug("_get_voice called")
\r
136 return self.voice_id
\r
138 def _set_voice(self, identifier):
\r
139 log.debug("_set_voice %s" % (identifier))
\r
140 rate = _nvdajp_jtalk.get_rate(self._rateBoost)
\r
141 for v in _nvdajp_jtalk._jtalk_voices:
\r
142 if v['id'] == identifier:
\r
143 if self.voice_id != identifier:
\r
144 self.voice_id = identifier
\r
145 _nvdajp_jtalk.terminate()
\r
146 _nvdajp_jtalk.initialize(v)
\r
147 _nvdajp_jtalk.set_rate(rate,self._rateBoost)
\r
148 _nvdajp_jtalk.set_volume(self._volume)
\r
152 def _get_lastIndex(self):
\r
153 if _nvdajp_jtalk.lastIndex is None:
\r
154 #log.debug("_get_lastIndex returns None")
\r
156 #log.debug("_get_lastIndex returns %d" % _nvdajp_jtalk.lastIndex)
\r
157 return _nvdajp_jtalk.lastIndex
\r