模拟麦克风(虚拟麦克风) [英] Simulate Microphone (virtual mic)

查看:639
本文介绍了模拟麦克风(虚拟麦克风)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了需要模拟"麦克风输出的问题.

I've got a problem where I need to "simulate" microphone output.

数据将通过网络传输,解码为 PCM,基本上需要写入麦克风 - 然后其他程序可以读取/记录/任何内容.

Data will be coming over the network, decoded into PCM and basically needs to be written into the mic - which then other programs can read/record/whatever.

我一直在阅读有关 alsa 的信息,但信息很少.文件插件似乎很有希望 - 我正在考虑将命名管道作为infile",然后我可以将数据从我的应用程序传送到它.但是,我无法让它工作(vlc/audacity 只是段错误).

I've been reading up on alsa but information is pretty sparse. The file plugin seemes promising - I was thinking of having a named pipe as "infile" which I could then deliver data to from my application. I can't get it to work however (vlc/audacity just segfault).

pcm.testing {
  type file
  slave {
    pcm {
      type hw
      card 0
      device 0
    }
  }
  infile "/dev/urandom"
  format "raw"
}

有没有更好的方法来做到这一点?对 alsa 插件(尤其是文件插件)有什么建议吗?

Are there any better ways of doing this? Any suggestions on alsa plug-ins (particularly the file plugin)?

推荐答案

你的声音会通过网络传来,什么东西会缓存它直到有人想要读取它?还是会丢弃数据?一般来说,像下面这样的东西(只是几乎没有测试过)应该作为一个虚拟麦克风工作,但我认为它总是在设备打开时从头开始读取文件,你需要检查它是如何处理文件结尾的.也许您会尝试使用管道,但随后缓存/丢弃传入数据需要由从网络读取的应用程序处理.

Your sound will come over the network and what would cache it until something wants to read? Or would data be discarded? In general something like the below (only barely tested) should work as a virtual mic, but I think that it will always read file from beginning when device opened and you need to check how does it handle end of file. Perhaps what you would try it using pipes but then caching/discarding incoming data needs to be handled by the app reading from network.

pcm.virtmic {
    type file
    format "raw"
    slave.pcm "default"
    file '/dev/null'
    infile '/dev/urandom'
}

有关更多选项,请参阅 alsa 文档.

See alsa docs for more options.

同样,不确定这个工具是否是您真正需要的工具.如果您可以使用 'infile' 选项启动命令,就像使用 'file' 一样,但不幸的是您不能...

Again, not sure if this tool is what you really need for the task. It would have been really nifty if you could start a command with the 'infile' option, like you can with 'file' but unfortunately you can't...

希望有所帮助.

更新:slave.pcm 不能是null",而是一些真实的设备.似乎是用于计时,或者我不知道,但使用 null 会导致记录器进程永远阻塞.该设备可能会强制您以给定的采样率进行操作,因此请务必小心.使用default"是一个合理的默认值.infile 需要提供具有正确/匹配格式和速率的原始声音数据.顺便说一句,您可以查看 alsa 服务器和 jackd 以及其他声音系统和库,为您的任务提供替代解决方案

UPDATE: slave.pcm must not be "null" but some real device. It seems that is used for timing or I don't know but using null causes the recorder process to block forever. This device could force you at a given sample rate though so be careful. Using "default" is a sane default value. infile needs to provide a raw sound data with the correct/matching format and rate. btw you can look at alsa server and jackd and other sound systems and libraries for alternative solutions for your task

这篇关于模拟麦克风(虚拟麦克风)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆