如何實際說沉默X#毫秒,而不是通過使用Thread.Sleep()。我試圖使用SpVoice變量的SpeechLib庫中的.Speak()函數根據指定的毫秒數說出特定的靜默持續時間。特別是在.wav文件的輸出中,我正在插入文本的文字行之間插入靜音。使用Thread.Sleep()會花費大量的時間來說話或保存,因爲我計劃將幾乎5000行的說出的文本保存爲.wav,並在行間暫停。如何使用SpVoice在C#中說毫秒的沉默?
這是解決我到目前爲止:
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]);
}
哪裏22050.0是採樣率和pauseLineBreak.Value是毫秒#。乘數2.0用於.wav數據中的短字符的2字節長度。
AudioOutputStream.Write只是將正確的#00寫入文件以保持靜音。
寫0的問題是什麼? – 2011-12-03 20:11:09