TTS 导出 wav 音频(转)
TTS 导出 wav 音频
实例一:
Sub Form_Load()
Const SSFMCreateForWrite = 3
Const SAFT22kHz16BitMono = 22
Const SVSFlagsAsync = 1
Set objVoice = CreateObject(“SAPI.SpVoice”)
objVoice.Volume = 100
objVoice.Rate = 1
Set objVoice.Voice = objVoice.GetVoices().Item(0)
Set fso = CreateObject(“Scripting.FileSystemObject”)
Set f = fso.OpenTextFile(“d:\3.txt”, 1)
Text = f.ReadAll
Set objFileStream = CreateObject(“SAPI.SpFileStream”)
objFileStream.Format.Type = SAFT22kHz16BitMono
objFileStream.Open “d:\test.wav”, SSFMCreateForWrite, False
Set objVoice.AudioOutputStream = objFileStream
objVoice.Speak Text, SVSFlagsAsync
objVoice.WaitUntilDone -1
objFileStream.Close
End Sub
中文需做如下改动
Private Sub Form_Load()
Set objVoice = CreateObject(“SAPI.SpVoice”)
Set colVoice = objVoice.GetVoices() ‘获得语音引擎集合
objVoice.Volume = 100 ‘设置音量,0到100,数字越大音量越大
objVoice.Rate = 0
‘得到所需语音引擎的编号
langCN = “MSSimplifiedChineseVoice” ‘简体中文
langEN = “MSSam” ‘如果安装了TTS Engines 5.1,还可以选择MSMike,MSMary
For i = 0 To colVoice.Count – 1
If Right(colVoice(i).Id, Len(langCN)) = langCN Then cnVoice = i
If Right(colVoice(i).Id, Len(langEN)) = langEN Then enVoice = i
Next
Const SSFMCreateForWrite = 3
Const SAFT22kHz16BitMono = 22
Const SVSFlagsAsync = 1
Set objVoice.Voice = colVoice.Item(cnVoice)
Set fso = CreateObject(“Scripting.FileSystemObject”)
Set f = fso.OpenTextFile(“d:\3.txt”, 1)
Text = f.ReadAll
Set objFileStream = CreateObject(“SAPI.SpFileStream”)
objFileStream.Format.Type = SAFT22kHz16BitMono
objFileStream.Open “d:\test.wav”, SSFMCreateForWrite, False
Set objVoice.AudioOutputStream = objFileStream
objVoice.Speak Text, SVSFlagsAsync
objVoice.WaitUntilDone -1
objFileStream.Close
实例二:
Private Sub Form_Load()
Const SSFMCreateForWrite = 3
Const SAFT22kHz16BitMono = 22
Const SVSFlagsAsync = 1
Set objVoice = CreateObject(“SAPI.SpVoice”)
objVoice.Volume = 100
objVoice.Rate = 1
Set objVoice.Voice = objVoice.GetVoices().Item(0)
Set fso = CreateObject(“Scripting.FileSystemObject”)
Set f = fso.OpenTextFile(“d:\3.txt”, 1)
Text = f.ReadAll
Set objFileStream = CreateObject(“SAPI.SpFileStream”)
objFileStream.Format.Type = SAFT22kHz16BitMono
objFileStream.Open “d:\test.wav”, SSFMCreateForWrite, False
Set objVoice.AudioOutputStream = objFileStream
objVoice.Speak Text, SVSFlagsAsync
objVoice.WaitUntilDone -1
objFileStream.Close
End Sub