zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Apache+PHP多端口多站点
    异步将远程链接上的内容(图片或内容)写到本地--微信头像
    如何判断微信内置浏览器(JS & PHP)
    阿里大于(阿里大鱼)短信发送
    商城分类表-二级,内容较全
    ajax省市县三级联动
    html5自带表单验证-美化改造
    thinkphp使用自定义类方法
    thinkphp模板中for循环与switch的使用
    css揭秘之按钮的实现技巧
  • 原文地址:https://www.cnblogs.com/Sandheart/p/1961476.html
Copyright © 2011-2022 走看看