使用 NAudio 进行音频录制和播放
当我尝试按照此处录制音频时,并且使用此处中的相关源代码 (voicerecorder.audio 项目),我面临着录音在开始后立即停止的问题,播放也是如此。录制的文件是46字节,回放不到一秒,基本上线程就立即跳转到下一条语句。如果我尝试让线程休眠,那是没有帮助的。我该怎么做才能使其保持在录制模式或播放模式直到用户中断?
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. the recorded file is 46 bytes, and playback is there for less than a second, basically, the thread jumps to the next statement immediately. 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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在 NAudio 论坛上回答过: http://naudio.codeplex.com /Thread/View.aspx?ThreadId=207713
但 LBushkin 的观点是正确的。您需要在录制时保持线程处于活动状态,并且如果您使用窗口回调,则需要有一个窗口。对控制台应用程序使用函数回调。
I've answered on the NAudio forums: http://naudio.codeplex.com/Thread/View.aspx?ThreadId=207713
But LBushkin is on the right lines. 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.
一个简短但完整的代码示例可能会帮助您获得好的答案。
相反,您应该确保您的主线程(假设这是一个控制台应用程序)不会立即终止开始录音后。当主应用程序线程在 .NET 中终止时,整个进程都会终止 - 后台或工作线程不会使进程保持活动状态。
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.