Reputation: 16416
I'm trying to write a simple script to run some txt files through the Windows 7 text-to-speech engine (which has the decent Anna voice) and produce wav files. However, the wav files don't sound as nice as when I just have it output directly to speakers. I've tried this on two completely different Windows 7 systems already. Any way to remedy this?
Script:
set x = createobject("SAPI.SpVoice") ' Uncomment following lines to output to file 'set ofs = createobject("SAPI.SpFileStream") 'ofs.Open "msg.wav", 3, vbFalse 'set x.AudioOutputStream = ofs x.Speak "In the fall of 2003, ..."
Upvotes: 3
Views: 7150
Reputation: 115
Little less 1990.
# run in powershell
$voice = New-Object -ComObject SAPI.SpVoice
$file = New-Object -ComObject SAPI.SpFileStream
$file.Open('d:\ok.wav', 3)
$voice.AudioOutputStream = $file
$voice.Speak('hi there')
$file.Close()
Upvotes: 1
Reputation: 571
SapiFileType is defined here: http://msdn.microsoft.com/en-us/library/ms720595%28v=vs.85%29.aspx
Enum 18 = 16kHz 16Bit Mono
Upvotes: 3
Reputation: 21
I have to admit, I was wondering the same thing up until a few days ago. Here is the solution, however the number '18' on the first line might be voice specific. I've been trying to get that high quality version into a wav file for a long time, so I finally ran through every number (0-64), and listened to all of the samples until I found the right one.
Paste the code below into notepad, save as 'SapiSomething.vbs', run, and hopefully it's the high quality output you're looking for. For me, the sound quality in the file output is finally the same as when speech is sent straight to the speakers.
Const SapiFileType=18 ' Magic number, possibly voice specific (0 to 64)
strText=Trim(InputBox("What do you want me to say?","Listen to Sapi.SpFileStream.Format.Type Quality",""))
If NOT len(strText)>0 Then WScript.Quit
With CreateObject("Scripting.FileSystemObject")
strFile=.BuildPath(.GetParentFolderName(WScript.ScriptFullName),"Sapi.SpFileStream.Format.Type_"&SapiFileType&".wav")
If .FileExists(strFile) Then .DeleteFile strFile
End With
With CreateObject("Sapi.SpVoice")
Set ss=CreateObject("Sapi.SpFileStream")
ss.Format.Type=SapiFileType
ss.Open strFile,3,False
Set .AudioOutputStream=ss
.Speak strText,8
.waituntildone(-1)
ss.Close
Set ss=Nothing
End With
With CreateObject("WMPlayer.OCX"):.settings.autoStart=True:.settings.volume=100:.URL=strFile:Do until .playState=1:Wscript.Sleep 200:Loop:End With
Upvotes: 2