無頭瀏覽器:音訊輸出到 Pulseaudio

無頭瀏覽器:音訊輸出到 Pulseaudio

我試圖在 EC2/Ubuntu 20.04 執行個體上執行無頭瀏覽器,然後將產生的音訊串流輸出到預設的 Pulseaudio 接收器(然後由 DarkIce/Icecast 拾取)。我只想運行一個網頁(我的,託管在不同的伺服器上,需要 jQuery 和 Howler.js),並且生成的瀏覽器/串流必須保持 24/7 開放。

我已經設法在實例上獲取一個音訊檔案以在 Icecast 上播放(使用 ogg123),因此 ogg123>Pulseaudio>Darkice>Icecast2 可以工作。我創建了一個預設接收器,如下所示

pactl load-module module-null-sink sink_name=radio
pacmd update-sink-proplist radio device.description=radio
pacmd set-default-sink radio

並透過創建 ~/.asoundrc 來包含 Pulseaudio 作為預設驅動程式

pcm.default pulse
ctl.default pulse

我不確定讓瀏覽器正常運作的正確方法是什麼。我嘗試過(google-chome和chromium)直接指向音訊檔案和帶有播放音訊的js的頁面(目的是最終在螢幕中運行它),這兩種方法似乎都找到了內容,兩種方法都沒有播放任何音訊。例如,

 google-chrome-stable --headless --disable-gpu --autoplay-policy=no-user-gesture-required --user-data-dir=/home/ubuntu/chromeUser --disable-accelerated-video-decode --disable-software-rasterizer --enable-logging=stderr --v=1  https://domain.name/stream.html 

產生以下內容

[0608/102421.257217:INFO:cpu_info.cc(53)] Available number of cores: 1
[0608/102421.258656:INFO:cpu_info.cc(53)] Available number of cores: 1
[0608/102421.258861:VERBOSE1:zygote_main_linux.cc(217)] ZygoteMain: initializing 0 fork delegates
[0608/102421.259318:VERBOSE1:zygote_main_linux.cc(217)] ZygoteMain: initializing 0 fork delegates
[0608/102421.271947:VERBOSE1:webrtc_internals.cc(118)] Could not get the download directory.
[0608/102421.280120:VERBOSE1:breakpad_linux.cc(2071)] Non Browser crash dumping enabled for: gpu-process
[0608/102421.283276:ERROR:gpu_init.cc(440)] Passthrough is not supported, GL is disabled
[0608/102421.286107:VERBOSE1:breakpad_linux.cc(2071)] Non Browser crash dumping enabled for: renderer
[0608/102421.288099:VERBOSE1:sandbox_linux.cc(69)] Activated seccomp-bpf sandbox for process type: gpu-process.
[0608/102421.293815:VERBOSE1:sandbox_linux.cc(69)] Activated seccomp-bpf sandbox for process type: renderer.
[0608/102421.303930:VERBOSE1:device_data_manager_x11.cc(216)] X Input extension not available
[0608/102421.356750:VERBOSE1:configured_proxy_resolution_service.cc(852)] PAC support disabled because there is no system implementation
[0608/102421.357514:VERBOSE1:configured_proxy_resolution_service.cc(852)] PAC support disabled because there is no system implementation
[0608/102421.359494:VERBOSE1:network_delegate.cc(32)] NetworkDelegate::NotifyBeforeURLRequest: https://domain.name/stream.html
[0608/102421.411474:VERBOSE1:document.cc(3974)] Document::DispatchUnloadEvents() URL = <null>
[0608/102421.411727:VERBOSE1:document.cc(4054)] Actually dispatching an UnloadEvent: URL = <null>
[0608/102421.421675:VERBOSE1:network_delegate.cc(32)] NetworkDelegate::NotifyBeforeURLRequest: /path/to/jquery.min.js
[0608/102421.424968:VERBOSE1:network_delegate.cc(32)] NetworkDelegate::NotifyBeforeURLRequest: /path/to/jquery-ui.min.js
[0608/102421.429480:VERBOSE1:network_delegate.cc(32)] NetworkDelegate::NotifyBeforeURLRequest: /path/to/howler.min.js

這是讓它發揮作用的正確方法嗎(如果是的話,為什麼不呢?),還是我應該使用 Selenium/Puppeteer/其他東西?

謝謝,克里斯

[旁白:我嘗試過事物的數量嘗試刪除“不支援Passthrough,GL is swiftshader”錯誤,但沒有成功,儘管它似乎並沒有阻止瀏覽器訪問該頁面]

答案1

我已經成功地透過運行 Puppeteer 來實現這一點,而不是試圖從命令列與 Chromium 進行爭論。我用過這個答案(希望)使用以下參數保持 Puppeteer 打開,以使音訊自動啟動。

 this.browser = await puppeteer.launch({
     headless: true,
     ignoreDefaultArgs: [
         "--mute-audio",
     ],
     args: [
         "--autoplay-policy=no-user-gesture-required",
     ],
  });

在 PulseAudio 中設定預設接收器並添加 ~/.ascoundrc (如上所述)後,一切正常(由 DarkIce > IceCast > 廣播拾取接收器音訊)。我可能會使用顆粒物監督 Puppeteer,但目前這是一個可行的解決方案。

相關內容