注册 登录
编程论坛 VB6论坛

关于TTS输出wav时显示进度的问题(附源码)

nxhujiee 发布于 2013-04-27 08:35, 1288 次点击
我写了一个语音朗读与合成的测试程序,想实现在输出wav过程中实时显示转换进度的效果,就像图中在朗读过程中实时显示朗读进度一样。
因为在输出wav时,如果文本太长,程序就会假死,有个进度条可以提醒用户耐心等待。
试了很多方法都不行,经测试,当 voice.speak 到流文件时,不响应任何spvoice事件。哪位高人能给支一招?万分感谢。
只有本站会员才能查看附件,请 登录

附源码:
只有本站会员才能查看附件,请 登录

程序代码:

Option Explicit
Private WithEvents sVoice As SpVoice

Private Sub Command1_Click()
    Set sVoice = New SpVoice
    Set sVoice.Voice = sVoice.GetVoices.Item(Combo1.ListIndex)
    sVoice.Speak RichTextBox1.Text, SVSFlagsAsync
End Sub

Private Sub Command2_Click()
    Dim sVoice As SpVoice
    Dim objFileStream As SpFileStream
    Dim sName As String
    'Dim S As SpeechLib.ISpeechVoiceStatus
   
    Set sVoice = New SpVoice
    Set sVoice.Voice = sVoice.GetVoices.Item(Combo1.ListIndex)
    Set objFileStream = CreateObject("SAPI.SpFileStream")
    objFileStream.Format.Type = SAFT11kHz16BitMono
    sName = "c:\temp.wav"
   
    objFileStream.Open sName, SSFMCreateForWrite, False
    Set sVoice.AudioOutputStream = objFileStream
   
    sVoice.Speak RichTextBox1.Text, SVSFlagsAsync                '录制文本
    sVoice.WaitUntilDone -1
    MsgBox "OK! The filename is " & sName, vbInformation + 4096, "text4wav"
    Set sVoice = Nothing
    Set objFileStream = Nothing
End Sub

Private Sub Command3_Click()
    sVoice.Speak "", SVSFPurgeBeforeSpeak
    Set sVoice = Nothing
End Sub

Private Sub Form_Load()
    Set sVoice = New SpVoice
    Dim Token As ISpeechObjectToken
    For Each Token In sVoice.GetVoices
        Combo1.AddItem Token.GetDescription()
    Next
    Combo1.ListIndex = 0
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set sVoice = Nothing
End Sub

Private Sub sVoice_Word(ByVal StreamNumber As Long, ByVal StreamPosition As Variant, ByVal CharacterPosition As Long, ByVal Length As Long)
    On Error Resume Next
    RichTextBox1.SetFocus
    RichTextBox1.SelStart = CharacterPosition
    RichTextBox1.SelLength = Length
    ProgressBar1.Max = Len(RichTextBox1.Text)
    ProgressBar1.Value = CharacterPosition
End Sub


[ 本帖最后由 nxhujiee 于 2013-4-27 09:34 编辑 ]
6 回复
#2
nxhujiee2013-04-27 08:36
贴子中不能插入图片?
#3
zhujianlin2013-04-27 08:50
可以使用附件呢嘛!  你的这个程序我没得办法解哦   亲
#4
nxhujiee2013-04-27 09:35
回复 3楼 zhujianlin
感谢,图片有了
附件可以打开啊,我自己试了一下没问题
#5
nxhujiee2013-04-27 09:36
以下是引用zhujianlin在2013-4-27 08:50:49的发言:

可以使用附件呢嘛!  你的这个程序我没得办法解哦   亲


谢谢,图片补上了,呵呵,老革命遇上了新问题
#6
nxhujiee2013-04-28 13:45
基本搞定,思路:将朗读文本split,然后按行speak,加一个进度条,每读一行,用该行的位置修改进行条的value。
如果全文就是一大段的话,就不是很完美了。

结贴
#7
唐大才子2013-04-28 14:44
kankan
1