11

I am trying to build a web app that captures both local and remote audios from a webrtc call, but I can`t record the remote audio(using recordRTC). I was wondering if I could capture the system sound somehow.

Is there a way to capture the system sound (not just the mic) from the browser. Maybe an extension?

  • 1
    Firefox addon works here - https://www.webrtc-experiment.com/RecordRTC/ - addon only needed for whitelisting a domain. – Noitidart Dec 12 '15 at 10:31

2 Answers2

8

In Chrome, the chrome.desktopCapture extension API can be used to capture the screen, which includes system audio (but only on Windows and Chrome OS and without plans for OS X or Linux). E.g.

chrome.desktopCapture.chooseDesktopMedia([
    'screen', 'window' // ('tab' is not supported; use chrome.tabCapture instead)
], function(streamId) {
    navigator.webkitGetUserMedia({
        audio: {
            mandatory: {
                chromeMediaSource: 'system',
                chromeMediaSourceId: streamId
            }
        },
        video: false, // We only want audio for now.
    }, function(stream) {
        // Do what you want with this MediaStream.
    }, function(error) {
        // Handle error
    });
});

I'm not sure whether Firefox can capture system sound, but at the very least it is capable of capturing some output (tab/window/browser/OS?). First you need to visit about:config and set media.getusermedia.audiocapture.enabled to true (this could be automated through a Firefox add-on). Then the stream can be captured as follows:

navigator.mozGetUserMedia({
    audio: {
        mediaSource: 'audioCapture'
    },
    video: false, // Just being explicit, we only want audio for now
}, function(stream) {
    // Do what you want with this MediaStream.
}, function(error) {
    // Handle error
});

This was implemented in Firefox 42, at https://bugzilla.mozilla.org/show_bug.cgi?id=1156472

Rob W
  • 341,306
  • 83
  • 791
  • 678
  • I tried it but I get no audio track on the resulting stream. I'm using Google Chrome 47 on Ubuntu 14.04. Does it have anything to do with browser version or OS? – Victor Canezin de Oliveira Dec 18 '15 at 16:16
  • @VictorCanezindeOliveira desktopCapture only works on Windows and Chrome OS at the moment. I've edited my answer. – Rob W Dec 18 '15 at 16:47
  • not working on firefox, I am getting Audio stream but when recording this nothing happening – Ashu Jul 17 '20 at 12:39
  • @RobW We are using Electron "It is a Desktop application development tool which uses chromium, which means Electron is somehow similar to Chrome". So the idea is when someone is using our Electron application. The user should be able to record the sound of the person he is talking to. It does not matter which application they are using to communicate "skype, zoom,.." and capture his voice and use that voice. Do you think desktopCapture does the job? Thank you – sediq khan Aug 31 '20 at 13:45
  • For reference, to use desktopCapturer in Electron on MacOS, one needs a signed kernel extension: https://www.electronjs.org/docs/latest/api/desktop-capturer#caveats – marcw Apr 21 '22 at 06:26
0

This is possible with the new Screen Capture API, but browser support is still limited.

See the "Browser compatibility" section in the above-linked MDN page for details. Some browsers currently don't yet support audio capture, and some others currently only allow audio capture from a specific tab, rather than the operating system as a whole.

Example code:

videoElem.srcObject = await navigator.mediaDevices.getDisplayMedia({audio:true, video:true});
joe
  • 3,752
  • 1
  • 32
  • 41