windows 使用 SAPI.SpVoice 输出到 WAV 文件时,结果声音与直接输出到扬声器时不同

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6560513/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 17:16:50  来源:igfitidea点击:

When using SAPI.SpVoice to output to a WAV file, result sounds different than when outputting directly to speakers

windowsvbscripttext-to-speechsapi

提问by Yang

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?

我正在尝试编写一个简单的脚本来通过 Windows 7 文本到语音转换引擎(具有体面的 Anna 语音)运行一些 txt 文件并生成 wav 文件。但是,wav 文件听起来不如我直接将其输出到扬声器时那么好。我已经在两个完全不同的 Windows 7 系统上尝试过这个。有什么办法可以补救吗?

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, ..."

回答by James

SapiFileTypeis defined here: http://msdn.microsoft.com/en-us/library/ms720595%28v=vs.85%29.aspx

SapiFileType在这里定义:http: //msdn.microsoft.com/en-us/library/ms720595%28v=vs.85%29.aspx

Enum 18= 16kHz 16Bit Mono

枚举18= 16kHz 16 位单声道

回答by Brandon

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.

我不得不承认,直到几天前我还在想同样的事情。这是解决方案,但是第一行的数字“18”可能是特定于语音的。很长一段时间以来,我一直试图将那个高质量的版本转换为 wav 文件,所以我最终遍历了每个数字 (0-64),并聆听了所有样本,直到找到正确的样本为止。

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.

将下面的代码粘贴到记事本中,另存为“ SapiSomething.vbs”,运行,希望它是您正在寻找的高质量输出。对我来说,文件输出中的音质最终与语音直接发送到扬声器时相同。

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