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
42 Dim sLanguage
, sVoice
, sSpeed
, sName
, sVendor
44 Dim oSpVoice
, oSpFS
' SAPI5 voice and filestream
45 Dim oTTS
, nMode
' SAPI4 TTS object, mode selector
46 Dim oVoice
' for traversing the list of voices
47 Dim nLangID
, sSelectString
49 Dim aLine
, aData
' used in command reading
53 Set oFSO
= CreateObject("Scripting.FileSystemObject")
54 Set oStdIn
= oFSO
.GetStandardStream(STDIN
, true)
55 Set oStdOut
= oFSO
.GetStandardStream(STDOUT
, true)
57 Set oShell
= CreateObject("WScript.Shell")
58 Set oEnv
= oShell
.Environment("Process")
59 bVerbose
= (oEnv("V") <> "")
61 Set oArgs
= WScript
.Arguments
.Named
62 bSAPI4
= oArgs
.Exists("sapi4")
63 bList
= oArgs
.Exists("listvoices")
64 sLanguage
= oArgs
.Item("language")
65 sVoice
= oArgs
.Item("voice")
66 sSpeed
= oArgs
.Item("speed")
70 ' Create SAPI4 ActiveVoice object
71 Set oTTS
= WScript
.CreateObject("ActiveVoice.ActiveVoice", "TTS_")
72 If Err
.Number
<> 0 Then
74 Set oTTS
= WScript
.CreateObject("ActiveVoice.ActiveVoice.1", "TTS_")
75 If Err
.Number
<> 0 Then
76 WScript
.StdErr
.WriteLine
"Error - could not get ActiveVoice" _
77 & " object. SAPI 4 not installed?"
84 ' Just list available voices for the selected language
85 For Each nLangID
in LangIDs(sLanguage
)
86 For nMode
= 1 To oTTS
.CountEngines
87 If oTTS
.LanguageID(nMode
) = nLangID
Then
88 WScript
.StdErr
.Write oTTS
.ModeName(nMode
) & ","
92 WScript
.StdErr
.WriteLine
96 ' Select matching voice
97 For Each nLangID
in LangIDs(sLanguage
)
98 sSelectString
= "LanguageID=" & nLangID
100 sSelectString
= sSelectString
& ";Speaker=" & sVoice _
101 & ";ModeName=" & sVoice
103 nMode
= oTTS
.Find(sSelectString
)
104 If oTTS
.LanguageID(nMode
) = nLangID
And (sVoice
= "" Or _
105 oTTS
.Speaker(nMode
) = sVoice
Or oTTS
.ModeName(nMode
) = sVoice
) Then
106 sName
= oTTS
.ModeName(nMode
)
108 WScript
.StdErr
.WriteLine
"Using " & sName
& " for " & sSelectString
115 If sSelectString
= "" Then
116 WScript
.StdErr
.WriteLine
"Error - found no matching voice for " _
117 & sLanguage
& ", " & sVoice
123 If sSpeed
<> "" Then oTTS
.Speed
= sSpeed
125 ' Get vendor information
126 sVendor
= oTTS
.MfgName(nMode
)
129 ' Create SAPI5 object
130 Set oSpVoice
= CreateObject("SAPI.SpVoice")
131 If Err
.Number
<> 0 Then
132 WScript
.StdErr
.WriteLine
"Error - could not get SpVoice object." _
133 & " SAPI 5 not installed?"
138 ' Just list available voices for the selected language
139 For Each nLangID
in LangIDs(sLanguage
)
140 sSelectString
= "Language=" & Hex(nLangID
)
141 For Each oVoice
in oSpVoice
.GetVoices(sSelectString
)
142 WScript
.StdErr
.Write oVoice
.GetAttribute("Name") & ","
145 WScript
.StdErr
.WriteLine
149 ' Select matching voice
150 For Each nLangID
in LangIDs(sLanguage
)
151 sSelectString
= "Language=" & Hex(nLangID
)
153 sSelectString
= sSelectString
& ";Name=" & sVoice
155 Set oSpVoice
.Voice
= oSpVoice
.GetVoices(sSelectString
).Item(0)
156 If Err
.Number
= 0 Then
157 sName
= oSpVoice
.Voice
.GetAttribute("Name")
159 WScript
.StdErr
.WriteLine
"Using " & sName
& " for " & sSelectString
167 If sSelectString
= "" Then
168 WScript
.StdErr
.WriteLine
"Error - found no matching voice for " _
169 & sLanguage
& ", " & sVoice
174 If sSpeed
<> "" Then oSpVoice
.Rate
= sSpeed
176 ' Get vendor information, protect from missing attribute
177 sVendor
= oSpVoice
.Voice
.GetAttribute("Vendor")
178 If Err
.Number
<> 0 Then
180 sVendor
= "(unknown)"
181 ' Some L&H engines don't set the vendor attribute - check the name
182 If Len(sName
) > 3 And Left(sName
, 3) = "LH " Then
187 ' Filestream object for output
188 Set oSpFS
= CreateObject("SAPI.SpFileStream")
189 oSpFS
.Format
.Type = AudioFormat(sVendor
)
193 aLine
= Split(oStdIn
.ReadLine
, vbTab
, 2)
194 If Err
.Number
<> 0 Then
195 WScript
.StdErr
.WriteLine
"Error " & Err
.Number
& ": " & Err
.Description
198 Select Case aLine(0) ' command
202 oStdOut
.WriteLine sVendor
205 aData
= Split(aLine(1), vbTab
, 2)
206 If bVerbose
Then WScript
.StdErr
.WriteLine
"Saying " & aData(1) _
209 oTTS
.FileName
= aData(0)
216 oSpFS
.Open
aData(0), SSFMCreateForWrite
, false
217 Set oSpVoice
.AudioOutputStream
= oSpFS
218 oSpVoice
.Speak
aData(1)
222 If bVerbose
Then WScript
.StdErr
.WriteLine
"> " & aLine(1)
223 oShell
.Run
aLine(1), 0, true
224 If Err
.Number
<> 0 Then
226 WScript
.StdErr
.Write
"> " & aLine(1) & ": "
228 If Err
.Number
= &H80070002
Then ' Actually file not found
229 WScript
.StdErr
.WriteLine
"command not found"
231 WScript
.StdErr
.WriteLine
"error " & Err
.Number
& ":" _
237 If bVerbose
Then WScript
.StdErr
.WriteLine
"Syncing"
238 oStdOut
.WriteLine
aLine(1) ' Just echo what was passed
240 If bVerbose
Then WScript
.StdErr
.WriteLine
"Quitting"
248 ' SAPI5 output format selection based on engine
249 Function AudioFormat(ByRef sVendor
)
252 AudioFormat
= SPSF_22kHz16BitMono
254 AudioFormat
= SPSF_32kHz16BitMono
256 AudioFormat
= SPSF_16kHz16BitMono
258 AudioFormat
= SPSF_22kHz16BitMono
260 AudioFormat
= SPSF_16kHz16BitMono
262 AudioFormat
= SPSF_22kHz16BitMono
263 WScript
.StdErr
.WriteLine
"Warning - unknown vendor """ & sVendor _
264 & """ - using default wave format"
268 ' Language mapping rockbox->windows
269 Function LangIDs(ByRef sLanguage
)
272 Select Case sLanguage
274 LangIDs
= Array(&h436
)
276 LangIDs
= Array( &h401
, &h801
, &hc01
, &h1001
, &h1401
, &h1801
, _
277 &h1c01
, &h2001
, &h2401
, &h2801
, &h2c01
, &h3001
, _
278 &h3401
, &h3801
, &h3c01
, &h4001
)
279 ' Saudi Arabia, Iraq, Egypt, Libya, Algeria, Morocco, Tunisia,
280 ' Oman, Yemen, Syria, Jordan, Lebanon, Kuwait, U.A.E., Bahrain,
283 LangIDs
= Array(&h42d
)
285 LangIDs
= Array(&h402
)
287 LangIDs
= Array(&h403
)
289 LangIDs
= Array(&h804
) ' PRC
291 LangIDs
= Array(&h404
) ' Taiwan. Perhaps also Hong Kong, Singapore, Macau?
293 LangIDs
= Array(&h405
)
295 LangIDs
= Array(&h406
)
297 LangIDs
= Array(&h407
, &hc07
, &h1007
, &h1407
)
298 ' Standard, Austrian, Luxembourg, Liechtenstein (Swiss -> wallisertitsch)
300 LangIDs
= Array(&h425
)
302 LangIDs
= Array( &h409
, &h809
, &hc09
, &h1009
, &h1409
, &h1809
, _
303 &h1c09
, &h2009
, &h2409
, &h2809
, &h2c09
, &h3009
, _
305 ' American, British, Australian, Canadian, New Zealand, Ireland,
306 ' South Africa, Jamaika, Caribbean, Belize, Trinidad, Zimbabwe,
309 LangIDs
= Array( &h809
, &h409
, &hc09
, &h1009
, &h1409
, &h1809
, _
310 &h1c09
, &h2009
, &h2409
, &h2809
, &h2c09
, &h3009
, _
312 ' British, American, Australian, Canadian, New Zealand, Ireland,
313 ' South Africa, Jamaika, Caribbean, Belize, Trinidad, Zimbabwe,
316 LangIDs
= Array( &h40a
, &hc0a
, &h80a
, &h100a
, &h140a
, &h180a
, _
317 &h1c0a
, &h200a
, &h240a
, &h280a
, &h2c0a
, &h300a
, _
318 &h340a
, &h380a
, &h3c0a
, &h400a
, &h440a
, &h480a
, _
320 ' trad. sort., mordern sort., Mexican, Guatemala, Costa Rica,
321 ' Panama, Dominican Republic, Venezuela, Colombia, Peru, Argentina,
322 ' Ecuador, Chile, Uruguay, Paraguay, Bolivia, El Salvador,
323 ' Honduras, Nicaragua, Puerto Rico
325 WScript
.StdErr
.WriteLine
"Error: no esperanto support in Windows"
328 LangIDs
= Array(&h40b
)
330 LangIDs
= Array(&h40c
, &hc0c
, &h100c
, &h140c
, &h180c
)
331 ' Standard, Canadian, Swiss, Luxembourg, Monaco (Belgian -> walon)
333 LangIDs
= Array(&h456
)
335 LangIDs
= Array(&h408
)
337 LangIDs
= Array(&h40d
)
339 LangIDs
= Array(&h439
)
341 LangIDs
= Array(&h41a
, &h101a
) ' Croatia, Bosnia and Herzegovina
343 LangIDs
= Array(&h40f
)
345 LangIDs
= Array(&h410
, &h810
) ' Standard, Swiss
347 LangIDs
= Array(&h411
)
349 LangIDs
= Array(&h412
)
351 LangIDs
= Array(&h426
)
353 LangIDs
= Array(&h427
)
355 LangIDs
= Array(&h40e
)
357 LangIDs
= Array(&h413
, &h813
) ' Standard, Belgian
359 LangIDs
= Array(&h814
)
361 LangIDs
= Array(&h414
) ' Bokmal
363 LangIDs
= Array(&h415
)
364 Case "portugues-brasileiro"
365 LangIDs
= Array(&h416
)
367 LangIDs
= Array(&h816
)
369 LangIDs
= Array(&h418
)
371 LangIDs
= Array(&h419
)
373 LangIDs
= Array(&h41B
)
375 LangIDs
= Array(&h424
)
377 LangIDs
= Array(&hc1a
) ' Cyrillic
379 LangIDs
= Array(&h41d
, &h81d
) ' Standard, Finland
381 LangIDs
= Array(&h464
) ' Filipino, might not be 100% correct
383 LangIDs
= Array(&h41e
)
385 LangIDs
= Array(&h41f
)
387 LangIDs
= Array(&h422
)
388 Case "wallisertitsch"
389 LangIDs
= Array(&h807
) ' Swiss German
391 LangIDs
= Array(&h80c
) ' Belgian French