使用 C# 从线路输入连续采样的最简单方法是什么
我想使用 C# 从 PC 的音频线路中连续采样(然后处理该数据)。 进行采样的最佳方法是什么?
I want to continuously sample from my PC's audio line in using C# (then process that data). What is the best way to do the sampling?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用开源 NAudio .NET 音频库进行一些(基本)音频捕获。 查看 NAudioDemo 项目,了解使用 WaveIn 函数录制到 WAV 文件的简单示例。 NAudio 现在还包括使用 WASAPI(Windows Vista 及更高版本)和 ASIO(如果您的声卡有 ASIO 驱动程序)捕获音频的功能。
You can do some (basic) audio capture using the open source NAudio .NET Audio Library. Have a look at the NAudioDemo project to see a simple example of recording to a WAV file using the WaveIn functions. NAudio also now includes the ability to capture audio using WASAPI (Windows Vista and above) and ASIO (if your soundcard has an ASIO driver).
还有 Alvas Audio 库,不是免费的,如果您有一个烦人的屏幕不用付钱,但效果很好。 而且文档很好,如果您发现错误或其他问题,支持也很好。
There is the Alvas Audio library as well, not free, has a nagging screen if you don't pay, but works beautifully. And the documentation is nice and, if you find a bug or something, the support is fine too.
.NET 框架中没有用于处理声音的内置库,但如果您使用的是 Win32,则可以使用 DirectSound 等非托管库来执行此操作。
Ianier Munoz 显示 如何在 CodeProject 上通过 P/Invoke 使用 waveIn 用 C# 编写全双工音频播放器。 他提到 托管 DirectSound一般方法。
There are no built-in libraries in the .NET framework for dealing with sound, but if you're on Win32, you can use an unmanaged library like DirectSound to do it.
Ianier Munoz shows how to write a full-duplex audio player in C# using waveIn via P/Invoke on CodeProject. He mentions Managed DirectSound as a more general method.
Managed DirectX 支持直接捕获音频并且非常易于使用,但不再受支持并于去年从 DirectX SDK 中删除。 仍然可以获取它 通过安装 2007 年 8 月之前的 SDK 版本。
虽然不能严格满足您的要求,但更可靠的方法是围绕本机 C++ DirectSound API 创建 C++/CLI 包装程序集,同样来自 DirectX SDK。 然后可以直接从 C# 代码调用它。 尽管需要一些 C++ 和 COM 知识,但这绝对是一种更强大且可维护的方法。
我过去曾使用过这两种技术,而且效果都很好。
Managed DirectX supports direct capture of audio and is very easy to use, but is no longer supported and was removed from the DirectX SDK last year. It's still possible to get it by installing an SDK version from before August 2007.
While not strictly meeting your requirements, a more robust approach would be to create a C++/CLI wrapper assembly around the native C++ DirectSound API, again from the DirectX SDK. This could then be called directly from C# code. This is definitely a more powerful and maintainable approach, despite requiring some knowledge of C++ and COM.
I have used both of these techniques in the past and they both work well.