_audiologic.py
2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#synthDrivers/_audiologic.py
#A part of NonVisual Desktop Access (NVDA)
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
#Copyright (C) 2008-2010 Gianluca Casalino <gianluca@spazioausili.net>
from ctypes import *
import os
NvdaDir=os.getcwdu()
TtsDir="c:\\TTS3\\"
Handle=c_int()
Tts=None
LastIndex=None
#Tts parameters constants
minRate=50
maxRate=200
minPitch=-12
maxPitch=+9
minVol=-40
maxVol=+12
#SynthStatus and SynthType Constants
ST_NONE=0
SYNTH_IDLE=0
SYNTH_RUNNING=1
SYNTH_PAUSED=2
#callback constants
M_BOOKMARK=8
#others constants
ttsRate=0
ttsPitch=1
ttsVol=2
ttsExpression=3
class TtsProsody(Structure):
_fields_=[
('Speed', c_int),
('Pitch', c_int),
('Vol', c_int),
('Expression', c_int),
('PhraseSpeed', c_int),
('PhrasePitch', c_int),
('PhraseGain', c_int),
('StressSpeed', c_int),
('StreesPitch', c_int),
('StreesGain', c_int),
('Declination', c_int),
('PauseFactor', c_int),
('DoubleFactor', c_int),
('RandomFactor', c_int)]
class Tts3Status(Structure):
_fields_=[
('SynthType', c_int),
('SynthStatus', c_int),
('CurrentTime', c_int),
('SynthesisTime', c_int),
('Samples', c_int),
('CurrentCharIndex', c_int),
('CurrentWordIndex', c_int),
('CurrentChar', c_char),
('CurrentWord', c_char_p)]
callbackType = WINFUNCTYPE(None, c_int, c_int, c_int, c_int)
@callbackType
def TtsCallBackProc(handle, callmode, index, sample):
global LastIndex
LastIndex=index
class TtsCallBack(Structure):
_fields_=[
('CallMode', c_int),
('BookIndex', c_int),
('CallbackProc', callbackType)]
call=TtsCallBack()
def TtsOpen():
global Handle, Tts, call
Tts=windll.LoadLibrary(TtsDir+"Tts3.dll")
Tts.Tts3Open(TtsDir, byref(Handle))
os.chdir(NvdaDir)
call.CallMode=M_BOOKMARK
call.BookIndex=-1
call.CallbackProc=TtsCallBackProc
Tts.Tts3SetCallback(Handle, byref(call))
def TtsGetStatus():
global Tts, Handle
Status=Tts3Status()
Tts.Tts3GetStatus(Handle, byref(Status))
def TtsSpeak(text):
global Handle, Tts
Tts.Tts3GenSpeech(Handle, c_char_p(text), 0)
def TtsStop():
global Handle, Tts
Tts.Tts3Stop(Handle, 1)
def TtsPause():
global Handle, Tts
Tts.Tts3Pause(Handle)
def TtsRestart():
global Handle,Tts
Tts.Tts3Restart(Handle)
def TtsSetParam(param, value, relative):
global Tts, Handle
Tts.Tts3SetProsodyValue(Handle, param, value, relative)
def TtsGetProsody(param):
global Tts, Handle
Parameters=TtsProsody()
Tts.Tts3GetProsody(Handle, byref(Parameters))
return getattr(Parameters, param)
def TtsClose():
global Tts, Handle
TtsStop()
Tts.Tts3Close(Handle)
Status=Tts3Status()
while Status.SynthType!=ST_NONE: TtsGetStatus()
Tts=None