SAPI 5 ~ Text to WAV sample (WSF/VBS)

You can download both the WSH/VBS version and the
AutoIt from here: http://www.box.net/shared/...zip
The WSH/VBS is almost identical to AutoIt.  
I wrap the VBS first with a .WSF file:

<package>
<job id="TextToWAV">
<reference object="WScript.Shell">
<reference object="Scripting.FileSystemObject">
<object id="oSh" progid="WScript.Shell">
</object>
<object id="oFS" progid="Scripting.FileSystemObject">
</object>
<script language="VBScript">
  oSh.PopUp "TextToWAV file1[, file2] [,file3] [,...]", _
    cint(5), _
    WScript.ScriptName, _
    vbSystemModal
</script>
<script language="VBScript" src="TextToWAV.VBS">     
</script>
</reference>
</reference>
</job>
</package>

Dim     i  
Sub ConvertTextToWAV(asFN)     
  Dim     text, oSPV, oSPSTRM, WAV, oFN     
  Set oSPV = CreateObject("SAPI.SpVoice")     
  Set oSPSTRM = CreateObject("SAPI.SpFileStream")     
  oSh.Popup "asFN[" & asFN & "]",5,WScript.ScriptName ' debug     
  Set oFN=oFS.OpenTextFile(asFN,ForReading)     
  text = oFN.ReadAll     
  WAV = Replace(asFN, ".txt", ".wav")     
  If oFS.FileExists(WAV) Then oFS.DeleteFile WAV     
  oSPSTRM.Open WAV, 3, vbFalse     
  Set oSPV.AudioOutputStream = oSPSTRM     
  oSPV.Speak text     
  oSPSTRM.Close End 
Sub  
For i = 0 To WScript.Arguments.Count - 1      
  ConvertTextToWAV(Wscript.Arguments.Unnamed(i)) 
Next

No comments:

Favorite Tweets