简体   繁体   English

使用NAudio录音和播放

[英]Audio recording and playback using NAudio

When I try recording audio following this here , and using the related source code from here in the (voicerecorder .audio project), I face the problem that the recording stops within moments of starting and so does the playback. 当我尝试录制音频以下这个位置 ,并使用相关源代码从这里(voicerecorder。音频项目),我面对的是,记录开始的瞬间内停止有问题的,因此不会播放。 the recorded file is 46 bytes, and playback is there for less than a second, basically, the thread jumps to the next statement immediately. 录制的文件是46个字节,播放时间不到一秒,基本上,线程立即跳转到下一个语句。 If I try to sleep the thread, it doesn't help. 如果我试着睡觉线程,它没有帮助。 What can I do to keep it in the recording mode or playback mode until user interrupt ? 在用户中断之前,我该怎么做才能将其保持在录制模式或播放模式?

A short but complete code example may help you get good answers. 一个简短但完整的代码示例可以帮助您获得良好的答案。

In lieu of that, one thing you should make sure that your main thread (assuming this is a console app) does not terminate immediately after starting the audio recording . 取而代之的是,有一件事你应该确保你的主线程(假设这是一个控制台应用程序)不会在开始录音后立即终止 When the main app thread terminates in .NET, the entire process is terminated - background or worker threads do not keep the process alive. 当主应用程序线程在.NET中终止时,整个进程终止 - 后台或工作线程不会使进程保持活动状态。

I've answered on the NAudio forums: http://naudio.codeplex.com/Thread/View.aspx?ThreadId=207713 我在NAudio论坛上回答: http ://naudio.codeplex.com/Thread/View.aspx?ThreadId = 207713

But LBushkin is on the right lines. 但是LBushkin是正确的。 You need to keep the thread alive while the recording is taking place, and if you are using windowed callbacks, there needs to be a window. 您需要在录制过程中保持线程处于活动状态,如果使用窗口回调,则需要有一个窗口。 Use function callbacks for Console applications. 使用控制台应用程序的函数回调。

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

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