filahf / budgie-stream

Stream system output to your Sonos devices. Built with Electron, React and Express
https://budgiestream.netlify.app/
MIT License
53 stars 4 forks source link

getUserMedia error on Ubuntu #19

Closed pascalopitz closed 3 years ago

pascalopitz commented 4 years ago

Can't get this to work on Linux:

DOMException: Could not start audio source
console.<computed> @ index.js:1
(anonymous) @ recorder.js:31
async function (async)
(anonymous) @ recorder.js:17
Promise.then (async)
startRecording @ recorder.js:13
togglePlay @ useSonos.js:9
handleButtonClick @ StartButton.js:25
callCallback @ react-dom.development.js:188
invokeGuardedCallbackDev @ react-dom.development.js:237
invokeGuardedCallback @ react-dom.development.js:292
invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:306
executeDispatch @ react-dom.development.js:389
executeDispatchesInOrder @ react-dom.development.js:414
executeDispatchesAndRelease @ react-dom.development.js:3278
executeDispatchesAndReleaseTopLevel @ react-dom.development.js:3287
forEachAccumulated @ react-dom.development.js:3259
runEventsInBatch @ react-dom.development.js:3304
runExtractedPluginEventsInBatch @ react-dom.development.js:3514
handleTopLevel @ react-dom.development.js:3558
batchedEventUpdates$1 @ react-dom.development.js:21871
batchedEventUpdates @ react-dom.development.js:795
dispatchEventForLegacyPluginEventSystem @ react-dom.development.js:3568
attemptToDispatchEvent @ react-dom.development.js:4267
dispatchEvent @ react-dom.development.js:4189
unstable_runWithPriority @ scheduler.development.js:653
runWithPriority$1 @ react-dom.development.js:11039
discreteUpdates$1 @ react-dom.development.js:21887
discreteUpdates @ react-dom.development.js:806
dispatchDiscreteEvent @ react-dom.development.js:4168

I tried passing different config object, with audio: true but it doesn't seem to capture anything.

pascalopitz commented 4 years ago

Maybe some sort of visual EQ indicator would be helpful so we know we actually capture stuff?

filahf commented 4 years ago

Yeah the visual EQ/status indicator sounds like a great idea, I'll have a look at that.

I know I managed to capture sound from my Linux machine, although just microphone audio. But I reckon that could work if you configure an ALSA loopback along with it. I'll see if I can dig up the config object I used on Linux.

pascalopitz commented 4 years ago

There might be a solution here. haven't tried it out yet: https://github.com/electron/electron/issues/4776#issuecomment-380297550

filahf commented 4 years ago

I'm able to capture microphone input with {audio: true, video: false} as config object.

You'll also need to modify the handleStream function at https://github.com/filahf/budgie-stream/blob/master/budgie-stream/src/utils/recorder.js#L39 to:

const handleStream = (stream) => {
     ̶ ̶c̶o̶n̶s̶t̶ ̶a̶u̶d̶i̶o̶T̶r̶a̶c̶k̶ ̶=̶ ̶n̶e̶w̶ ̶M̶e̶d̶i̶a̶S̶t̶r̶e̶a̶m̶(̶[̶s̶t̶r̶e̶a̶m̶.̶g̶e̶t̶T̶r̶a̶c̶k̶s̶(̶)̶[̶0̶]̶]̶)̶;̶
    var audioInput = context.createMediaStreamSource(stream);
    var bufferSize = 2048;
    // create a javascript node
    var recorder = context.createScriptProcessor(bufferSize, 1, 1);
    // specify the processing function
    recorder.onaudioprocess = recorderProcess;
    // connect stream to our recorder
    audioInput.connect(recorder);
    // connect our recorder to the previous destination
    recorder.connect(context.destination);
};