我正在使用Naudio Library開發錄音程序。 現在記錄我必須按下記錄按鈕,然後按保存按鈕。 我想讓節目始終錄製並自動保存錄制的音頻。 感謝您的幫助。 這是一些代碼。 開始錄製:沒有音頻時停止錄音
NAudio.Wave.WaveIn sourceStream = null;
NAudio.Wave.WaveFileWriter waveWriter = null;
private void SRecording_Click(object sender, EventArgs e)
{
if (sourceList.SelectedItems.Count == 0) return;
SaveFileDialog save = new SaveFileDialog();
save.Filter = "Wave File (*.wav)|*.wav;";
string wavoutputpath = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
wavoutputpath += "\\Speech.wav";
save.FileName = wavoutputpath;
int deviceNumber = sourceList.SelectedItems[0].Index;
sourceStream = new NAudio.Wave.WaveIn();
sourceStream.DeviceNumber = deviceNumber;
sourceStream.WaveFormat = new NAudio.Wave.WaveFormat(44100, NAudio.Wave.WaveIn.GetCapabilities(deviceNumber).Channels);
sourceStream.DataAvailable += new EventHandler<NAudio.Wave.WaveInEventArgs>(sourceStream_DataAvailable);
waveWriter = new NAudio.Wave.WaveFileWriter(save.FileName, sourceStream.WaveFormat);
sourceStream.StartRecording();
}
private void sourceStream_DataAvailable(object sender, NAudio.Wave.WaveInEventArgs e)
{
if (waveWriter == null) return;
waveWriter.WriteData(e.Buffer, 0, e.BytesRecorded);
waveWriter.Flush();
}
停止錄音:
if (sourceStream != null)
{
sourceStream.StopRecording();
sourceStream.Dispose();
sourceStream = null;
}
if (waveWriter != null)
{
waveWriter.Dispose();
waveWriter = null;
}
你想要做什麼。一直錄音,或者在沒有音頻時停止錄音? –
歡迎來到StackOverflow!正如這個問題所表達的那樣,很難幫助你。請張貼您迄今爲止的代碼,並且解決方案將更容易創建。 – paqogomez
更新了我的帖子。 – user2992413