神州教育培训网 打造高端培训课程,传播精品教育理念! 神州教育 神州培训 教育 企业培训 企业内训 企业管理 研修课程 简章 资本运作 房地产 国学 名师推荐

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

posted on 2011-02-22 16:55  努力&快乐  阅读(3426)  评论(0编辑  收藏  举报

导航

神州教育培训网 打造高端培训课程,传播精品教育理念! 神州教育 神州培训 教育 企业培训 企业内训 企业管理 研修课程 简章 资本运作 房地产 国学 名师推荐