Is there a way of recording only system audio with Javascript? I cant seem to find anything so any pointers are welcome.
I am aware of UserMedia and Recorder.js, but it records both System Audio and Mic audio and can it be separate? Any configs?
For anyone who wants to take a look:
$(function () {
const upworkRecorder = {
rec: {
context: null,
stream: null,
recorder: null,
},
init: function () {
if (this.rec.context === null) {
this.rec.context = new (AudioContext || webkitAudioContext)();
console.log(this.rec.context);
}
},
start: function () {
var onlyAudio = {
audio: {
sampleRate: 52000,
channelCount: {
ideal: 2,
min: 1,
},
noiseSuppression: true,
autoGainControl: true,
echoCancellation: true,
volume: 1.0,
},
video: false,
};
navigator.mediaDevices
.getUserMedia(onlyAudio)
.then(s => {
console.log(s);
this.rec.stream = s;
this.rec.recorder = new Recorder(
this.rec.context.createMediaStreamSource(s),
{ numChannels: 2 }
);
this.rec.recorder.record();
})
.catch(err => {
console.log(err.message);
});
},
stop: function () {
if (this.rec.stream !== null) {
this.rec.stream.getAudioTracks()[0].stop();
}
if (this.rec.recorder !== null) {
this.rec.recorder.stop();
}
this.rec.recorder.exportWAV(blob => {
let url = (window.URL || window.webkitURL).createObjectURL(blob);
console.log(blob, url);
const audio = document.createElement("div");
audio.innerHTML = `<h1>Your recording</h1><audio controls src=${url}></audio>`;
document.body.append(audio);
});
},
};
$("#start-rec").on("click", e => {
upworkRecorder.init();
upworkRecorder.start();
});
$("#pause-rec").on("click", e => {
upworkRecorder.stop();
});
});