Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chromium does not support capture of monitor devices by default #17

Open
guest271314 opened this issue Aug 14, 2020 · 4 comments
Open
Assignees
Labels

Comments

@guest271314
Copy link
Owner

Chromium does not support capture of monitor devices by default https://bugs.chromium.org/p/chromium/issues/detail?id=1114422.

Workarounds https://github.com/guest271314/captureSystemAudio.

@guest271314 guest271314 self-assigned this Aug 14, 2020
@guest271314
Copy link
Owner Author

Workaround for https://bugs.chromium.org/p/chromium/issues/detail?id=931749#c6 where Chromium refuses to support listing or capturing monitor devices https://bugs.chromium.org/p/chromium/issues/detail?id=1155954#c_ts1607798815.

$ pactl load-module module-remap-source \
  master="$(pactl list | grep -A2 'Source #' | grep 'Name: .*\.monitor$' | cut -d" " -f2)" \
  source_name=virtmic source_properties=device.description=Virtual_Microphone
$ pactl set-default-source virtmic

See https://github.com/guest271314/captureSystemAudio#pulseaudio-module-remap-source.

@guest271314
Copy link
Owner Author

guest271314 commented Dec 23, 2020

To capture speech-dispatcher-espeak-ng module at Linux on Chromium or Chrome we create a virtual device and remap the monitor thereof to a different name to avoid Chrome refusing to list or capture monitor devices

pactl load-module module-combine-sink \
sink_name=Web_Speech_Sink slaves=$(pacmd list-sinks | grep -A1 "* index" | grep -oP "<\K[^ >]+") \
sink_properties=device.description="Web_Speech_Stream" \
format=s16le \
channels=1 \
rate=22050
pactl load-module module-remap-source \
master=Web_Speech_Sink.monitor \
source_name=Web_Speech_Monitor \
source_properties=device.description=Web_Speech_Output
pactl move-sink-input $(pacmd list-sink-inputs | tac | perl -E'undef$/;$_=<>;/speech-dispatcher-espeak-ng.*?index: (\d+)\n/s;say $1') Web_Speech_Sink

We can then select device with label 'Web_Speech_Output'

navigator.mediaDevices.getUserMedia({audio: true})
.then(async stream => {
  const [track] = stream.getAudioTracks();
  const devices = await navigator.mediaDevices.enumerateDevices();
  const device = devices.find(({label}) => label === 'Web_Speech_Output');
  if (track.getSettings().deviceId === device.deviceId) {
    return stream;
  } else {
    track.stop();
    console.log(devices, device);
    return navigator.mediaDevices.getUserMedia({audio: {deviceId: {exact: device.deviceId}}});
  }
})
.then(stream => {
  const recorder = new MediaRecorder(stream);
  recorder.ondataavailable = e => console.log(URL.createObjectURL(e.data));
  const synth = speechSynthesis;
  const u = new SpeechSynthesisUtterance('test');
  u.onstart = e => {
    recorder.start();
    console.log(e);
  }
  u.onend = e => {
    recorder.stop();
    recorder.stream.getTracks().forEach(track => track.stop());
    console.log(e);
  }
  synth.speak(u);
});

References:

@guest271314
Copy link
Owner Author

Workaround for https://bugs.chromium.org/p/chromium/issues/detail?id=931749#c6 where Chromium refuses to support listing or capturing monitor devices https://bugs.chromium.org/p/chromium/issues/detail?id=1155954#c_ts1607798815.

$ pactl load-module module-remap-source \
  master="$(pactl list | grep -A2 'Source #' | grep 'Name: .*\.monitor$' | cut -d" " -f2)" \
  source_name=virtmic source_properties=device.description=Virtual_Microphone
$ pactl set-default-source virtmic

See https://github.com/guest271314/captureSystemAudio#pulseaudio-module-remap-source.

This evidently no longer works on Chromium 104. Records only silence.

@guest271314
Copy link
Owner Author

Workarounds working again on Chrome 106.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant