简体   繁体   中英

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 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 ?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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