将 PulseAudio 流式传输到文件(可能使用 GStreamer)

发布于 2024-12-05 22:02:16 字数 187 浏览 2 评论 0原文

我在 Ubuntu 上,我想将 PulseAudio 输出记录到文件中,以录制 pygame 程序。格式并不重要,因为我可以稍后更改它,所以原始音频就可以了。

环顾四周,似乎 GStreamer 可能能够处理这个问题,但我对它并不熟悉,并且广泛的搜索也没有得到答案。因此,欢迎涉及 GStreamer 或其他方面的答案。

谢谢!

I'm on Ubuntu and I want to record PulseAudio output to a file, to make a recording of a pygame program. The format doesn't matter, because I can change it afterward, so raw audio is fine.

Looking around, it seems like GStreamer may be able to handle this, but I'm not familiar with it, and extensive searching has not yielded an answer. So answers involving GStreamer or otherwise are welcome.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏花。依旧 2024-12-12 22:02:16

每个pulsaudio接收器都有一个监视器。您只需要获取它的名称:

$ pactl list
...
Sink #0
    State: RUNNING
    Name: alsa_output.pci-0000_00_1b.0.analog-stereo
    Description: Internal Audio Analog Stereo
    Driver: module-alsa-card.c
    Sample Specification: s16le 2ch 44100Hz
    Channel Map: front-left,front-right
    Owner Module: 4
    Mute: no
    Volume: 0:  40% 1:  40%
            0: -23.87 dB 1: -23.87 dB
            balance 0.00
    Base Volume:  96%
                 -1.00 dB
    Monitor Source: alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
    Latency: 119973 usec, configured 210000 usec
    Flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY 
    ...

注意行监视器源:alsa_output.pci-0000_00_1b.0.analog-stereo.monitor。这是您的监控源。

首先,您需要取消静音:

$ pacmd
Welcome to PulseAudio! Use "help" for usage information.
>>> set-source-mute alsa_output.pci-0000_00_1b.0.analog-stereo.monitor false
>>> exit

现在您可以从它中录制声音:

$ parec \
>     --format=s16le \
>     --device=alsa_output.pci-0000_00_1b.0.analog-stereo.monitor \
> | oggenc --raw --quiet -o dump.ogg -

或者使用 lame:使用

$ parec \
>    --format=s16le \
>    --device=alsa_output.pci-0000_00_1b.0.analog-stereo.monitor \
> | lame -r - dump.mp3

gstreamer 也可以完成相同的操作,但如果您不需要一些复杂的处理,那么它没有多大意义:

$ gst-launch-0.10 \
>  pulsesrc device=alsa_output.pci-0000_00_1b.0.analog-stereo.monitor \
>  ! lame \
>  ! filesink location=dump.mp3

There is a monitor for each pulseaudio sink. You just need to get it's name:

$ pactl list
...
Sink #0
    State: RUNNING
    Name: alsa_output.pci-0000_00_1b.0.analog-stereo
    Description: Internal Audio Analog Stereo
    Driver: module-alsa-card.c
    Sample Specification: s16le 2ch 44100Hz
    Channel Map: front-left,front-right
    Owner Module: 4
    Mute: no
    Volume: 0:  40% 1:  40%
            0: -23.87 dB 1: -23.87 dB
            balance 0.00
    Base Volume:  96%
                 -1.00 dB
    Monitor Source: alsa_output.pci-0000_00_1b.0.analog-stereo.monitor
    Latency: 119973 usec, configured 210000 usec
    Flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY 
    ...

Note line Monitor Source: alsa_output.pci-0000_00_1b.0.analog-stereo.monitor. It is your monitor source.

First, you need to unmute it:

$ pacmd
Welcome to PulseAudio! Use "help" for usage information.
>>> set-source-mute alsa_output.pci-0000_00_1b.0.analog-stereo.monitor false
>>> exit

And now you can record sound form it:

$ parec \
>     --format=s16le \
>     --device=alsa_output.pci-0000_00_1b.0.analog-stereo.monitor \
> | oggenc --raw --quiet -o dump.ogg -

Or with lame:

$ parec \
>    --format=s16le \
>    --device=alsa_output.pci-0000_00_1b.0.analog-stereo.monitor \
> | lame -r - dump.mp3

The same could be done with gstreamer, but there is not much sense in it if you don't need some complex processing:

$ gst-launch-0.10 \
>  pulsesrc device=alsa_output.pci-0000_00_1b.0.analog-stereo.monitor \
>  ! lame \
>  ! filesink location=dump.mp3
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文