owntone / owntone-container

Workflows and artifacts of the containerisation of OwnTone
https://owntone.github.io/owntone-server
12 stars 2 forks source link

No audio output on local devices (eg USB-speakers) #7

Open marioscube opened 3 months ago

marioscube commented 3 months ago

I tried owntone from a docker container on debian 12 bookworm xfce.

When I try to play music to airplay devices it works (listening to music now on my homepod mini).

When I try to play music to a locally attached sound device (soundsticks) owntone does not work.

My relevant setup in owntone.conf:

    alsa "hw:1" {
    # Name used in the speaker list. If not set, the card name will be used.
    nickname = "Soundsticks"

    # Mixer channel to use for volume control
    # If not set, PCM will be used if available, otherwise Master
    # mixer = "PCM"

    # Mixer device to use for volume control
    # If not set, the card name will be used
    # mixer_device = ""
    }

Error when enabling the sound device:

[2024-08-22 09:46:31] [ LOG] laudio: Cannot get card index for 1[2024-08-22 09:46:31] [ LOG] laudio: Failed to attach mixer 'hw:1': No such file or directory [2024-08-22 09:46:31] [ LOG] laudio: Could not open mixer 'hw:1' ('(null)') [2024-08-22 09:46:31] [ LOG] web: JSON api request failed with error code 500 (/api/outputs/0/toggle) Screenshot 2024-08-22 at 11 46 45

When I use the same config on another computer with owntone installed without docker it works.

Is this a (owntone) docker limitation, a config error or something else?

hacketiwack commented 3 months ago

On the principle, containers isolate everything from the host. So this is normal that you can’t access this device from within the container. As I never did such configuration myself, I don’t know on the spot how to do it. But what you have to look for is to instruct docker or podman to get the device from the host. I will investigate in the coming days. And if you find something in between, please comment on that work item.

marioscube commented 3 months ago

Thank you for your quick response.

My dirty workaround is:

However i think it would be nice if owntone docker is able to play audio to the local speakers.

hacketiwack commented 3 months ago

Great! The secret ingredient resides in this part of the docker command: --device /dev/snd

I need to test that and document it.

marioscube commented 3 months ago

I thought so too, however when I tested this it did not work. Maybe I did something not entirely right?

Please test it for yourself.

marioscube commented 3 months ago

@hacketiwack

The owntone-container does not have a /dev/snd device.

The daapd (owntone) docker from linuxserver.io does have a /dev/snd device.

Adding --device /dev/snd to the startup script works.

Audio plays to my speakers without shairport-sync.

The volume control is not good though, much to loud!

hacketiwack commented 3 months ago

@marioscube to be sure to understand. With the version of linuxserver.io it works when you add the --device /dev/snd to your configuration but the volume is too loud. Did I understand correctly? It would be interesting to understand which package is missing so that we can add it as well.

marioscube commented 3 months ago

@hacketiwack

Indeed, if I add —device /dev/snd to the configuration of linuxserver.io daapd to start a docker container local ALSA audio works.

When using the owntone/daapd webinterface I have to slide the volume sliders almost to zero, otherwise my speakers (original usb Harman Kardon soundsticks) are way too loud. That is a problem with stairport-sync as wel. So possibly hardware specific. I need to test with other speakers.

hacketiwack commented 3 months ago

If you can verify which package needs to be added - I guess it is alsalib, plus others - then I could envision to add it. However, I don't have any way to test it as my motherboard doesn't have audio output at the moment.

Regarding the volume, I guess you have to use the alsamixer command.

marioscube commented 3 months ago

I will try tomorrow.

No need for an actual working sound card or output on your motherboard.

Just check inside the container if there is /dev/snd .

Alsamixer does not help enough.

marioscube commented 3 months ago

@hacketiwack alsa-lib-dev is not the difference (based on a quick compare of build files).

The only relevant difference I see at this moment (without building) is: --disable-install_systemd \ # = in owntone / not in daapd

marioscube commented 3 months ago

@hacketiwack

Error on building docker image of owntone with Dockerimage from repository.

OK fixed that error, my bad. Needed to read up on building a docker image.

marioscube commented 3 months ago

..... interesting ......

I build owntone-docker from this github.

git clone https://github.com/owntone/owntone-container

docker build . -t owntone:test

then:

docker run -d \
  --name=owntone \
  --network=host \
  -e UID=1000 \
  -e GID=1000 \
  -v /home/debian/Docker/owntone/config:/etc/owntone \
  -v /home/debian/Docker/owntone/media:/srv/media \
  -v /home/debian/Docker/owntone/cache:/var/cache/owntone \
  --device /dev/snd  \
  owntone:test

check for /dev/snd : docker exec -ti owntone sh cd /dev/snd exists OK! (not in owntone from docker.io/owntone/owntone:latest)

Edit owntone.conf

alsa "hw:1" {
        # Name used in the speaker list. If not set, the card name will be used.
        nickname = "Earplugs"

        # Mixer channel to use for volume control
        # If not set, PCM will be used if available, otherwise Master
  #      mixer = "PCM"

        # Mixer device to use for volume control
        # If not set, the card name will be used
  #      mixer_device = "PCM"
}

And it works ........ (for now). After some (a lot of) fiddling with the settings in owntone.conf I have music through my earphones.

@hacketiwack I would say build your own owntone docker-image and check if there is a /dev/snd device in the container. Then we can compare if needed.

marioscube commented 2 months ago

Something to add:

If I make my own image based on the buildfile of this repo then I miss group 29 in the container. Added with vi in /etc/group. It seems to have an effect on the preferences of /dev/snd and if user owntone can access audio devices.

I need to test further.

Edit: Either add a group with number 29 and user owntone as member or change the group of /dev/snd to audio and make sure user owntone is a member of audio.

timbrd commented 1 month ago

@hacketiwack

Indeed, if I add —device /dev/snd to the configuration of linuxserver.io daapd to start a docker container local ALSA audio works.

When using the owntone/daapd webinterface I have to slide the volume sliders almost to zero, otherwise my speakers (original usb Harman Kardon soundsticks) are way too loud. That is a problem with stairport-sync as wel. So possibly hardware specific. I need to test with other speakers.

Same here. I send the audio stream to an av receiver via airplay, but i have to turn the volume nearly down so that it is not too loud. Did you fix the issue with your soundsticks?

marioscube commented 1 month ago

@timbrd

Sending audio to HomePod mini and/or AirPort Express I have no problem with needing to have to turn the volume down.

If I send the audio to my USB Soundsticks I need to turn the volume almost to 0. (actually 5)

I will check again tomorrow. No solutions.

Alsa should not interfere with airplay...... Pulseaudio neither, but check.