Package synthDrivers :: Module _audiologic
[hide private]
[frames] | no frames]

Source Code for Module synthDrivers._audiologic

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