我有以下用于文本到语音转换的VBScript代码:
Set objVoice = CreateObject("SAPI.SpVoice")
objVoice.Speak Inputbox("Enter Text")
我想将语音保存到音频文件中。我怎么能这样做?
答案 0 :(得分:4)
您可以将SAPI输出保存为.WAV文件,如下所示:
使用SpFileStream.Open
方法创建并打开.WAV文件作为流。
将此文件流分配给SpVoice.AudioStream
属性。
以下是一个例子:
Const SAFT48kHz16BitStereo = 39
Const SSFMCreateForWrite = 3 ' Creates file even if file exists and so destroys or overwrites the existing file
Dim oFileStream, oVoice
Set oFileStream = CreateObject("SAPI.SpFileStream")
oFileStream.Format.Type = SAFT48kHz16BitStereo
oFileStream.Open "C:\Work\Sample.wav", SSFMCreateForWrite
Set oVoice = CreateObject("SAPI.SpVoice")
Set oVoice.AudioOutputStream = oFileStream
oVoice.Speak "Hello world"
oFileStream.Close