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

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

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

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 
For i = 0 To WScript.Arguments.Count - 1      

No comments:

Favorite Tweets