0

我正在尝试在我的 vb 应用程序中创建文本到语音功能。

创建文本到语音的默认方法:

Dim SAPI

SAPI = CreateObject("SAPI.spvoice")

SAPI.Speak(TextBox1.Text)

这种方法不适合我正在做的事情。

假设我有 4 个音频剪辑,剪辑的名称是:

  1. ba.wav ba sound

  2. .wav a sound

  3. 卡瓦夫 ka sound

  4. ja.wav ja sound

假设我现在有 4 个字符,这些字符是:

  1. 微米to represent the ba sound

  2. öto represent the a sound

  3. ❗️to represent the ka sound

  4. ◊◊to represent the ja sound

我有RichTextBox一个RichTextBox1

可以输入µ,ö,姫,◊◊四个字符RichTextBox1

我现在有这个

Private Sub SpeakButton_Click(sender As Object, e As EventArgs) Handles SpeakButton.Click

' how do i get each character in RichTextBox1 to play when this button is clicked

End Sub

我不确定,但我相信应该将某种 wav 音频文件分配给相应的角色

我知道我可以使用这种方法播放 wav 文件

My.Computer.Audio.Play(My.Resources.WAV-NAME, AudioPlayMode.Background)

因此,如果输入的文本RichTextBox1◊◊ߧµ,则生成的语音输出应该听起来JAKABA

4

2 回答 2

0

您可以使用字典轻松完成此操作,其中键是字符,值是关联的 WAV 文件。然后你可以简单地遍历每个字符,在字典中查找它的值,然后播放它。这称为“级联语音合成”。它速度快,结果相对容易理解,但使用这种方法你永远无法接近准确的语音。多年的研究已经进入语音合成领域,它需要的不仅仅是简单地将 WAV 文件拼接在一起。

如果您需要准确的语音,您应该尝试查看可能支持您所需语言或易于扩展的其他 TTS 引擎。节日可能是一个不错的选择。

于 2013-06-17T01:09:49.670 回答
0

尝试这个 ...

Dim s as String = RichTextBox1.Text
Dim fWav as String
Dim myWav As New List(Of Byte)

For x as Integer = 0 to s.Length -1
    fwav = "" 
    Select Case s.Substring(x,1)
       case "µ" : fWav = "ba.wav"
       case "ö" : fWav = "a.wav"
       case "ߧ" : fWav = "ka.wav"
       case "◊"
         If x < s.Length - 1 Then
           If s.Substring(x + 1, 1) = "◊" Then
             fWav = "ja.wav"
             x += 1
           End if  
         End if  
    End Select
    if fWav.Length > 0 Then
      if myWav.Count = 0 Then
        myWav = IO.File.ReadAllBytes(fWav).ToList
      else
        myWav = Join(myWav, IO.File.ReadAllBytes(fwav).ToList)   
      endif
    endif

Next

Dim NewWav As New System.IO.FileStream("new.wav", System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write)

NewWav.WriteAllBytes("new.wav", myWav.ToArray)

NewWav.Close()

Dim snd As New System.Media.SoundPlayer("new.wav")
snd.Play()    

这是 Join() 函数

Private Function Join(ByVal wavBytes As List(Of Byte), ByVal wav2 As List(Of Byte)) As List(Of Byte)

    '   add on the second file excluding its header bytes
    wavBytes.AddRange(wav2.Skip(44).Take(wav2.Count - 44))


    '   rewrite the ChunkSize and Subchunk2Size fields of the Header
    Dim chunkSize As Integer = wavBytes.Count - 8
    Dim subChunk2Size As Integer = wavBytes.Count - 44

    Dim chunkSizeBytes() As Byte = BitConverter.GetBytes(chunkSize)
    Dim subChunk2SizeBytes() As Byte = BitConverter.GetBytes(subChunk2Size)
    For i = 0 To 3
        wavBytes(4 + i) = chunkSizeBytes(i)
        wavBytes(40 + i) = subChunk2SizeBytes(i)
    Next

    Return wavBytes
End Function

从http://www.vbforums.com/showthread.php?714827-RESOLVED-Concatenate-wav-files-via-byte-array得到这个

于 2013-06-17T01:20:44.253 回答