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

No sound on Ubuntu 18.04 #21

Open axi92 opened 3 years ago

axi92 commented 3 years ago

I fired up the dev env with firstnpx electron-rebuild. Started the app, the json from my devices looks good. I can select a device press play. And then start a youtube video. But I don't hear anything on my sonos speaker.

Console log:

[1] strange error flushing buffer ... 
[1] Yeay
[1] strange error flushing buffer ... 
[1] strange error flushing buffer ... 
[1] Yeay
[1] strange error flushing buffer ... 
[1] strange error flushing buffer ... 
[1] Yeay
[1] strange error flushing buffer ... 
[1] strange error flushing buffer ... 
[1] Yeay
[1] strange error flushing buffer ...
filahf commented 3 years ago

Apparently linux based systems wont allow system output as input in unsigned software.

There is a workaround though. You'll need too configure a loopback in your sound settings and modify the handleStream function at https://github.com/filahf/budgie-stream/blob/master/budgie-stream/src/utils/recorder.js#L39 to:

const handleStream = (stream) => {
    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);
};
jaypz commented 3 years ago

configure a loopback in your sound settings

can you go into a little more detail here? I made the modifications it seems like I'm almost there but this seems to be the missing piece

filahf commented 3 years ago

configure a loopback in your sound settings

can you go into a little more detail here? I made the modifications it seems like I'm almost there but this seems to be the missing piece

I think I was following this tutorial for setting up an audio loopback device (system output will be directed like it was coming from a microphone).

https://sysplay.in/blog/linux/2019/06/playing-with-alsa-loopback-devices/

However, modifying the code for source selection is quite tedious so I think I'll add a source selection to the settings pane.

Let me know how it goes!

jaypz commented 3 years ago

Let me know how it goes!

I should've updated my comment :sweat_smile: I did end up getting this working; I realized budgie was never actually opening a recording stream but otherwise seemed to be working; this is what had me so confused - I realized in the console log there was an error opening recording device, so I ended up needing to make minor modification to startRecording in addition to the changes you outline for handleStream (I just turned off video, otherwise it seems to not work at all)

export const startRecording = () => {
  audioContext = window.AudioContext;
  context = new audioContext();
  desktopCapturer.getSources({ types: ["screen"] }).then(async (sources) => {
    for (const source of sources) {
      if (source.name === "Entire Screen" || "Screen 1") {
        try {
          const stream = await navigator.mediaDevices.getUserMedia({
            audio: true,
            video: false,
          });
          handleStream(stream);
        } catch (e) {
          console.log(e);
        }
        return;
      }
    }
  });
};

const handleStream = (stream) => {
  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);
};

after doing this budgie successfully showed it had opened a recording stream in pavucontrol and from there I was finally able to set budgie to use loopback of my audio output after I enabled pulse audio loopback via pactl load-module module-loopback

unfortunately I found the audio to cut in and out a bit over wireless network; may dig around a little more to see if I can figure out anything to improve things

Cool stuff thanks for your contributions here

*edit: I'm on Ubuntu 21.04