我正在使用 NAudio 库将音频录制到 WAV 文件中。我希望能够在示例数据到达时将 ProgressBar 更新为音频电平/音量的值。
public WaveIn Recorder_NAudio;
public WaveFileWriter Writer_NAudio;
public void record()
{
Recorder_NAudio = new WaveIn();
Recorder_NAudio.WaveFormat = new NAudio.Wave.WaveFormat(sampleRate, 1);
Writer_NAudio = new WaveFileWriter(File.Open(tempPath, FileMode.Create), Recorder_NAudio.WaveFormat);
Recorder_NAudio.DataAvailable += new EventHandler<WaveInEventArgs>(Recorder2_DataAvailable);
Recorder_NAudio.StartRecording();
}
void Recorder2_DataAvailable(object sender, WaveInEventArgs e)
{
if (Writer_NAudio != null) if (Writer_NAudio.CanWrite)
{
Writer_NAudio.WriteData(e.Buffer, 0, e.BytesRecorded);
// I need help to create this function
ProgressBar1.value = GetVolumeFromBytes(e.buffer);
}
}