헤드리스 브라우저: Pulseaudio로 오디오 출력

헤드리스 브라우저: Pulseaudio로 오디오 출력

EC2/Ubuntu 20.04 인스턴스에서 헤드리스 브라우저를 실행한 다음 결과 오디오 스트림을 기본 Pulseaudio 싱크(DarkIce/Icecast에서 선택)로 출력하려고 합니다. 저는 단일 웹페이지(내 웹페이지는 다른 서버에서 호스팅되고 jQuery 및 Howler.js가 필요함)만 실행하고 싶고 결과 브라우저/스트림은 연중무휴 24시간 열려 있어야 합니다.

인스턴스에서 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/다른 것을 사용해야 합니까?

고마워요, 크리스

[제쳐두고: 나는 한 가지를 시도했습니다사물의 수"패스스루는 지원되지 않습니다. GL은 Swiftshader입니다." 오류를 제거하려고 시도했지만 성공하지 못했습니다. 그러나 브라우저가 페이지에 액세스하는 것을 막지는 못하는 것 같습니다.]

답변1

나는 명령줄에서 Chromium을 다루려고 시도하는 대신 Puppeteer를 실행하여 이 작업을 수행했습니다. 나는 사용했다이 답변(희망적으로) 오디오가 자동으로 시작되도록 다음 인수를 사용하여 Puppeteer를 열어 두십시오.

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

PulseAudio에서 기본 싱크를 설정하고 ~/.ascoundrc(위와 같이)를 추가하면 모든 것이 작동합니다(DarkIce > IceCast > 브로드캐스트에서 선택한 오디오 싱크). 나는 아마 사용할 것이다오후 2시Puppeteer를 감독하기 위한 것이지만 현재로서는 작동하는 솔루션입니다.

관련 정보