使用 .NET Framework 捕获麦克风音频流
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/510019/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Capture a Microphone Audio Stream Using .NET Framework
提问by Josh Stodola
I need to capture the input stream from a microphone in my application, which is written in VB.NET. I need to be able to stream this data to a file or over HTTP and possibly encode it using LAME MP3. Can anybody help me get started with this?
我需要从我的应用程序中的麦克风捕获输入流,该应用程序是用 VB.NET 编写的。我需要能够将此数据流式传输到文件或通过 HTTP 并可能使用 LAME MP3 对其进行编码。有人可以帮我开始吗?
Thank you!
谢谢!
回答by Mark Heath
If you want a .NET solution, you can check out NAudiowhich is an open source audio library. Look at the WaveInStreamclass (or WaveInin the latest code). This will let you open a microphone, and receive events containing the latest captured bytes. This would be quite easy then to pass on to a stream.
如果您需要 .NET 解决方案,您可以查看NAudio,这是一个开源音频库。查看WaveInStream类(或WaveIn在最新的代码中)。这将让您打开麦克风,并接收包含最新捕获字节的事件。这将很容易传递给流。
As for encoding MP3 using LAME, one approach I have seen used is to pass the audio to lame.exe via stdin and read the mp3 from stdout. This is I think easier than getting hold of a LAME DLL and writing interop wrappers for it.
至于使用 LAME 编码 MP3,我见过的一种方法是通过 stdin 将音频传递给 lame.exe 并从 stdout 读取 mp3。我认为这比获取 LAME DLL 并为其编写互操作包装更容易。
Update:I have created an example project that uses NAudio to record from the microphone, and LAME to save as MP3 at http://voicerecorder.codeplex.com. See my article at Coding4Fun here.
更新:我创建了一个示例项目,该项目使用 NAudio 从麦克风录音,并在http://voicerecorder.codeplex.com 上使用LAME 保存为 MP3 。在这里查看我在 Coding4Fun 上的文章。
回答by dimarzionist
Maybe not the latest experience, but I remember I was playing with http://nyxtom.vox.com/library/post/recording-audio-in-c.html
也许不是最新的体验,但我记得我在玩http://nyxtom.vox.com/library/post/recording-audio-in-c.html
For more professional things you probably need to take a look at DirectSound API.
对于更专业的事情,您可能需要查看 DirectSound API。
Cheers.
干杯。

