1 '***************************************************************************
3 ' Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 ' Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 ' Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 ' Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 ' Copyright (C) 2007 Steve Bavin, Jens Arnold, Mesar Hameed
12 ' All files in this archive are subject to the GNU General Public License.
13 ' See the file COPYING in the source tree root for full license agreement.
15 ' This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 ' KIND, either express or implied.
18 '***************************************************************************
22 Const SSFMCreateForWrite
= 3
24 ' Audio formats for SAPI5 filestream object
25 Const SPSF_8kHz16BitMono
= 6
26 Const SPSF_11kHz16BitMono
= 10
27 Const SPSF_12kHz16BitMono
= 14
28 Const SPSF_16kHz16BitMono
= 18
29 Const SPSF_22kHz16BitMono
= 22
30 Const SPSF_24kHz16BitMono
= 26
31 Const SPSF_32kHz16BitMono
= 30
32 Const SPSF_44kHz16BitMono
= 34
33 Const SPSF_48kHz16BitMono
= 38
39 Dim oShell
, oArgs
, oEnv
40 Dim oFSO
, oStdIn
, oStdOut
41 Dim bVerbose
, bSAPI4
, bList
43 Dim sLanguage
, sVoice
, sSpeed
, sName
, sVendor
45 Dim oSpVoice
, oSpFS
' SAPI5 voice and filestream
46 Dim oTTS
, nMode
' SAPI4 TTS object, mode selector
47 Dim oVoice
' for traversing the list of voices
48 Dim nLangID
, sSelectString
50 Dim aLine
, aData
' used in command reading
54 Set oFSO
= CreateObject("Scripting.FileSystemObject")
55 Set oStdIn
= oFSO
.GetStandardStream(STDIN
, true)
56 Set oStdOut
= oFSO
.GetStandardStream(STDOUT
, true)
58 Set oShell
= CreateObject("WScript.Shell")
59 Set oEnv
= oShell
.Environment("Process")
60 bVerbose
= (oEnv("V") <> "")
62 Set oArgs
= WScript
.Arguments
.Named
63 bSAPI4
= oArgs
.Exists("sapi4")
64 bMSSP
= oArgs
.Exists("mssp")
65 bList
= oArgs
.Exists("listvoices")
66 sLanguage
= oArgs
.Item("language")
67 sVoice
= oArgs
.Item("voice")
68 sSpeed
= oArgs
.Item("speed")
72 ' Create SAPI4 ActiveVoice object
73 Set oTTS
= WScript
.CreateObject("ActiveVoice.ActiveVoice", "TTS_")
74 If Err
.Number
<> 0 Then
76 Set oTTS
= WScript
.CreateObject("ActiveVoice.ActiveVoice.1", "TTS_")
77 If Err
.Number
<> 0 Then
78 WScript
.StdErr
.WriteLine
"Error - could not get ActiveVoice" _
79 & " object. SAPI 4 not installed?"
86 ' Just list available voices for the selected language
87 For Each nLangID
in LangIDs(sLanguage
)
88 For nMode
= 1 To oTTS
.CountEngines
89 If oTTS
.LanguageID(nMode
) = nLangID
Then
90 WScript
.StdErr
.Write oTTS
.ModeName(nMode
) & ","
94 WScript
.StdErr
.WriteLine
98 ' Select matching voice
99 For Each nLangID
in LangIDs(sLanguage
)
100 sSelectString
= "LanguageID=" & nLangID
102 sSelectString
= sSelectString
& ";Speaker=" & sVoice _
103 & ";ModeName=" & sVoice
105 nMode
= oTTS
.Find(sSelectString
)
106 If oTTS
.LanguageID(nMode
) = nLangID
And (sVoice
= "" Or _
107 oTTS
.Speaker(nMode
) = sVoice
Or oTTS
.ModeName(nMode
) = sVoice
) Then
108 sName
= oTTS
.ModeName(nMode
)
110 WScript
.StdErr
.WriteLine
"Using " & sName
& " for " & sSelectString
117 If sSelectString
= "" Then
118 WScript
.StdErr
.WriteLine
"Error - found no matching voice for " _
119 & sLanguage
& ", " & sVoice
125 If sSpeed
<> "" Then oTTS
.Speed
= sSpeed
127 ' Get vendor information
128 sVendor
= oTTS
.MfgName(nMode
)
131 ' Create SAPI5 object
133 Set oSpVoice
= CreateObject("speech.SpVoice")
135 Set oSpVoice
= CreateObject("SAPI.SpVoice")
137 If Err
.Number
<> 0 Then
138 WScript
.StdErr
.WriteLine
"Error " & Err
.Number _
139 & " - could not get SpVoice object." _
140 & " SAPI 5 not installed?"
145 ' Just list available voices for the selected language
146 For Each nLangID
in LangIDs(sLanguage
)
147 sSelectString
= "Language=" & Hex(nLangID
)
148 For Each oVoice
in oSpVoice
.GetVoices(sSelectString
)
149 WScript
.StdErr
.Write oVoice
.GetAttribute("Name") & ";"
152 WScript
.StdErr
.WriteLine
156 ' Select matching voice
157 For Each nLangID
in LangIDs(sLanguage
)
158 sSelectString
= "Language=" & Hex(nLangID
)
160 sSelectString
= sSelectString
& ";Name=" & sVoice
162 Set oSpVoice
.Voice
= oSpVoice
.GetVoices(sSelectString
).Item(0)
163 If Err
.Number
= 0 Then
164 sName
= oSpVoice
.Voice
.GetAttribute("Name")
166 WScript
.StdErr
.WriteLine
"Using " & sName
& " for " & sSelectString
174 If sSelectString
= "" Then
175 WScript
.StdErr
.WriteLine
"Error - found no matching voice for " _
176 & sLanguage
& ", " & sVoice
181 If sSpeed
<> "" Then oSpVoice
.Rate
= sSpeed
183 ' Get vendor information, protect from missing attribute
184 sVendor
= oSpVoice
.Voice
.GetAttribute("Vendor")
185 If Err
.Number
<> 0 Then
187 sVendor
= "(unknown)"
188 ' Some L&H engines don't set the vendor attribute - check the name
189 If Len(sName
) > 3 And Left(sName
, 3) = "LH " Then
194 ' Filestream object for output
195 Set oSpFS
= CreateObject("SAPI.SpFileStream")
196 oSpFS
.Format
.Type = AudioFormat(sVendor
)
200 aLine
= Split(oStdIn
.ReadLine
, vbTab
, 2)
201 If Err
.Number
<> 0 Then
202 WScript
.StdErr
.WriteLine
"Error " & Err
.Number
& ": " & Err
.Description
205 Select Case aLine(0) ' command
209 oStdOut
.WriteLine sVendor
212 aData
= Split(aLine(1), vbTab
, 2)
213 If bVerbose
Then WScript
.StdErr
.WriteLine
"Saying " & aData(1) _
216 oTTS
.FileName
= aData(0)
223 oSpFS
.Open
aData(0), SSFMCreateForWrite
, false
224 Set oSpVoice
.AudioOutputStream
= oSpFS
225 oSpVoice
.Speak
aData(1)
229 If bVerbose
Then WScript
.StdErr
.WriteLine
"> " & aLine(1)
230 oShell
.Run
aLine(1), 0, true
231 If Err
.Number
<> 0 Then
233 WScript
.StdErr
.Write
"> " & aLine(1) & ": "
235 If Err
.Number
= &H80070002
Then ' Actually file not found
236 WScript
.StdErr
.WriteLine
"command not found"
238 WScript
.StdErr
.WriteLine
"error " & Err
.Number
& ":" _
244 If bVerbose
Then WScript
.StdErr
.WriteLine
"Syncing"
245 oStdOut
.WriteLine
aLine(1) ' Just echo what was passed
247 If bVerbose
Then WScript
.StdErr
.WriteLine
"Quitting"
255 ' SAPI5 output format selection based on engine
256 Function AudioFormat(ByRef sVendor
)
259 AudioFormat
= SPSF_22kHz16BitMono
261 AudioFormat
= SPSF_32kHz16BitMono
263 AudioFormat
= SPSF_16kHz16BitMono
265 AudioFormat
= SPSF_22kHz16BitMono
267 AudioFormat
= SPSF_16kHz16BitMono
269 AudioFormat
= SPSF_22kHz16BitMono
270 WScript
.StdErr
.WriteLine
"Warning - unknown vendor """ & sVendor _
271 & """ - using default wave format"
275 ' Language mapping rockbox->windows
276 Function LangIDs(ByRef sLanguage
)
279 Select Case sLanguage
281 LangIDs
= Array(&h436
)
283 LangIDs
= Array( &h401
, &h801
, &hc01
, &h1001
, &h1401
, &h1801
, _
284 &h1c01
, &h2001
, &h2401
, &h2801
, &h2c01
, &h3001
, _
285 &h3401
, &h3801
, &h3c01
, &h4001
)
286 ' Saudi Arabia, Iraq, Egypt, Libya, Algeria, Morocco, Tunisia,
287 ' Oman, Yemen, Syria, Jordan, Lebanon, Kuwait, U.A.E., Bahrain,
290 LangIDs
= Array(&h42d
)
292 LangIDs
= Array(&h402
)
294 LangIDs
= Array(&h403
)
296 LangIDs
= Array(&h804
) ' PRC
298 LangIDs
= Array(&h404
) ' Taiwan. Perhaps also Hong Kong, Singapore, Macau?
300 LangIDs
= Array(&h405
)
302 LangIDs
= Array(&h406
)
304 LangIDs
= Array(&h407
, &hc07
, &h1007
, &h1407
)
305 ' Standard, Austrian, Luxembourg, Liechtenstein (Swiss -> wallisertitsch)
307 LangIDs
= Array(&h425
)
309 LangIDs
= Array( &h409
, &h809
, &hc09
, &h1009
, &h1409
, &h1809
, _
310 &h1c09
, &h2009
, &h2409
, &h2809
, &h2c09
, &h3009
, _
312 ' American, British, Australian, Canadian, New Zealand, Ireland,
313 ' South Africa, Jamaika, Caribbean, Belize, Trinidad, Zimbabwe,
316 LangIDs
= Array( &h809
, &h409
, &hc09
, &h1009
, &h1409
, &h1809
, _
317 &h1c09
, &h2009
, &h2409
, &h2809
, &h2c09
, &h3009
, _
319 ' British, American, Australian, Canadian, New Zealand, Ireland,
320 ' South Africa, Jamaika, Caribbean, Belize, Trinidad, Zimbabwe,
323 LangIDs
= Array( &h40a
, &hc0a
, &h80a
, &h100a
, &h140a
, &h180a
, _
324 &h1c0a
, &h200a
, &h240a
, &h280a
, &h2c0a
, &h300a
, _
325 &h340a
, &h380a
, &h3c0a
, &h400a
, &h440a
, &h480a
, _
327 ' trad. sort., mordern sort., Mexican, Guatemala, Costa Rica,
328 ' Panama, Dominican Republic, Venezuela, Colombia, Peru, Argentina,
329 ' Ecuador, Chile, Uruguay, Paraguay, Bolivia, El Salvador,
330 ' Honduras, Nicaragua, Puerto Rico
332 WScript
.StdErr
.WriteLine
"Error: no esperanto support in Windows"
335 LangIDs
= Array(&h40b
)
337 LangIDs
= Array(&h40c
, &hc0c
, &h100c
, &h140c
, &h180c
)
338 ' Standard, Canadian, Swiss, Luxembourg, Monaco (Belgian -> walon)
340 LangIDs
= Array(&h456
)
342 LangIDs
= Array(&h408
)
344 LangIDs
= Array(&h40d
)
346 LangIDs
= Array(&h439
)
348 LangIDs
= Array(&h41a
, &h101a
) ' Croatia, Bosnia and Herzegovina
350 LangIDs
= Array(&h40f
)
352 LangIDs
= Array(&h410
, &h810
) ' Standard, Swiss
354 LangIDs
= Array(&h411
)
356 LangIDs
= Array(&h412
)
358 LangIDs
= Array(&h426
)
360 LangIDs
= Array(&h427
)
362 LangIDs
= Array(&h40e
)
364 LangIDs
= Array(&h413
, &h813
) ' Standard, Belgian
366 LangIDs
= Array(&h814
)
368 LangIDs
= Array(&h414
) ' Bokmal
370 LangIDs
= Array(&h415
)
371 Case "portugues-brasileiro"
372 LangIDs
= Array(&h416
)
374 LangIDs
= Array(&h816
)
376 LangIDs
= Array(&h418
)
378 LangIDs
= Array(&h419
)
380 LangIDs
= Array(&h41B
)
382 LangIDs
= Array(&h424
)
384 LangIDs
= Array(&hc1a
) ' Cyrillic
386 LangIDs
= Array(&h41d
, &h81d
) ' Standard, Finland
388 LangIDs
= Array(&h464
) ' Filipino, might not be 100% correct
390 LangIDs
= Array(&h41e
)
392 LangIDs
= Array(&h41f
)
394 LangIDs
= Array(&h422
)
395 Case "wallisertitsch"
396 LangIDs
= Array(&h807
) ' Swiss German
398 LangIDs
= Array(&h80c
) ' Belgian French