Playing sound at the same time from Rhasspy (Docker) and the host

I have a Pi Zero with a USB soundcard and a PS3 Eye set up with Rhasspy 2.5-pre in Docker. I’ve set up my asoundrc.conf to be able to play and record from multiple applications at the same time outside of Docker (which indicates to me that my dmix and dsnoop config is working), but then when I try to play back a file from the host and from within the Rhasspy container at the same time, I get an error from aplay:

root@1530daa229ed:/usr/lib/rhasspy-voltron# aplay etc/wav/beep_hi.wav 
ALSA lib pcm_dmix.c:1108:(snd_pcm_dmix_open) unable to open slave
aplay: main:828: audio open error: Device or resource busy

Has anyone had any success with getting sound to play on the host and inside a Docker container at the same time?

I’ve tried linking my /etc/asoundrc.conf into the container (-v /etc/asound.conf:/etc/asound.conf:ro), making /dev/snd available in the container (--device /dev/snd), and even setting the container to privileged without any success.

When the host is not playing and I have brought /dev/snd and my asoundrc.conf into the container, I can play multiple files from within the container as I would on the host. I’m not quite sure how the dmix ALSA plugin works, but if it accesses the hardware directly through DMA, perhaps the instance inside the Docker container is trying to grab the hardware device and create an entirely new dmix plugin instance within the container instead of using the existing one outside of the container. Any ALSA gurus have any ideas?

Because this is on a Pi Zero, I’d rather not run pulseaudio and hog more CPU…

Any advice would be appreciated! Thanks!

Well, I may have answered my own question. Running this:

$ aplay -D plug:dmix test.wav

in both the container and on the host at the same time results in both files being played back at the same time!

Now to figure out how to make this the default…

Just adapt the respeaker 2mic asound.conf

# The IPC key of dmix or dsnoop plugin must be unique
# If 555555 or 666666 is used by other processes, use another one


# use samplerate to resample as speexdsp resample is bad
defaults.pcm.rate_converter "samplerate"

pcm.!default {
    type asym
    playback.pcm "playback"
    capture.pcm "capture"
}

pcm.playback {
    type plug
    slave.pcm "dmixed"
}

pcm.capture {
    type plug
    slave.pcm "array"
}

pcm.dmixed {
    type dmix
    slave.pcm "hw:seeed2micvoicec"
    ipc_key 555555 
}

pcm.array {
    type dsnoop
    slave {
        pcm "hw:seeed2micvoicec"
        channels 2
    }
    ipc_key 666666
}

Found my problem. In my own asound.conf, I had the following line in my pcm.dmixed section:

   ipc_key_add_uid yes

This was causing the issue as the uid in the container was different from the uid in the host.
After I removed that line and reloaded the alsa config, all was working as expected.

Hope this helps someone else in the future!

Hello,

one question is this working when alsa conf as above is done only on host machine? I have problems, when modifying asound.conf on hot machine my Rhasspy running in Docker do not see changes. For example I created new PCM device for output into the file and I can see it corectly in aplay -L on host machine, but Rhasspy Docker even after restart do not list it as output device on the web configuration page under alsa output devices dropdown.

Thank you. :slight_smile:
litin

Make sure you run the container with --device /dev/snd, or add a devices: line to your docker-compose.yaml file.

Because I also have some extra plugins for my PS Eye mic, I map my asound.conf into the container as well. Here is my docker-compose.yaml:

version: "2"
services:
  rhasspy:
    container_name: rhasspy
    image: "rhasspy/rhasspy:2.5.0-pre-arm32v6"
    restart: unless-stopped
    ipc: host
    volumes:
        - "/home/pi/docker/rhasspy/profiles:/profiles"
        - "/etc/asound.conf:/etc/asound.conf"
    ports:
        - "12101:12101"
    devices:
        - "/dev/snd/:/dev/snd/"
    command: --user-profiles /profiles --profile en

And here is my /etc/asound.conf:

pcm.array {
  type hw
  card CameraB409241
}

pcm.dsnooped {
    type dsnoop
    ipc_key 666666
    ipc_perm 0666
    slave.pcm "array"
}

pcm.array_gain {
    type softvol
    slave.pcm "dsnooped"
    control {
      name "PSEye"
      count 2
      card 0
    }
    min_dB -10.0
    max_dB 30.0
}

pcm.cap {
  type plug
  slave.pcm "array_gain"
  slave.channels 4
  ttable {
    0.0 15.0
    1.1 15.0
  }
}

pcm.dmixed {
    type dmix
    ipc_key 555555
    ipc_perm 0666
    slave.pcm "hw:0,0"
}

pcm.!default {
    type asym
    playback.pcm {
        type plug
        slave.pcm "dmixed"
    }
    capture.pcm {
        type plug
        slave.pcm "cap"
   }
}

ctl.!default {
        type hw
        card 0
}

Hope it helps.

Like hawkeye says your missing an internal asound.conf
"/etc/asound.conf:/etc/asound.conf"

But not sure if you should share same and prob create another file for docker.

So you have unique ipc_key 555555

Thank you for help.

Yes I run container with standard

--device /dev/snd:/dev/snd \

otherwise I would not be able to get sound output from Rhasspy at all.

I just added to /etc/asound.conf

pcm.snapcast_fifo {
    type plug
    slave {
        pcm {
            type file
            file "/tmp/snapfifo"
            slave.pcm null
            format raw
        }
        rate 48000
        format s24_3le
        channels 2
    }
}

on the host machine I see:

# aplay -L
null
    Discard all samples (playback) or generate zero samples (capture)
snapcast_fifo
default:CARD=ArrayUAC10
    ReSpeaker 4 Mic Array (UAC1.0), USB Audio
    Default Audio Device
......

I am still not able to see snapcast_fifo in Rhasspy web under alsa devices dropdown. Should I redeploy Rhasspy container?

P.S.: As you can see I would prefer Rhasspy in Docker to output into pipe input of snapcast client running on the same host. As far as I understand, snapcast discouraging using mix devices for its output because in would introduce delay and therefore desynchronization of snapcat audio.

does docker have access to /tmp/snapfifo and does docker have access to an internal asound.conf?

If you map in your asound.conf as I did, you should see all your devices inside the container.

Nope and now I understand I need both… Thank you.

/etc/asound.conf - so alsa running in the Docker will see device
/tmp/snapfifo - to be able to share the pipe (output for Rhasspy, input for snapcast)

Thank you.

BTW:do you know about any other better way how to share Rhasspy output with media players running on the same machine or snapcast?

Yep, that’s it.

I use snapcast on my Pi as well and have not noticed any latency issues using alsa’s dmix. Snapcast’s snapclient is running on the host and Rhasspy is in Docker.

Docker always does me that way its confusing and a mistake I often make that its a container and contained with own devices and file structure.

“share Rhasspy output with media players running on the same machine or snapcast”?

As in media meta data rather than output? Container & host just think as seperate machines on the same network.

PS default for /tmp in raspbian isnt tmpfs so you could get a lot of writes to your sd card.

You can either create an fstab entry with tmpfs or use the above on the host.

tmpfs /tmp tmpfs defaults,noatime 0 0 or something in fstab

I usually spam the above as it was just a protest to get biantu repos to sort out the bad zram-config they have, but people seem to find it usefull.

Thank you. :slight_smile:
that is very good hint. Just one thing, I believe that named pipes are never written to disk, as they stay in RAM only. Anyway Zram is very god project for swap and other directories to prevent SDcard wear.

Doh not the named pipe but the file fifo /tmp/snapfifo apols. If the green activity light is on whilst in use then prob so, if not prob not.

Well IMHO fifo file == named pipe. Google says same. :slight_smile:
(https://www.linuxjournal.com/article/2156)

snapcast fifo: The server’s audio input is a named pipe /tmp/snapfifo.
(https://manpages.ubuntu.com/manpages/disco/man1/snapserver.1.html)

I am just saying /tmp on Raspbian is just part of the normal / root directory and file based.

Can not remember if Ubuntu moved to tmpfs by default or not.
If when using the green activity led is on then its constant file access, if not its likely ram.

The server’s audio input is a named pipe /tmp/snapfifo. All data that is fed into this
file will be send to the connected clients

That sounds very much like a file and if in /tmp on raspbian its not in ram, by default.

sudo apt-get install  inotify-tools
inotifywait -m /tmp

True

No, at least up to 18.04.

Base on snapcast decumentation it is not file, it is named pipe. Content written to named pipe is not be written to disk and it doesn’t matters where it resides (if on tmpfs mount point or zram or disk)

I hope, that it is no more clear. :wink:

Yeah had a look its just a mount point, thought the buffer was on disk

@litinoveweedle are you gonna pipe everything from /tmp/snapfifo to rhasspy output?

I’ve opened a thread about streaming radio on the same machine as rhasspy is running. Maybe we are both trying something pretty similiar? So far my mopidy isn’t working properly. How do you feed snapserver with music in your scenario?

Hello I do not know if I understand your question correctly, but lets discuss it in your thread.

1 Like

OK, I am lost.

I tried for last 2 days to get working alsa config to allow me to dmix and softvol two sources - one from host an second from Docker. And I can’t get it to work. Here is what I have:

  • Respeaker USB MIc Array v2 card (with 48kHz + 1 channel input fw), which can only play audi when recoded into 48kHz, S24_3LE, 2channel stream.

  • Snapcast client on host, which is unable to recode (include server) into S24_3LE, and therefore I do receive 48kHz, S16_LE, 2 channel stream.

  • Rhasspy in Docker, using aplay.

I want both application to output simultaneously, playing to Respeaker card. Also I want to be able to set volume independently for each application. I tried almost any combination I can think of, but I failed.

It seems that problem is Docker, which is not able to share alsa dmix device, so even if dmix is working locally (i.e. on the host I can play from both apps in the same time) this doesn’t work in Docker.

So my snapcast client started on system boot will start playing music, but from rhasspy Docker when I try to play any file I get:

root@b4a24c1da87d:/# aplay -D rhasspy /usr/share/rhasspy/etc/wav/beep_hi.wav -v
ALSA lib pcm_dmix.c:1108:(snd_pcm_dmix_open) unable to open slave
aplay: main:828: audio open error: Device or resource busy

Using same command on host:

pi@speakerliving:~/rhasspy $ aplay -D rhasspy beep_error.wav
Playing WAVE ‘beep_error.wav’ : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo

works like a charm. So the only problem is dmix alsa plugin shared via Docker. :frowning: From this source:

For ALSA sound just share sound devices with --device /dev/snd . You would not need the more advanced Pulseaudio setup, but will have trouble if more than one application tries to access the sound hardware. x11docker provides this setup with option --alsa .

And no, I don’t want to try Pulse Audio on RPi. :stuck_out_tongue_closed_eyes:

I would be glad for any help/hint/idea. Only one in my mind now is to install snapcast client into Rhasspy docker. But hat meant starting maintain my own Docker forks.:upside_down_face:

FYI: my current asound.conf:

pcm.mix {
    type dmix
    ipc_key 1024
    ipc_perm 0666
    slave {
        pcm "hw:0,0"
        period_time 0
        period_size 1024
        buffer_size 4096
        rate 48000
        format S24_3LE
    }
    bindings {
        0 0
        1 1
    }
}


pcm.snapcast {
    type plug
    slave.pcm "snapcast_vol"
}


pcm.snapcast_vol {
    type softvol
    slave.pcm "mix"
    control {
        name "Snapcast"
        card 0
    }
}


pcm.rhasspy {
    type plug
    slave.pcm "rhasspy_vol"
}


pcm.rhasspy_vol {
    type softvol
    slave.pcm "mix"
    control {
        name "Rhasspy"
        card 0
    }
}

A couple of questions:

  1. What’s your run line or what’s in your docker-compose.yaml for Rhasspy?
  2. Are you mapping the host’s asound.conf inside the Rhasspy docker container?

Hello,

I map both /dev/snd and /etc/asound.conf.

docker run -d -p 12101:12101 --restart unless-stopped --name rhasspy -v "/home/pi/rhasspy/profiles:/profiles" -v "/etc/asound.conf:/etc/asound.conf" --device /dev/snd:/dev/snd synesthesiam/rhasspy-server:latest --user-profiles /profiles --profile en

The issue seems to be docker limitation.

Also create a copy of your asound.conf somewhere and the one in the docker run command give it a unique IPC.

@hawkeye217 has his running that way I think and all is hunky dory.

But also your not setting the defaults with an asym.

pcm.!default {
    type asym
    playback.pcm "eci"
    capture.pcm "eco"
}


pcm.eci {
    type plug
    slave {
        format S16_LE
        rate 16000
        channels 1
        pcm {
            type file
            slave.pcm null
            file "/tmp/ec.input"
            format "raw"
        }
    }
}

pcm.eco {
    type plug
    slave.pcm {
        type fifo
        infile "/tmp/ec.output"
        rate 16000
        format S16_LE
        channels 2
    }
}

Just posted all of mine as using software EC but thought I would ask as your calling it snapcast but just seems to point at your card.
The card also is hw:0 you sure about that as no pi embedded?

Try adding --ipc="host" to your command line.

2 Likes

YES, thank you! This done the trick. :slight_smile:

2 Likes

Now I am missing last thing, some hook to mute snapcast on wake word recognition. To mute snapcast is easy as snapcast server has API, only to find some Rhasspy trigger to use. :slight_smile:

Great! Glad it worked.

You could probably do this with a little bash script listening on the appropriate MQTT topics and through the amixer command line tool.

Thank you again. Well so far I am using Rhasspy http API for integration. Is there any other benefit using MQTT for client/server integration?

Not 100% sure, but from what I can tell, Rhasspy’s websocket API isn’t as robust as MQTT to be able to get in and hack something together.

Because of what rhasspy is, a ai voice controlled hmi it does make sense to use MQTT

http://mqtt.org/

MQTT is a machine-to-machine (M2M)/“Internet of Things” connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport. It is useful for connections with remote locations where a small code footprint is required and/or network bandwidth is at a premium. For example, it has been used in sensors communicating to a broker via satellite link, over occasional dial-up connections with healthcare providers, and in a range of home automation and small device scenarios. It is also ideal for mobile applications because of its small size, low power usage, minimised data packets, and efficient distribution of information to one or many receivers

Has some well defined core building blocks and its prob wise to continue to use MQTT due to it likely being the default machine-to-machine (M2M)/“Internet of Things” connectivity protocol of practically everything.

If https://docs.snips.ai/reference/hermes should be implemented or used as a guide to the base use of opensource MQTT I guess needs some clarrification.
As to the Hermes audio transport I am beginning to think audio might be a bad format when there are so many advantages in sending and processing Mel Filter (MFCC) Spectrograms and audio distribution via Snapcast which is really great for that purpose.
But again Hermes audio has already been defined, but passing wavs is anything but lightweight.

MQTT is prob a really good idea to follow.

Thank you both for reply. I know MQTT as I use it for Homeassistant integrations, I did even wrote few integrations for my home bred Raspberry Pi devices. My question was more like if there are any drawbacks (for example speed, resources consumption, etc of MQTT vs HTTP)

I checked on Rhasspy 2.5 (i.e. Voltron) and I saw that MQTT seems to be primary way how all component are integrated. But right now, as I use Homeassistant conversation integration for intent recognition (with Almond), I can’t use Rhasspy 2.5 (as by the docs this integration is not yet complete). So I will wait until I will be able to test it.

Than it should be no problem to write MQTT client which will subscribe for Hermes topics and could do things like snapcast client muting, or Respeaker Array LED control. :slight_smile:

1 Like

I really like the look of snapcast and how it does latency handling.
It also has codec support that can reduce bandwidth requirements substantially.
Maybe should also have an option for a lightweight codec like the ones bluetooth uses.
But it looks awesome but do you guys know if you can just stream single channels to devices or do you split them and create multiple streams?
If your setting up and playing with snapcast create a thread and let us know what and how your doing as my only criticism of snapchat is the documentation.

But I am interested in your setup, devices, speakers, AI and what you do.

I found that MQTT seemed a bit faster for me with my setup.

I use Rhasspy 2.5-pre with Home Assistant intents and it’s working great. See this other thread on how I’ve done it.

Thank you for observation.

I would preffer to keep my HA integration with Almond, which is conversation integration - which seems to be not yet finished in Rhasspy 2.5. This is actually free speach integration… You do not need to create intents at all and work supringly OK.

Thanks a lot for this thread. This helped me a lot. I managed to play sound from Rhasspy (Docker) and Squeezelite (Host) at the same time only by you !

1 Like

Hi,

maybe someone here can help me.
I have rhasspy (docker) and mopidy (host) running.
Once mopidy was on rhasspy can’t make a sound.
I have tried to take over my asound.conf in the container.
Unfortunately without success

The command “aplay /usr/share/sounds/alsa/Front_Center.wav” works on the host but not in the container

Error

ALSA lib pcm_dmix.c:1108:(snd_pcm_dmix_open) unable to open slave
aplay: main:828: audio open error: Device or resource busy

asound.conf

# use samplerate to resample as speexdsp resample is bad
defaults.pcm.rate_converter "samplerate"

pcm.!default {
    type asym
    playback.pcm "playback"
    capture.pcm "capture"
}

pcm.playback {
    type plug
    slave.pcm "dmixed"
}

pcm.capture {
    type plug
    slave.pcm "array"
}

pcm.dmixed {
    type dmix
    ipc_perm 0666
    slave.pcm "hw:seeed2micvoicec"
    ipc_key 555555
}

pcm.array {
    type dsnoop
    slave {
        pcm "hw:seeed2micvoicec"
        channels 2
    }
    ipc_key 666666
}

Haaa, I was solving same issue. And with help of others I solved it. As far as I remember I needed to do several things:

  1. Create two playback devices in alsa asound.conf and dmix them to given HW card (one is for Rhasspy playback TTS and second for music playback - in my case snapcast client)
  2. Share same asound.conf between host and Rhasspy Docker container
  3. Share host IPC Rhasspy Docker container

asound.conf (with independent sof volume control for both playback channels)

pcm.mix {
    type dmix
    ipc_key 1024
    ipc_perm 0666
    slave {
        pcm "hw:0,0"
        period_time 0
        period_size 1024
        buffer_size 4096
        rate 48000
        format S24_3LE
    }
    bindings {
        0 0
        1 1
    }
}


pcm.snapcast {
    type plug
    slave.pcm "snapcast_vol"
}


pcm.snapcast_vol {
    type softvol
    slave.pcm "mix"
    control {
        name "Snapcast"
        card 0
    }
}


pcm.rhasspy {
    type plug
    slave.pcm "rhasspy_vol"
}


pcm.rhasspy_vol {
    type softvol
    slave.pcm "mix"
    control {
        name "Rhasspy"
        card 0
    }
}


pcm.snoop {
    type dsnoop
    ipc_key 2048
    ipc_perm 0666
    slave {
        pcm "hw:0,0"
        channels 1
        period_size 1024
        buffer_size 4096
        rate 48000
        format S16_LE
    }
    bindings {
        0 0
    }
}


pcm.mic {
    type plug
    slave.pcm "mic_vol"
}


pcm.mic_vol {
    type softvol
    slave.pcm "snoop"
    control {
      name "Mic"
      card 0
    }
    min_dB -10.0
    max_dB 30.0
}

docker run (with both 2. + 3. requirements)

docker run -d -p 12101:12101
           --name rhasspy \
           --restart unless-stopped \
           -v "$HOME/.config/rhasspy/profiles:/profiles" \
           -v "/etc/localtime:/etc/localtime:ro" \
           -v "/etc/asound.conf:/etc/asound.conf" \
           --device /dev/snd:/dev/snd \
           --ipc="host" \
           rhasspy/rhasspy --user-profiles /profiles  --profile en

2 Likes

Thank you.
With this asound.conf and docker command it works now.
But explain me something.
Wich parameter in your docker command makes it work?
It dosen’t work with mine.

docker run -it 
    --name rhasspy \
    --restart always \
    -v "$HOME/.config/rhasspy/satellite:/profiles"  \
    -v "/etc/asound.conf:/etc/asound.conf" \
    --network host \
    --device /dev/snd \
    rhasspy/rhasspy --profile de --user-profiles /profiles --local-mqtt-port 13183

The one missing :slight_smile:

 --ipc="host" \

Hello guys, thank you for all the hints here!

I’ve quite achieve my goal on my laptop: playing audio from Rhasspy docker and my base OS at the same time.

I’m saying quite because if I use rhasspy TTS (based on my “rhasspy” audio device) or other audio output flows from Rhasspy while using “speaker-test -D host” from a terminal on my computer (my “host” audio device ), the audio is mixed and played correctly (TTS sentence mixed with pink noise).

But if I’m using my computer normally while rhasspy is saying something through the TTS system then I got a “resource busy” (eg: while rhasspy is talking, if i’m opening a youtube video, this got stuck with loading loader icon)

I’m on Ubuntu 18.04 and this is my .asoundrc file (or asound.conf).

Maybe I’m just missing some basic step to do on my host or maybe I need to use the PulseAudio features as described here https://github.com/TheBiggerGuy/docker-pulseaudio-example ?

pcm.!default {
    type plug
    slave.pcm "host_vol"
}


pcm.host_vol {
    type softvol
    slave.pcm "mix"
    control {
        name "default"
        card 0
    }
}


pcm.rhasspy {
    type plug
    slave.pcm "rhasspy_vol"
}


pcm.rhasspy_vol {
    type softvol
    slave.pcm "mix"
    control {
        name "Rhasspy"
        card 0
    }
}

pcm.mix {
    type dmix
    ipc_key 1024
    ipc_perm 0666
    slave {
        pcm "hw:0,0"
        period_time 0
        period_size 1024
        buffer_size 4096
        rate 48000
        format S24_3LE
    }
    bindings {
        0 0
        1 1
    }
}

ctl.!default {
        type hw           
        card 0
}

Notice:

It took me too long to figure out, what was the problem and I couldn’t have rhasspy read my “virtual channels”.

So if you have rhasspy with docker-compose running and you have already added the /etc/asound.conf binded that in docker-compose.yml added also the line ipc: host then you should delete the volumes from container with:

docker-compose down -v

And then start the container.

docker-compose up -d

Just to make sure nobody else tries only to restart the rhasspy container without deleting the volumes…

The above is almost correct

So the docker run will be

docker run -d -p 12101:12101 \
    --ipc=host \
    --name rhasspy \
    --restart unless-stopped \
    -v "$HOME/.config/rhasspy/profiles:/profiles" \
    -v "/etc/asound.conf:/etc/asound.conf:ro" \
    -v "/etc/localtime:/etc/localtime:ro" \
    --device /dev/snd:/dev/snd \
    rhasspy/rhasspy \
    --user-profiles /profiles \
    --profile en

So you will have to stop the container rm to remove then docker run again
The /etc/asound.conf for the 2mic is as so

# The IPC key of dmix or dsnoop plugin must be unique
# If 555555 or 666666 is used by other processes, use another one


# use samplerate to resample as speexdsp resample is bad
defaults.pcm.rate_converter "samplerate"

pcm.!default {
    type asym
    playback.pcm "playback"
    capture.pcm "capture"
}

pcm.playback {
    type plug
    slave.pcm "dmixed"
}

pcm.capture {
    type plug
    slave.pcm "array"
}

pcm.dmixed {
    type dmix
    slave.pcm "hw:seeed2micvoicec"
    ipc_key 555555
    ipc_perm 0666
}

pcm.array {
    type dsnoop
    slave {
        pcm "hw:seeed2micvoicec"
        channels 2
    }
    ipc_key 666666
    ipc_perm 0666
}

The respeaker install for some reason misses the ipc_perm 0666 and without permissions you will get an ipc error.

So to recap you need to add --ipc=“host” which uses the ipc of the host so also share a copy of /etc/asound.conf in the docker run as -v "/etc/asound.conf:/etc/asound.conf:ro" \ that way the same IPC and settings are on the host and in the container and rhasspy should be set to use default as the /etc/asound.conf sets that.

If on the cli I run speaker-test I get that horrid pink noise test and if I sudo docker exec -it rhasspy /bin/bash and run speaker-test in the container I get double the horrid pink noise test, running at the same time but mixed.

I added --ipc="host" to my docker command and added ipc_perm 0666 to pcm.array in asound.conf

I made several docker stop, rm, runs and some reboots.
Seems like now rhasspy only play sound if i had not yet used squeezelite, after start/stop squeezelite rhasspy dont play sound anymore.

Before changing rhasspy played sound after stopping the player
I remember the above behavior from the past, dont know how/when it changed to be usable after player stop.

I hear nothing from speaker-test, probably because it uses the other pi soundcard rather the respeaker one.

speaker-test -Ddmix:seeed2micvoicec -c2
gives a device busy error, after restart there is an error about 48000 Hz not supported.

docker run -d -p 12101:12101 -p 12183:12183 
  --ipc="host" --name rhasspy --restart unless-stopped 
  -v "$HOME/.config/rhasspy/profiles:/profiles" 
  -v "/etc/localtime:/etc/localtime:ro" 
  -v "/etc/asound.conf:/etc/asound.conf" 
  --device /dev/snd:/dev/snd rhasspy/rhasspy 
  --user-profiles /profiles --profile de
# The IPC key of dmix or dsnoop plugin must be unique
# If 555555 or 666666 is used by other processes, use another one


# use samplerate to resample as speexdsp resample is bad
defaults.pcm.rate_converter "samplerate"

pcm.!default {
    type asym
    playback.pcm "playback"
    capture.pcm "capture"
}

pcm.playback {
    type plug
    slave.pcm "dmixed"
}

pcm.capture {
    type plug
    slave.pcm "array"
}

pcm.dmixed {
    type dmix
    ipc_perm 0666       # Andere Benutzer können ebenfalls dmix gleichzeitig nutzen
    slave.pcm "hw:seeed2micvoicec"
    ipc_key 555555.
    ipc_key_add_uid false
}

pcm.array {
    type dsnoop
    slave {
        pcm "hw:seeed2micvoicec"
        channels 2
    }
    ipc_key 666666
    ipc_perm 0666
}
$ aplay -l
card 0: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones]
  Subdevices: 8/8
  ...

card 1: seeed2micvoicec [seeed-2mic-voicecard], device 0: bcm2835-i2s-wm8960-hifi wm8960-hifi-0 [bcm2835-i2s-wm8960-hifi wm8960-hifi-0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

Did you delete the container and do the docker run again as the speaker-test not giving an output means /etc/asound.conf must not be active as if it was the default would be set.

pcm.!default {
    type asym
    playback.pcm "playback"
    capture.pcm "capture"
}

I have never tried speaker-test -Ddmix:seeed2micvoicec -c2 but it would never use the IPC of -Ddmixed and on its own like that has no IPC set, so don’t think that would work anyway as a dmix and if it does it would be the same as hw: or plug: due to no IPC

At a guess somewhere in the config be it squeezelite, rhasspy web config likely there is something not using the default and has a hw: or plughw: that is likely locking others out maybe.

I haven’t got that image up and running now and also never tried squeezelite but thinking how I have it, it will prob work.
I might get round to setting it up with squeezelite later or tomorrow

I deleted the container several times.
I dont know how to do testing with a non-default device, i found the speaker-test command in my shell history.
How should i do the test?

Pi sound card was not deactivated, maybe i need them later (if i find a small speaker not needing extra power).

Btw, i have squeezelite on the host, not in a docker.
I think ifollowed http://www.gerrelt.nl/RaspberryPi/wordpress/tutorial-installing-squeezelite-player-on-raspbian/#Starting_Squeezelite_on_startup
SL_SOUNDCARD is commented out in config and there seems no changed value, most comments. Squeezlite uses the seeed card.

$ squeezelite -l
Output devices:
  null                           - Discard all samples (playback) or generate zero samples (capture)
  jack                           - JACK Audio Connection Kit
  pulse                          - PulseAudio Sound Server
  playback                      
  capture                       
  dmixed                        
  array                         
  default                       
  output                        
  sysdefault:CARD=Headphones     - bcm2835 Headphones, bcm2835 Headphones - Default Audio Device
  dmix:CARD=Headphones,DEV=0     - bcm2835 Headphones, bcm2835 Headphones - Direct sample mixing device
  dsnoop:CARD=Headphones,DEV=0   - bcm2835 Headphones, bcm2835 Headphones - Direct sample snooping device
  hw:CARD=Headphones,DEV=0       - bcm2835 Headphones, bcm2835 Headphones - Direct hardware device without any conversions
  plughw:CARD=Headphones,DEV=0   - bcm2835 Headphones, bcm2835 Headphones - Hardware device with all software conversions
  usbstream:CARD=Headphones      - bcm2835 Headphones - USB Stream Output
  sysdefault:CARD=seeed2micvoicec - seeed-2mic-voicecard, bcm2835-i2s-wm8960-hifi wm8960-hifi-0 - Default Audio Device
  dmix:CARD=seeed2micvoicec,DEV=0 - seeed-2mic-voicecard, bcm2835-i2s-wm8960-hifi wm8960-hifi-0 - Direct sample mixing device
  dsnoop:CARD=seeed2micvoicec,DEV=0 - seeed-2mic-voicecard, bcm2835-i2s-wm8960-hifi wm8960-hifi-0 - Direct sample snooping device
  hw:CARD=seeed2micvoicec,DEV=0  - seeed-2mic-voicecard, bcm2835-i2s-wm8960-hifi wm8960-hifi-0 - Direct hardware device without any conversions
  plughw:CARD=seeed2micvoicec,DEV=0 - seeed-2mic-voicecard, bcm2835-i2s-wm8960-hifi wm8960-hifi-0 - Hardware device with all software conversions
  usbstream:CARD=seeed2micvoicec - seeed-2mic-voicecard - USB Stream Output

Dunno as never use squeezelite apt-get install squeezelite really but just setting it up now which I have but didn’t read any setup lols, I never read the instructions!

I just installed squeezelite and then went off at a tangent as it was failing but that was because asound2-plugins was not installed but presumed everything else 1st.
I haven’t installed rhasspy yet as think my OC Pi02W was dying as also to make things worse kept crashing with kernel messages so set to default speed but it seemed to be the network and confused

So with LMS on my PC I install squeezelite and do nothing more
Play some music in the web control and it plays
Play speaker-test or aplay file_example_WAV_2MG.wav Sample .wav download | File Examples Download

Rhasspy just installed

docker exec -it rhasspy /bin/bash

speaker-test and again its all mixed with squeezelite playing joy division merilly

your mum is fat speaks away via TTS or anything you can think of, whilst still playing joydivision

No problem so maybe that tutorial as I just installed.

/etc/asound.conf

 # The IPC key of dmix or dsnoop plugin must be unique
# If 555555 or 666666 is used by other processes, use another one


# use samplerate to resample as speexdsp resample is bad
defaults.pcm.rate_converter "samplerate"

pcm.!default {
    type asym
    playback.pcm "playback"
    capture.pcm "capture"
}

pcm.playback {
    type plug
    slave.pcm "dmixed"
}

pcm.capture {
    type plug
    slave.pcm "array"
}

pcm.dmixed {
    type dmix
    slave.pcm "hw:Device"
    ipc_key 555555
    ipc_perm 0666
}

pcm.array {
    type dsnoop
    slave {
        pcm "hw:Device"
        channels 2
    }
    ipc_key 666666
    ipc_perm 0666
}

Its a plugable usb device but has spaces in its naming so you just get the last word from /proc/asound/cards

I am thinking my pref for snapcast is going to stay snapcast, I am presuming groups and stuff can be added and setup, but all seems an after thought.
LMS is a media server whilst snapcast is network virtual audio cable and doesn’t have a media player that is from the go organised into rooms/zones with corresponding inputs for near anything and you use whatever media player or in/out you wish, whilst LMS is very concentric to the LMS media server and isn’t as simple for multiroom design purity that snapcast has.
Pretty sure you can add plugins to do the same with LMS but snapcast is setup from the get go and likely offers more in/out methods and has audiophile quality network latency compensation.

I think i need to do the test, but dont know how.
Can you help me with this? I posted the squeezebox devices so you can see my hardware.

Beside LMS i dont know other music systems. I tried volumio which does not work out of the box and then found LMS, which worked fine + i found a used squeezebox radio. I am in no way audiophile, but i like to have the same music in 2 rooms.

Squeezelite is OK for that the big difference comes if you plan to have active speakers or not as the latency tolerance to the speed of sound works out about 3 meters so really your talking a single multi-channel amp in each room than an active wireless speaker setup.
Snapcat is pure audio delivery so its setup to accept all audio whilst LMS is very focussed on its media player with plugins and not even worked out how you play music in each room, whilst snapcast feathers the latency adjust in a similar way to AGC (feathers in/out samples as agc does amplitude) and works at x10 smaller tolerance size.
Also its not just Snapcast it what other such as Hifiberry add such as GitHub - hifiberry/snapcastmpris: MPRIS interface to snapcast but squeezelite does run on esp32 whilst the snapcast client doesn’t look totally complete but if on Arm…

Start with a fresh image install your 2mic driver? Add the changes, install squeezelite and don’t pick or set an audio output leave all to default.
Reboot after installing squeezelite as can not remember if it runs auto on install.
speaker-test which is part of the alsa install run without -D so it uses default is a good a test as any.

Both should play at the same time and mix, if so then run the rhasspy docker install again keeping all to default.
docker exec -it rhasspy /bin/bash and also run speaker-test there and if that mixes then you are 100% but what you have done with your system now, who knows?

I have the same hat you do; which is what I did all my development on this with:

I also just setup squeezelite and alice_satellite to work together; I am working on adding support to control squeezelite from alice_satellite so that it will pause and resume any audio that is playing.

I am using the following in /etc/asound.conf

pcm.dmixed {
    type dmix
    slave {
	pcm "hw:seeed2micvoicec"
	rate 44100
    }
    ipc_key 555555 
    ipc_perm 0666
}

/etc/default/squeezelite

SL_SOUNDCARD="dmixed"

I also set alice_satellite to use dmixed and they both work simultaneously.

I can not just reinstall my raspi, i have some sensors served from there to my HA. I do not want them to become mixed up…

Yeah just going to have to let you sort it out as it works fine no problem, but somewhere in your setup you have something blocking it.
All you need is a single app to not access the default and correct dmixed pcm and it will block all else and what, only you can tell.

Found the problem :flushed:

In rhasspy Audio Playing device need to be empty/Default Device, not sysdefault:CARD=seeed2micvoicec

Now it works as expected.

Thank you very much!!!

1 Like

gggrrrrrrrrrrrrrr
after restarting the rhasspy pi i still can play both sources together, BUT my radio streamed from LMS sounds like very very slow motion :frowning: while the speech and sounds from rhasspy are ok.

I added the line rate 44100 and restartet with no change.

I have no idea where to look…

The setup you had will autoconvert so look at LMS and again it just needs to be setup with default.
When I tried the LMS install I used that /etc/asound.conf and just installed with no config.

What I would do is get another sdcard so you don’t break or wipe your current install and just install lms add the asound.conf and get it working. Add rhasspy docker get that working so you get to that safe ground of knowing that should work.
Then go back to the original with that working knowledge and see if you can spot what went wrong.

I found one not commented line in the config, after commenting it out it now works as expected :smiling_face_with_three_hearts: :hugs: :blush:

1 Like