如何使用 C#/WPF 录制音频?
我有一个应用程序,我想添加直接从某种麦克风设备导入小音频片段的功能。
我已经允许导入图片,这适用于磁盘文件和相机,因为当您附加相机时,它们会神奇地变成磁盘设备,因此文件导入方法适用于两者。
然而音频略有不同。我已经允许从磁盘导入音频文件,但我想添加直接从麦克风录制到磁盘文件或内存缓冲区的功能。
C#/WPF 是否提供了一种简单的方法来做到这一点?添加此功能的好方法是什么?
I have an application to which I want to add the ability to import small audio snippets directly from a microphone device of some sort.
I already allow importing of pictures and this works okay with disk files and cameras since cameras magically become disk devices when you attach them so a file import method works for both.
Audio however is slightly different. I've already allowed for importing audio files off the disk but I want to add the capability to directly record from a microphone to a disk file or in-memory buffer.
Does C#/WPF provide an easy way to do this? What's a good way to add this functionality?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
可能最简单的方法是使用 mciSendString 函数
:选项是使用 DirectShowNet 库(有一个 示例 称为
PlayCap
)。您可能还会发现这篇CodeProject 文章很有用。
Probably the easiest is to use mciSendString function:
Another option is to use the DirectShowNet library (there's a sample called
PlayCap
).You might also find this CodeProject article useful.
我正在使用这个库:
http://www.codeproject.com/KB/cs/Streaming_wave_audio.aspx
主要是因为api简单。但我不太喜欢这段代码。例如,它会长时间修复内存中的缓冲区,而不是分配非托管缓冲区。
I'm using the this library:
http://www.codeproject.com/KB/cs/Streaming_wave_audio.aspx
Mainly due to the simple api. But I don't like this code too much. For example it fixes it's buffers in memory for a long time instead of allocating unmanaged buffers.