You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将PipeWire与Puppeteer配合使用?

如何将PipeWire与Puppeteer配合使用?

嘿,我之前也折腾过把Puppeteer的音频导去虚拟设备的需求,换成PipeWire后其实流程比PulseAudio更顺手,给你一步步拆解怎么做:

  • 先确认PipeWire环境正常
    首先得确保你的系统已经装了PipeWire,并且兼容PulseAudio的接口(现在大部分发行版的PipeWire默认都带这个)。可以用这条命令检查服务状态:

    systemctl --user status pipewire pipewire-pulse
    

    如果显示active (running)就没问题,要是没装的话,直接用你的包管理器装pipewire和pipewire-pulse就行。

  • 创建虚拟音频接收器(Virtual Sink)
    用PipeWire的命令直接创建一个持久化的虚拟音频设备,专门给Puppeteer用:

    pw-cli create-node adapter factory.name=support.null-audio-sink media.class=Audio/Sink object.linger=1 node.name=PuppeteerVirtualSink
    

    解释下参数:object.linger=1是让这个设备在创建后一直存在,不会随命令结束消失;node.name是给设备起个好记的名字,方便后面调用。

  • 配置Puppeteer指定这个音频设备
    启动Puppeteer的时候,在Chrome的启动参数里指定刚才创建的虚拟sink。你可以直接用设备名字,或者先通过pactl list sinks short找到它的ID(PipeWire兼容pactl命令)。

    举个Node.js的代码例子:

    const puppeteer = require('puppeteer');
    
    (async () => {
      const browser = await puppeteer.launch({
        args: [
          '--no-sandbox', // 开发环境可以加,生产环境按需调整
          '--audio-output-device=PuppeteerVirtualSink' // 这里填你的虚拟设备名字或ID
        ]
      });
      const page = await browser.newPage();
      // 可以打开一个带音频的页面测试,比如视频网站
      await page.goto('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
      await page.waitForTimeout(10000); // 等待音频播放一段时间
      await browser.close();
    })();
    
  • 验证音频是否正常转发
    怕配置错了?可以用这条命令录制虚拟sink的输出,然后播放看看有没有声音:

    pw-record --target=PuppeteerVirtualSink test_audio.wav
    # 录制完成后按Ctrl+C停止,然后播放
    aplay test_audio.wav
    
  • 可选:设置开机自动创建虚拟sink
    要是不想每次开机都手动敲命令创建设备,可以把创建命令加到PipeWire的启动配置里:

    1. 先创建配置目录(如果没有的话):mkdir -p ~/.config/pipewire/pipewire.conf.d/
    2. 创建一个配置文件99-puppeteer-virtual-sink.conf,内容如下:
      context.exec = [
        { path = "pw-cli" args = "create-node adapter factory.name=support.null-audio-sink media.class=Audio/Sink object.linger=1 node.name=PuppeteerVirtualSink" }
      ]
      
    3. 重启PipeWire服务生效:systemctl --user restart pipewire

备注:内容来源于stack exchange,提问作者Matrix 404

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.21 16:10:27