How to save SAPI text to speech to an audio file in VBScript?

笑着哭i 提交于 2019-11-29 16:06:37

You can save the SAPI output to a .WAV file as follows:

  1. Create and open a .WAV file as a stream using the SpFileStream.Open method.

  2. Assign this file stream to the SpVoice.AudioStream property.

Here's an example:

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!