如何使用SpVoice在C#中说毫秒的静音?

gia*_*olo 15 c#

如何实际说出X#毫秒的静音而不是使用Thread.Sleep().我正在尝试使用SpVoice变量的SpeechLib库中的.Speak()函数,根据指定的毫秒数说出特定的静默持续时间.特别是,在.wav文件的输出中,其中我在语音文本行之间插入静默时段.使用Thread.Sleep()会花费大量的时间来说话或保存,因为我计划将近5000行语音文本保存到.wav,并在行之间暂停.

这是我到目前为止的解决方案:

        int pauseA = (int)(22050.0 * ((double)pauseTargetToSource.Value / 1000.0) * 2.0);
        int pauseB = (int)(22050.0 * ((double)pauseLineBreak.Value / 1000.0) * 2.0);
        while (
            (lineSource = srSource.ReadLine()) != null &&
            (lineTarget = srTarget.ReadLine()) != null)
        {
            voiceSource.Speak(lineSource, SpeechVoiceSpeakFlags.SVSFlagsAsync);
            voiceSource.WaitUntilDone(Timeout.Infinite);
            voiceSource.AudioOutputStream.Write(new byte[pauseA]);
            voiceTarget.Speak(lineTarget, SpeechVoiceSpeakFlags.SVSFlagsAsync);
            voiceTarget.WaitUntilDone(Timeout.Infinite);
            voiceSource.AudioOutputStream.Write(new byte[pauseB]);
        }
Run Code Online (Sandbox Code Playgroud)

其中22050.0是采样率,pauseLineBreak.Value是毫秒数.乘法器2.0用于.wav数据中的短字节的2字节长度.

AudioOutputStream.Write只是将正确的#00写入文件以保持静音.

Gre*_*zer 0

有几个选择:

  • 您可以启动另一个线程来执行该操作
  • 您可以简单地计算出每秒需要多少字节并将它们写入输出流。