简体   繁体   English

Linux-在没有硬件声卡的情况下,捕获音频回放并将其记录到文件中

[英]Linux - Without hardware soundcard, capture audio playback, and record it to file

Is such a thing even possible? 这样的事情有可能吗?

Is there a possibility to create a virtual sound card and then use for example PyAudio to listen to its output and save it to a file? 是否可以创建虚拟声卡,然后使用例如PyAudio监听其输出并将其保存到文件中? NOTE that there is no hardware soundcard present on the machine. 注意机器上没有硬件声卡。

I have tried a lot of things, especially snd-dummy ALSA module, but I am starting to doubt if I am looking for the right tools. 我已经尝试了很多东西,尤其是snd-dummy ALSA模块,但是我开始怀疑我是否在寻找正确的工具。 I would be grateful if someone could point me towards at least high-level solution. 如果有人能指出我至少是高级解决方案,我将不胜感激。 Preferably something that would work on Ubuntu server. 最好是可以在Ubuntu服务器上运行的东西。

Install the PulseAudio. 安装PulseAudio。

sudo apt install pulseaudio

PulseAudio has emulation for ALSA. PulseAudio具有针对ALSA的仿真。

If the application producing the sound supports JACK , this should be easy. 如果产生声音的应用程序支持JACK ,这应该很容易。 Then you only need to select the dummy driver for JACK and you can route the audio signal to any sound recording program you want (as long as it also supports JACK). 然后,您只需要为JACK选择dummy驱动程序,就可以将音频信号路由到所需的任何录音程序(只要它也支持JACK)。

You'll need the package jackd , which has a command line interface for starting the JACK daemon. 您需要包jackd ,它具有用于启动JACK守护程序的命令行界面。 The package qjackctl provides a nice GUI for experimenting with different settings and for making audio connections between programs. 软件包qjackctl提供了一个不错的GUI,用于尝试不同的设置以及在程序之间建立音频连接。 For recording, you can try the program jack_rec which is part of jackd , but there are many other recording application for JACK available as well. 对于录音,你可以尝试程序jack_rec这是一部分jackd ,但也有许多其他录音应用JACK可用。

If you want to use Python for recording, you can try the sounddevice and soundfile modules. 如果你想使用Python记录,你可以尝试sounddevice音效档模块。 If you need some JACK-specific functionality, you should try jackclient-python . 如果需要某些JACK特定功能,则应尝试jackclient-python

Thanks to both @mjy and @Matthias I have finally managed to figure out the minimal steps to take in order to make the recording work: 由于@mjy和@Matthias的帮助,我终于设法找出了使录音工作所需的最少步骤:

sudo apt-get install pulseaudio jackd2 alsa-utils dbus-x11

No need to play with snd-dummy , no need to create any additional config files... All these things only caused me to lose few hours :( After installing these packages on a clean Ubuntu server installation, I was able to run Python script and capture output audio to a file using PyAudio... 无需使用snd-dummy ,无需创建任何其他配置文件...所有这些仅使我损失了几个小时:(在干净的Ubuntu服务器安装上安装了这些软件包之后,我能够运行Python脚本并使用PyAudio将输出音频捕获到文件中...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM