diff options
Diffstat (limited to 'tools/sapi5_voice_new.vbs')
-rwxr-xr-x | tools/sapi5_voice_new.vbs | 69 |
1 files changed, 48 insertions, 21 deletions
diff --git a/tools/sapi5_voice_new.vbs b/tools/sapi5_voice_new.vbs index 96c6e2a720..f6abcf7d0b 100755 --- a/tools/sapi5_voice_new.vbs +++ b/tools/sapi5_voice_new.vbs | |||
@@ -20,11 +20,13 @@ | |||
20 | 20 | ||
21 | 'To be done: | 21 | 'To be done: |
22 | ' - Allow user to override voice, speed and/or format (currently uses Control Panel defaults for voice/speed) | 22 | ' - Allow user to override voice, speed and/or format (currently uses Control Panel defaults for voice/speed) |
23 | ' - Voice specific replacements/corrections for pronounciation (this should be at a higher level really) | 23 | |
24 | Option Explicit | ||
24 | 25 | ||
25 | Const SSFMCreateForWrite = 3 | 26 | Const SSFMCreateForWrite = 3 |
26 | 27 | ||
27 | Const SPSF_8kHz16BitMono = 6 | 28 | ' Audio formats for SAPI5 filestream object |
29 | Const SPSF_8kHz16BitMono = 6 | ||
28 | Const SPSF_11kHz16BitMono = 10 | 30 | Const SPSF_11kHz16BitMono = 10 |
29 | Const SPSF_12kHz16BitMono = 14 | 31 | Const SPSF_12kHz16BitMono = 14 |
30 | Const SPSF_16kHz16BitMono = 18 | 32 | Const SPSF_16kHz16BitMono = 18 |
@@ -34,34 +36,59 @@ Const SPSF_32kHz16BitMono = 30 | |||
34 | Const SPSF_44kHz16BitMono = 34 | 36 | Const SPSF_44kHz16BitMono = 34 |
35 | Const SPSF_48kHz16BitMono = 38 | 37 | Const SPSF_48kHz16BitMono = 38 |
36 | 38 | ||
37 | Dim oSpVoice, oSpFS, nAudioFormat, sText, sOutputFile | 39 | Dim oShell, oEnv |
40 | Dim oSpVoice, oSpFS ' SAPI5 voice and filestream | ||
41 | Dim aLine, aData ' used in command reading | ||
42 | Dim nAudioFormat | ||
43 | Dim bVerbose | ||
44 | |||
45 | |||
46 | On Error Resume Next | ||
38 | 47 | ||
39 | nAudioFormat = SPSF_22kHz16BitMono 'Audio format to use, recommended settings: | 48 | nAudioFormat = SPSF_22kHz16BitMono 'Audio format to use, recommended settings: |
40 | '- for AT&T natural voices, use SPSF_32kHz16BitMono | 49 | '- for AT&T natural voices, use SPSF_32kHz16BitMono |
41 | '- for MS voices, use SPSF_22kHz16BitMono | 50 | '- for MS voices, use SPSF_22kHz16BitMono |
42 | 51 | ||
52 | Set oShell = CreateObject("WScript.Shell") | ||
53 | Set oEnv = oShell.Environment("Process") | ||
54 | bVerbose = (oEnv("V") <> "") | ||
55 | |||
43 | Set oSpVoice = CreateObject("SAPI.SpVoice") | 56 | Set oSpVoice = CreateObject("SAPI.SpVoice") |
44 | If Err.Number <> 0 Then | 57 | If Err.Number <> 0 Then |
45 | WScript.Echo "Error - could not get SpVoice object. " & _ | 58 | WScript.StdErr.WriteLine "Error - could not get SpVoice object. " & _ |
46 | "SAPI 5 not installed?" | 59 | "SAPI 5 not installed?" |
47 | Err.Clear | 60 | Err.Clear |
48 | WScript.Quit 1 | 61 | WScript.Quit 1 |
49 | End If | 62 | End If |
50 | 63 | ||
51 | While 1 > 0 | 64 | Set oSpFS = CreateObject("SAPI.SpFileStream") |
52 | sText = WScript.StdIn.ReadLine | 65 | oSpFS.Format.Type = nAudioFormat |
53 | sOutputFile = WScript.StdIn.ReadLine | 66 | |
54 | If sOutputFile = "" Then | 67 | On Error Goto 0 |
55 | Set oSpFS = Nothing | 68 | |
56 | Set oSpVoice = Nothing | 69 | Do |
57 | Set oArgs = Nothing | 70 | aLine = Split(WScript.StdIn.ReadLine, vbTab, 2) |
58 | WScript.Quit 0 | 71 | If Err.Number <> 0 Then |
72 | WScript.StdErr.WriteLine "Error " & Err.Number & ": " & Err.Description | ||
73 | WScript.Quit 1 | ||
59 | End If | 74 | End If |
60 | ' WScript.Echo "Saying " + sText + " in " + sOutputFile | 75 | Select Case aLine(0) ' command |
61 | Set oSpFS = CreateObject("SAPI.SpFileStream") | 76 | Case "SPEAK" |
62 | oSpFS.Format.Type = nAudioFormat | 77 | aData = Split(aLine(1), vbTab, 2) |
63 | oSpFS.Open sOutputFile, SSFMCreateForWrite, False | 78 | If bVerbose Then WScript.StdErr.WriteLine "Saying " & aData(1) _ |
64 | Set oSpVoice.AudioOutputStream = oSpFS | 79 | & " in " & aData(0) |
65 | oSpVoice.Speak sText | 80 | oSpFS.Open aData(0), SSFMCreateForWrite, false |
66 | oSpFS.Close | 81 | Set oSpVoice.AudioOutputStream = oSpFS |
67 | Wend | 82 | oSpVoice.Speak aData(1) |
83 | oSpFS.Close | ||
84 | Case "EXEC" | ||
85 | If bVerbose Then WScript.StdErr.WriteLine "> " & aLine(1) | ||
86 | oShell.Run aLine(1), 0, true | ||
87 | Case "SYNC" | ||
88 | If bVerbose Then WScript.StdErr.WriteLine "Syncing" | ||
89 | WScript.StdOut.WriteLine aLine(1) ' Just echo what was passed | ||
90 | Case "QUIT" | ||
91 | If bVerbose Then WScript.StdErr.WriteLine "Quitting" | ||
92 | WScript.Quit 0 | ||
93 | End Select | ||
94 | Loop | ||