用于NAudio录音的音频电平计 [英] Audio level meter for NAudio recording

查看:239
本文介绍了用于NAudio录音的音频电平计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NAudio库将音频录制到WAV文件中.我希望能够在示例数据到达时将ProgressBar更新为音频电平/音量的值.

I´m recording audio to a WAV file using NAudio library. I want to be able to update a ProgressBar to the value of audio level/volume as the sample data arrives.

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

推荐答案

对于Windows窗体示例,请查看NAudioDemo源代码,尤其是

For a Windows Forms example, have a look at the NAudioDemo source code and in particular the AudioPlaybackPanel class, which uses a MeteringSampleProvider and subscribes to its StreamVolume event to set the properties on a custom volume meter control (included in NAudio)

对于WPF示例,请查看 voicerecorder.codeplex.com ,它使用了类似的技术,音量计量为本文中所述.

For a WPF example, look at voicerecorder.codeplex.com which uses a similar technique and the volume metering is described in this article.

这篇关于用于NAudio录音的音频电平计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆