Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guest271314/baaa0b8d4b034ff4e9352af4f2bbf42c to your computer and use it in GitHub Desktop.
Save guest271314/baaa0b8d4b034ff4e9352af4f2bbf42c to your computer and use it in GitHub Desktop.
Finally possible to capture monitor devices in Chromium and Chrome on Linux
// Finally possible to capture speechSynthesis.speak() on Chromium and Chrome
// Enable Speech Dispatcher, PulseAudio loopback for screen capture, disable default WebRTC input volume adjustment from 100% to 8%
// chrome --enable-speech-dispatcher --enable-features=PulseaudioLoopbackForScreenShare --disable-features=WebRtcAllowInputVolumeAdjustment
// Still have to manually select share system audio in picker with systemAudio set to "include"
// https://issues.chromium.org/issues/40155218
let stream = await navigator.mediaDevices.getDisplayMedia({
// We're not going to be using the video track
video: {
width: 0,
height: 0,
frameRate: 0,
displaySurface: "monitor"
},
audio: {
suppressLocalAudioPlayback: false,
// Speech synthesis audio output is generally 1 channel
channelCount: 2,
noiseSuppression: false,
autoGainControl: false,
echoCancellation: false
},
systemAudio: "include",
// Doesn't work for Tab capture
// preferCurrentTab: true
});
function log(e, ...args) {
if (e?.target) {
console.log(e.target.constructor.name, e.type);
} else {
console.log(...args);
}
};
let [videoTrack] = stream.getVideoTracks();
videoTrack.stop();
let [audioTrack] = stream.getAudioTracks();
log(null, audioTrack.constructor.name, audioTrack.kind, audioTrack.getSettings().deviceId);
let recorder = new MediaRecorder(stream);
recorder.onstart = log;
recorder.onstop = (e) => {
recorder.stream.getTracks().forEach((track) => track.stop());
log(e);
};
recorder.ondataavailable = (e) => {
console.log(URL.createObjectURL(e.data));
log(e);
};
let utterance = new SpeechSynthesisUtterance(`von Braun believed in testing. I cannot
emphasize that term enough – test, test,
test. Test to the point it breaks.
- Ed Buckbee, NASA Public Affairs Officer, Chasing the Moon`);
utterance.onstart = (e) => {
recorder.start();
log(e);
};
utterance.onend = (e) => {
recorder.stop();
log(e);
};
globalThis.speechSynthesis.speak(utterance);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment