晚上好。我试图使用简单的延迟来执行混响效果,但是尽管使用了SpeakAsync方法,代码还是不会继续执行。
我在任何地方都找不到关于这个问题的文档,所以我非常感谢你能给我的任何建议。谢谢您抽时间见我!我在VisualStudio2017中使用的是System.Speech版本4.0.0。我的目标是运行时4.5.2
Imports System.Speech.Synthesis
Imports System.Threading
Imports System.Threading.Tasks
Module Module1
Sub main()
Dim SpeechString As String = "This is a test phrase, there are many
like it, but this one is mine."
Call OutSpeech(1, 100, SpeechString)
End Sub
Sub OutSpeech(SpeechRate As Integer, SpeechVolume As Integer, SpeechText As String)
Dim SpeechHolder As New SpeechSynthesizer
SpeechHolder.Rate = SpeechRate
SpeechHolder.Volume = SpeechVolume
SpeechHolder.SpeakAsync(SpeechText)
Thread.Sleep(100)
SpeechHolder.SpeakAsync(SpeechText)
Console.ReadLine()
End Sub终端模块
发布于 2018-01-01 11:41:02
按顺序调用SpeechHolder.SpeakAsync(SpeechText)只会使输出排队,并且语音(Es)不会重叠。
混响效应是一种快速波在短时间内合并在一起的回波效应。因此,为了产生类似混响的效果,产生两个或更多相同的声音,每个声音之间都有延迟。
Reverb()方法将调用两次OutSpeech(),设置一个adeguate延迟(100 to似乎适合获得结果)。
Sub Reverb()
Dim Delay As Integer = 100
Dim SpeechString As String = "This is a test phrase, there are many like it, but this one is mine."
OutSpeech(1, 100, Delay, SpeechString)
OutSpeech(1, 100, Delay, SpeechString)
End SubOutSpeech()方法将成为异步方法,因此在创建新的综合器时,调用将重叠。
创建了两个任务。一种是设置延迟,另一种是在合成器“说话”时等待,测试SpeechHolder.State。
Async Sub OutSpeech(SpeechRate As Integer, SpeechVolume As Integer, Delay As Integer, SpeechText As String)
Using SpeechHolder As SpeechSynthesizer = New SpeechSynthesizer
SpeechHolder.Rate = SpeechRate
SpeechHolder.Volume = SpeechVolume
Await Task.Run(Async Function() As Task(Of Boolean)
SpeechHolder.SpeakAsync(SpeechText)
Await Task.Delay(Delay)
Await Task.Run(Sub()
While SpeechHolder.State = SynthesizerState.Speaking
End While
End Sub)
Return True
End Function)
End Using
End Sub发布于 2017-12-31 14:37:23
深入到System.Speech.dll,它似乎是排队发言的操作。因此,即使演讲将异步开始,一次只播放一次。
在我意识到这就是我必须要做的事情之前,我已经进入了反编译的程序集:
private void AddSpeakParameters(VoiceSynthesis.Parameters param)
{
lock (this._pendingSpeakQueue)
{
this._pendingSpeakQueue.Enqueue(param);
if (this._pendingSpeakQueue.Count == 1)
{
this._evtPendingSpeak.Set();
}
}
}您可以使用多个SpeechSynthesizer实例同时播放声音或通过睡眠抵消。
https://stackoverflow.com/questions/48039745
复制相似问题