如何在 VBScript 中将 SAPI 文本保存为语音文件? [英] How to save SAPI text to speech to an audio file in VBScript?
本文介绍了如何在 VBScript 中将 SAPI 文本保存为语音文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下用于文本到语音转换的 VBScript 代码:
I have the following VBScript code for text to speech conversion:
Set objVoice = CreateObject("SAPI.SpVoice")
objVoice.Speak Inputbox("Enter Text")
我想将语音保存到音频文件中.我该怎么做?
I want to save the speech to an audio file. How can I do this?
推荐答案
您可以将 SAPI 输出保存为 .WAV 文件,如下所示:
You can save the SAPI output to a .WAV file as follows:
使用
SpFileStream.Open
方法.
将此文件流分配给 SpVoice.AudioStream
属性.
Assign this file stream to the SpVoice.AudioStream
property.
这是一个例子:
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
这篇关于如何在 VBScript 中将 SAPI 文本保存为语音文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文