~mshinke/nvdajp/betterBraille

« back to all changes in this revision

Viewing changes to source/synthDrivers/nvdajp_jtalk.py

  • Committer: Masataka Shinke
  • Date: 2011-10-25 12:35:26 UTC
  • mfrom: (4175.1.10 jpmain)
  • mto: (4175.1.36 jpmain)
  • mto: This revision was merged to the branch mainline in revision 4193.
  • Revision ID: mshinke@users.sourceforge.jp-20111025123526-ze527a2rl3z0g2ky
lp:~nishimotz/nvdajp/main : 4185 をマージ

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
7
#
 
8
# nvdajp_jtalk (based on Open JTalk and libopenjtalk)
 
9
# Copyright (C) 2010-2011 Takuya Nishimoto (nishimotz.com)
 
10
 
 
11
import _nvdajp_jtalk
 
12
from synthDriverHandler import SynthDriver,VoiceInfo,BooleanSynthSetting
 
13
import synthDriverHandler
 
14
from collections import OrderedDict
 
15
import speech
 
16
from logHandler import log
 
17
import _nvdajp_spellchar
 
18
 
 
19
class SynthDriver(SynthDriver):
 
20
        """A Japanese synth driver for NVDAjp.
 
21
        """
 
22
        name = "nvdajp_jtalk"
 
23
        description = "JTalk"
 
24
        supportedSettings=(
 
25
                SynthDriver.VoiceSetting(),
 
26
                SynthDriver.RateSetting(),
 
27
                BooleanSynthSetting("rateBoost",_("Rate boos&t")),
 
28
                SynthDriver.PitchSetting(),
 
29
                SynthDriver.InflectionSetting(),
 
30
                SynthDriver.VolumeSetting()
 
31
        )
 
32
 
 
33
        @classmethod
 
34
        def check(cls):
 
35
                return True
 
36
 
 
37
        def __init__(self):
 
38
                _nvdajp_jtalk.initialize()
 
39
                self.voice_id = 'V1'
 
40
                self._volume = 100
 
41
                self._pitch = 50
 
42
                self._inflection = 100
 
43
                _nvdajp_spellchar.init()
 
44
 
 
45
        def speak(self,speechSequence):
 
46
                textList=[]
 
47
                finalIndex = None
 
48
                spellState = False
 
49
                for item in speechSequence:
 
50
                        if isinstance(item,basestring):
 
51
                                if spellState:
 
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):
 
58
                                if item.state: 
 
59
                                        #log.info("spellState = True")
 
60
                                        spellState = True 
 
61
                                else: 
 
62
                                        #log.info("spellState = False")
 
63
                                        spellState = False
 
64
                        elif isinstance(item,speech.SpeechCommand):
 
65
                                log.debugWarning("Unsupported speech command: %s"%item)
 
66
                        else:
 
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)
 
71
 
 
72
        def cancel(self):
 
73
                _nvdajp_jtalk.stop()
 
74
 
 
75
        def pause(self,switch):
 
76
                _nvdajp_jtalk.pause(switch)
 
77
 
 
78
        _rateBoost = False
 
79
 
 
80
        def _get_rateBoost(self):
 
81
                return self._rateBoost
 
82
 
 
83
        def _set_rateBoost(self, enable):
 
84
                if enable == self._rateBoost:
 
85
                        return
 
86
                rate = self.rate
 
87
                self._rateBoost = enable
 
88
                self.rate = rate
 
89
 
 
90
        def terminate(self):
 
91
                _nvdajp_jtalk.terminate()
 
92
 
 
93
        # The current rate; ranges between 0 and 100
 
94
        def _get_rate(self):
 
95
                return _nvdajp_jtalk.get_rate(self._rateBoost)
 
96
 
 
97
        def _set_rate(self,rate):
 
98
                _nvdajp_jtalk.set_rate(rate, self._rateBoost)
 
99
 
 
100
        def _get_pitch(self):
 
101
                return self._pitch
 
102
 
 
103
        def _set_pitch(self,pitch):
 
104
                self._pitch = int(pitch)
 
105
                _nvdajp_jtalk.set_lf0_params(self._pitch, self._inflection)
 
106
 
 
107
        def _get_volume(self):
 
108
                return self._volume
 
109
 
 
110
        def _set_volume(self,volume_):
 
111
                self._volume = int(volume_)
 
112
                _nvdajp_jtalk.set_volume(self._volume)
 
113
                return
 
114
 
 
115
        def _get_inflection(self):
 
116
                return self._inflection
 
117
 
 
118
        def _set_inflection(self,val):
 
119
                self._inflection = int(val)
 
120
                _nvdajp_jtalk.set_lf0_params(self._pitch, self._inflection)
 
121
 
 
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')
 
127
                return voices
 
128
 
 
129
        def _get_voice(self):
 
130
                log.debug("_get_voice called")
 
131
                return self.voice_id # "V1"
 
132
 
 
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)
 
145
                                        return
 
146
                return
 
147
 
 
148
        def _get_lastIndex(self):
 
149
                if _nvdajp_jtalk.lastIndex == None:
 
150
                        #log.debug("_get_lastIndex returns None")
 
151
                        return None
 
152
                #log.debug("_get_lastIndex returns %d" % _nvdajp_jtalk.lastIndex)
 
153
                return _nvdajp_jtalk.lastIndex
 
154