Implementing sound in Ubuntu Core 24.04 for electron app

Hello,

can anyone point me in right direction in implementing sound support for snap running on Ubuntu Core?

Disclaimer: I am very new to ecosystem of both snapcraft and Ubuntu Core. I have followed documentation of snapcraft, Ubuntu Core and ubuntu-frame/mir to accomplish the task. Sadly I feel like many resources are missing or are outdated.

What has helped me the most besides resources provided by ogra1 is this starter template GitHub - canonical/iot-example-graphical-snap at 24/Electron-quick-start However the template considers implementation of sound support out of scope. Most other resources solve the task by installing pulseaudio from beta channel, but they also say that it is not recommended solution. My question is, what is the recommended solution?

From what I collected, installing snap for pulseaudio or pipewire is not recommended, one should implement audio support directly to its own snap. I think I could do it by staging packages like libasound2 and maybe some other ones. There comes another problem I was not able to solve. Where can I get list of possible stage packages? These packages do not always correlate with apt package names. Is there repository for those stage packages I can browse and also possibly read some details on what those packages provide?

Another issue may be, that when I install Ubuntu Core on x86 computer, it has by default muted all sinks. So from my understanding I still need some sort of pulseaudio utils to set correct output and unmute it? Do I also implement this into my snap or do I need another snap for this functionality?

Will be grateful for any help and possibly other resources I may dig through. I will also try my best to provide back to community by sharing things I learn along the way. At the very least I want to publish electron app example repo with sound support if I get there.

Jakub

You could (and perhaps should) use alsa directly, though my example here uses pluse (but the pulseaudio snap is largely outdated and unmaintained nowadays and pipewire is not ready yet for core):

technically using a sound server like pulse is overkill on a kiosk system where there is always only one app using the output, so shipping libasound and alsa-utils plus a few layouts to map the things in the right places might be enough…

Well yes, that’s what I am talking about. Everywhere is just pulseaudio implementation and no examples how to implement alsa directly. Sadly I have tried my best and I failed miserably. I probably got the alsa running, but I was not able to connect to sound card (aplay -l says no soundcards found…) although I have implemented alsa plug and connected it manually.

However when I played around with alsa, I noticed that there may be problem with my electron app anyways. I have also some child web views, which also play sound. In that case it is separate process and thus it has problems when two electron processes try to use alsa directly right? In that case I may need audio server anyways. If that’s the case, is really currently the only way installing pulseaudio snap? Or can I implement pulseaudio to my snap? Or should I use pulseaudio snap now and wait for pipewire being ready for core to change it later?

If pulse works for you I’d just go with it and once pipewire is ready think about switching (given it provides a pulse socket and the pulse tools work with it it should be just plug and play…)