1
#synthDrivers/nvdajp_jtalk.py
2
# -*- coding: utf-8 -*-
3
#A part of NonVisual Desktop Access (NVDA)
4
#Copyright (C) 2006-2010 NVDA Contributors <http://www.nvda-project.org/>
5
#This file is covered by the GNU General Public License.
6
#See the file COPYING for more details.
8
# nvdajp_jtalk (based on Open JTalk and libopenjtalk)
9
# Copyright (C) 2010-2011 Takuya Nishimoto (nishimotz.com)
12
from synthDriverHandler import SynthDriver,VoiceInfo,BooleanSynthSetting
13
import synthDriverHandler
14
from collections import OrderedDict
16
from logHandler import log
17
import _nvdajp_spellchar
19
class SynthDriver(SynthDriver):
20
"""A Japanese synth driver for NVDAjp.
25
SynthDriver.VoiceSetting(),
26
SynthDriver.RateSetting(),
27
BooleanSynthSetting("rateBoost",_("Rate boos&t")),
28
SynthDriver.PitchSetting(),
29
SynthDriver.InflectionSetting(),
30
SynthDriver.VolumeSetting()
38
_nvdajp_jtalk.initialize()
42
self._inflection = 100
43
_nvdajp_spellchar.init()
45
def speak(self,speechSequence):
49
for item in speechSequence:
50
if isinstance(item,basestring):
52
item = _nvdajp_spellchar.convert(item)
53
textList.append(unicode(item))
54
elif isinstance(item,speech.IndexCommand):
55
#if item.index != None: log.debug("speak() setting index %d" % item.index)
56
finalIndex = item.index
57
elif isinstance(item,speech.CharacterModeCommand):
59
#log.info("spellState = True")
62
#log.info("spellState = False")
64
elif isinstance(item,speech.SpeechCommand):
65
log.debugWarning("Unsupported speech command: %s"%item)
67
log.error("Unknown speech: %s"%item)
68
text=u"".join(textList)
69
#if finalIndex != None: log.debug("finalIndex %d" % finalIndex)
70
_nvdajp_jtalk.speak(text, index=finalIndex)
75
def pause(self,switch):
76
_nvdajp_jtalk.pause(switch)
80
def _get_rateBoost(self):
81
return self._rateBoost
83
def _set_rateBoost(self, enable):
84
if enable == self._rateBoost:
87
self._rateBoost = enable
91
_nvdajp_jtalk.terminate()
93
# The current rate; ranges between 0 and 100
95
return _nvdajp_jtalk.get_rate(self._rateBoost)
97
def _set_rate(self,rate):
98
_nvdajp_jtalk.set_rate(rate, self._rateBoost)
100
def _get_pitch(self):
103
def _set_pitch(self,pitch):
104
self._pitch = int(pitch)
105
_nvdajp_jtalk.set_lf0_params(self._pitch, self._inflection)
107
def _get_volume(self):
110
def _set_volume(self,volume_):
111
self._volume = int(volume_)
112
_nvdajp_jtalk.set_volume(self._volume)
115
def _get_inflection(self):
116
return self._inflection
118
def _set_inflection(self,val):
119
self._inflection = int(val)
120
_nvdajp_jtalk.set_lf0_params(self._pitch, self._inflection)
122
def _getAvailableVoices(self):
123
log.debug("_getAvailableVoices called")
124
voices = OrderedDict()
125
for v in _nvdajp_jtalk._jtalk_voices:
126
voices[v['id']] = VoiceInfo(v['id'], v['name'], 'ja_JP')
129
def _get_voice(self):
130
log.debug("_get_voice called")
131
return self.voice_id # "V1"
133
def _set_voice(self, identifier):
134
log.debug("_set_voice %s" % (identifier))
135
rate = _nvdajp_jtalk.get_rate(self._rateBoost)
136
for v in _nvdajp_jtalk._jtalk_voices:
137
if v['id'] == identifier:
138
if self.voice_id != identifier:
139
self.voice_id = identifier
140
_nvdajp_jtalk.terminate()
141
_nvdajp_jtalk.initialize(v)
142
_nvdajp_jtalk.set_rate(rate,self._rateBoost)
143
_nvdajp_jtalk.set_volume(self._volume)
144
_nvdajp_jtalk.set_lf0_params(self._pitch, self._inflection)
148
def _get_lastIndex(self):
149
if _nvdajp_jtalk.lastIndex == None:
150
#log.debug("_get_lastIndex returns None")
152
#log.debug("_get_lastIndex returns %d" % _nvdajp_jtalk.lastIndex)
153
return _nvdajp_jtalk.lastIndex