在Linux上将麦克风录音到wav或mp3文件?
我不知道从哪里开始,我试图在Linux上记录麦克风输入,这可能吗,我的意思是我知道Linux下的一切都是文件描述符,它会像用fopen/fread读取文件一样容易吗?另外,需要root吗?
谢谢。
i didnt know where to start, im trying to record mic input on linux, is it possible, i mean i know that everything is a file descriptor under linux, will it be as easy as reading a file with fopen/fread? also, does it require root to be done?
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这当然是可能的,但它并不像从文件中读取那么简单。最简单的方法是使用库,例如 PortAudio。 PortAudio 是跨平台的并且使用起来相当简单。
PortAudio 可以让你从麦克风录音,但它不知道任何有关文件格式的信息。为此,您将需要另一个库。我从未使用过它,但 libsndfile 库 可能可以满足您的需求。
在任何情况下,您都必须从麦克风录制并将数据存储在缓冲区中,然后将该缓冲区写入文件(通过 libsndfile 或类似的东西)。
编辑:示例 PortAudio 的东西(未经测试,但你应该明白)。
It certainly is possible but it's not as simple as reading from a file. The easiest way is to use a library, such as PortAudio. PortAudio is cross-platform and fairly simple to use.
PortAudio will let you record from the mic, but it doesn't know anything about file formats. For that you're going to need another library. I've never used it, but the libsndfile library might do what you need.
In any case, you're going to have to record from the mic and store the data in a buffer, then write that buffer to a file (via libsndfile or something similar).
EDIT: example PortAudio stuff (untested, but you should get the idea).
如果您安装 PulseAudio 的开发包(在许多声音发行版中使用),这绝对是可行的,如果您将麦克风定义为 PA 接收器,您可以将数据从接收器传输到 FIFO 我还没有有很多相关经验,但 wiki 应该可以帮助
http://pulseaudio.org/wiki/DeveloperDocumentation
编辑:文档中的一些示例代码,看起来它完全按照您想要的方式使用 FD 等
If you install the Dev package for PulseAudio (used in a number of distros for sound) this should definately be doable, if you define the mic as a PA sink you can just pipe data from the sink into a FIFO I've not had a lot of experience with it but the wiki should help
http://pulseaudio.org/wiki/DeveloperDocumentation
edit: some sample code from the documentation, looks like it does exactly what you want uses FD's etc