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 infomration
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(&h402
)
278 LangIDs
= Array(&h403
)
280 LangIDs
= Array(&h804
) ' PRC
282 LangIDs
= Array(&h404
) ' Taiwan. Perhaps also Hong Kong, Singapore, Macau?
284 LangIDs
= Array(&h405
)
286 LangIDs
= Array(&h406
)
288 LangIDs
= Array(&h407
, &hc07
, &h1007
, &h1407
)
289 ' Standard, Austrian, Luxembourg, Liechtenstein (Swiss -> wallisertitsch)
291 LangIDs
= Array(&h425
)
293 LangIDs
= Array( &h809
, &h409
, &hc09
, &h1009
, &h1409
, &h1809
, _
294 &h1c09
, &h2009
, &h2409
, &h2809
, &h2c09
, &h3009
, _
296 ' British, American, Australian, Canadian, New Zealand, Ireland,
297 ' South Africa, Jamaika, Caribbean, Belize, Trinidad, Zimbabwe,
300 LangIDs
= Array( &h40a
, &hc0a
, &h80a
, &h100a
, &h140a
, &h180a
, _
301 &h1c0a
, &h200a
, &h240a
, &h280a
, &h2c0a
, &h300a
, _
302 &h340a
, &h380a
, &h3c0a
, &h400a
, &h440a
, &h480a
, _
304 ' trad. sort., mordern sort., Mexican, Guatemala, Costa Rica,
305 ' Panama, Dominican Republic, Venezuela, Colombia, Peru, Argentina,
306 ' Ecuador, Chile, Uruguay, Paraguay, Bolivia, El Salvador,
307 ' Honduras, Nicaragua, Puerto Rico
309 WScript
.StdErr
.WriteLine
"Error: no esperanto support in Windows"
312 LangIDs
= Array(&h40b
)
314 LangIDs
= Array(&h40c
, &h80c
, &hc0c
, &h100c
, &h140c
, &h180c
)
315 ' Standard, Belgian, Canadian, Swiss, Luxembourg, Monaco
317 LangIDs
= Array(&h456
)
319 LangIDs
= Array(&h408
)
321 LangIDs
= Array(&h40d
)
323 LangIDs
= Array(&h439
)
325 LangIDs
= Array(&h40f
)
327 LangIDs
= Array(&h410
, &h810
) ' Standard, Swiss
329 LangIDs
= Array(&h411
)
331 LangIDs
= Array(&h412
)
333 LangIDs
= Array(&h40e
)
335 LangIDs
= Array(&h413
, &h813
) ' Standard, Belgian
337 LangIDs
= Array(&h414
) ' Bokmal
339 LangIDs
= Array(&h814
)
341 LangIDs
= Array(&h415
)
343 LangIDs
= Array(&h816
)
344 Case "portugues-brasileiro"
345 LangIDs
= Array(&h416
)
347 LangIDs
= Array(&h418
)
349 LangIDs
= Array(&h419
)
351 LangIDs
= Array(&h424
)
353 LangIDs
= Array(&hc1a
) ' Cyrillic
355 LangIDs
= Array(&h41d
, &h81d
) ' Standard, Finland
357 LangIDs
= Array(&h464
) ' Filipino, might not be 100% correct
359 LangIDs
= Array(&h41e
)
361 LangIDs
= Array(&h41f
)
362 Case "wallisertitsch"
363 LangIDs
= Array(&h807
) ' Swiss German