简体   繁体   English

录制5秒后NAudio Record缓冲区已满

[英]NAudio Record buffer full after 5 seconds of recording

I'm making a program using Visual C# Studio that records from a microphone. 我正在使用Visual C#Studio制作一个从麦克风录制的程序。

I wish to record for a few minutes, but when I try to record, it shows me an error with 'Buffer Full' after it records for 5 seconds. 我希望记录几分钟,但是当我尝试记录时,它在记录5秒后显示“缓冲区已满”错误。

This is the code I'm using: 这是我正在使用的代码:

private void button2_Click(object sender, EventArgs e) //Play Button
{
  fileName = "lastReplay.wav";            

  FileStream FS_Write = File.OpenWrite("lastReplay.wav");
  FS_Write.Close();

  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);

  NAudio.Wave.WaveInProvider waveIn = new
      NAudio.Wave.WaveInProvider(sourceStream);

  sourceStream.DataAvailable += new EventHandler<NAudio.Wave.WaveInEventArgs>
      (sourceStream_DataAvailable);
  waveWriter = new NAudio.Wave.WaveFileWriter(fileName, sourceStream.WaveFormat);
  sourceStream.StartRecording();
}


private void sourceStream_DataAvailable(object sender, NAudio.Wave.WaveInEventArgs e)
{
  if (waveWriter == null) return;
  waveWriter.Write(e.Buffer, 0, e.BytesRecorded);
  waveWriter.Flush();
}

Does anyone knows what is the problem? 有谁知道这是什么问题? Thanks. 谢谢。

There's a bunch of code in there you don't need. 那里有一堆不需要的代码。 Get rid of creating the empty WAV file. 摆脱创建空的WAV文件的麻烦。 Also, there is no need for the WaveInProvider . 同样,也不需要WaveInProvider In fact, that is what is causing the buffer full exception, since nothing is reading from it. 实际上,这就是导致缓冲区已满异常的原因,因为没有读取任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM