如何修复语音合成应用程序中的延迟? [英] How do I fix a delay in a speech synthesis app?

查看:115
本文介绍了如何修复语音合成应用程序中的延迟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Basic 2017中编写了一个应用程序,旨在帮助我理解语音合成。该应用程序工作正常,除了一件事,在第一次迭代期间说话部分有1-2秒的延迟,但在任何后续迭代中都没有。在声明完成一半之前,我们没有听到任何声音。我错过了什么?

代码包含在这里:

I have written an app in Visual Basic 2017 that was meant to help me understand speech synthesis. The app works OK except for one thing, there is a 1 - 2 second delay in speaking part during the first iteration but not in any subsequent iterations. We don't hear anything until the statement is half done. What am I missing?
The code is included here:

Imports System.Speech.Synthesis

Public Class Form1

    Dim synth As New SpeechSynthesizer()
    Dim prompt1 As String = ""
    Dim prompt2 As String = ""
    Dim user As String = "Darby"
    Dim currentTime As Date = TimeOfDay
    Dim Sayit1 As String = ""
    Dim Sayit2 As String = ""
    Dim greeting1 As String = ""
    Dim greeting2 As String = ""


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        greeting1 = "Hi " & user & ", "
        If currentTime >= #12:00:00 AM# And currentTime < #12:00:00 PM# Then
            greeting2 = " How is your Morning going?"
        ElseIf currentTime >= #12:00:00 PM# And currentTime < #6:00:00 PM# Then
            greeting2 = " How is your Afternoon going?  "
        ElseIf currentTime >= #6:00:00 PM# Then
            greeting2 = " How is your Evening going? "
        End If
        TalkToMe(greeting1, greeting2)
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        greeting1 = "Goodbye " & user & ", "
        If currentTime >= #12:00:00 AM# And currentTime < #12:00:00 PM# Then
            greeting2 = " you Have a Good Morning  "
        ElseIf currentTime >= #12:00:00 PM# And currentTime < #6:00:00 PM# Then
            greeting2 = " you Have a Blessed Afternoon "
        ElseIf currentTime >= #6:00:00 PM# Then
            greeting2 = " you Have a Good Evening "
        End If
        TalkToMe(greeting1, greeting2)
    End Sub


    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        Sayit1 = TextBox1.Text
        TalkToMe(Sayit1, "")
    End Sub

    Private Sub TalkToMe(prompt1, prompt2)
        synth.SelectVoice("Microsoft David Desktop")
        synth.Volume = 40
        synth.Rate = -1
        synth.Speak(prompt1 + prompt2)
        prompt1 = ""
        prompt2 = ""
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        End
    End Sub

End Class






我试过的:



我已经将初始化序列移动到各种位置,但延迟是相同的。 (即:



What I have tried:

I have moved the initialization sequence to various positions but the delay is the same. (ie:

synth.SelectVoice("Microsoft David Desktop")
   synth.Volume = 40
   synth.Rate = -1


推荐答案

加载语音引擎可能需要一些时间。



无论如何,语音应异步完成以获得最佳性能;使用说asynch或后台工作者。
It's probably taking time to load the speech engine.

In any event, "speech" should be done asynchronously for best performance; using "speak asynch" or a background worker.


这篇关于如何修复语音合成应用程序中的延迟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆