NAudio记录从未收到样本 [英] NAudio record never receiving a sample

查看:160
本文介绍了NAudio记录从未收到样本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用最简单的NAudio示例从输入设备进行录制,但是由于某种原因,我无法调用DataAvailable回调函数.

I'm attempting the simplest possible NAudio example to record from an input device but for some reason I can't get the DataAvailable callback function to be called.

在下面的示例中,做某事永远不会被击中"的断点.

In the example below a break point on Do Something never gets hit.

WaveIn waveIn = new WaveIn();
waveIn.DeviceNumber = 0;
waveIn.DataAvailable += waveIn_DataAvailable;
waveIn.RecordingStopped += new EventHandler(waveIn_RecordingStopped);
waveIn.WaveFormat = new WaveFormat(44100, 1);
waveIn.StartRecording();

private void waveIn_DataAvailable(object sender, WaveInEventArgs e)
{
   Do Something
}

我已经检查,重新检查并重新检查了这些设置是否与NAudio VoiceRecorder测试应用程序所使用的设置完全相同,该应用程序可以使用完全相同的设置录制精美的音频.

I've checked, re-checked and re-re-checked that the settings are exactly the same as those used by the NAudio VoiceRecorder test application which is able to record audio fine with the exact same settings.

唯一的区别是我的测试应用程序是控制台应用程序,而不是WPF应用程序.会有所作为吗?

The only difference is my test application is a console application rather than a WPF app. Would that make a difference?

推荐答案

是的,这是因为它是一个控制台应用程序,WaveIn类使用Windows消息作为回调.如果您能够下载并构建来自codeplex的最新源代码,则可以使用全新的WaveInEvent类(2012年3月6日添加),它不依赖于Windows消息循环.

Yes, it is because it is a console app, and the WaveIn class uses Windows messages as callbacks. If you are able to download and build the very latest source code from codeplex, you can use the brand new WaveInEvent class (added 6 Mar 2012), which does not rely on a Windows message loop.

或者,如果您熟悉使用NuGet安装预发行版程序包,则可以安装最新的 NAudio预发行版本(当前为 1.5.4-beta ).

Alternatively, if you are familiar with installing pre-release packages using NuGet, you can install the latest NAudio prerelease (currently 1.5.4-beta) which has this class in.

这篇关于NAudio记录从未收到样本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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