Hass.io addon: make Rhasspy use custom asound.conf

Hi all!

I had an issue with my PS3Eye mic volume being too low (I’m using raspberry Pi 3B+)
On my host system I’ve amended /etc/asound.conf and it’s ok, but Rhasspy uses default config inside Hass.io addon (which is docker container)
So below is my solution:

Run
sudo docker container ls | grep rhasspy
on host system (Rhasspy addon should be started) and find Rhasspy container ID

Copy you config file into container:
sudo docker cp /etc/asound.conf 3ade54edfea0:/root/.asoundrc
here and below replace 3ade54edfea0 with your container id

With the command above we create .asoundrc which overrides default asound.conf

That’s all. You should see effect immediately
Testing:
To record wav file run:
sudo docker exec 3ade54edfea0 arecord -d 5 -r 16000 /tmp/test.wav
To play wav file:
sudo docker exec 3ade54edfea0 aplay /tmp/test.wav

Important note: every time you restart Hassio addon you need to copy the file again
I’m gong to create automation in HA, maybe you have other ideas? =)

P.S. also it’s possible to fork Rhasspy addon on github and put COPY command into
https://github.com/synesthesiam/hassio-addons/blob/master/rhasspy/Dockerfile
but I think it’s not the best way

1 Like

You can also create a custom volume to store that file outside the container. Then it won’t get overwritten if the container is refreshed. I stored it under /etc versus the root home folder, but either should work the same.

-v "$HOME/rhasspy/asound.conf:/etc/asound.conf" 
1 Like

Thanks for the reply… for docker it works, but do you know how can I pass -v parameter to Hassio addon?

Sorry I am not 100% familiar with all the ins and outs of Hassio. My assumption was since it is based on docker you could adjust the config. You might be able to use docker commands or something like portainer.

For those, who is interested in it
Method I use (until I automate it :crazy_face:)

On a host system go to
/usr/share/hassio/addons/git/75f2ff60/rhasspy/docker
and copy updated asound.conf there

Then go level up and open this file in rhasspy directory
sudo nano Dockerfile
And add there COPY command
COPY docker/asound.conf /root/.asoundrc
Save and then rebuild rhasspy addon in HA addon menu
That’s all… you can check docker container to be sure file is there
You can start/stop addon, but after rebuildor upgrade you need to do this again

3 Likes

@synesthesiam, isn’t there a better way of doing this?

I have the same problems (with the microphone’s volume being too low).

Can we make these changes persistent somehow? Or beter yet, add the config file to the UI?

1 Like

This is a tough call. Rhasspy generally does not write to directories outside of the profile or /tmp, so I’m hesitant to add something that ends up writing a file in the user’s $HOME.

For the Hass.io add-on, however, this is a different story. An add-on config option might be an easy option to add. Is anyone aware of any Hass.io controls for the microphone volume? I’d hate to end up overwriting settings accidentally.

I’ve tried to ask on HA community site, but with no luck :no_mouth:

Yes, it’s required for hass.io addon only, as in pure docker container it’s possible to use -v parameter

By the way, does anyone know how i can keep my alsamixer volume settings after a reboot of the pi?

right now after every reboot the bar of pcm sits at 40%

my asound.conf

pcm.array {
type hw
card CameraB409241
}
pcm.array_gain {
type softvol
slave {
pcm “array”
}
control {
name “Mic Gain”
count 2
card 0
}
min_dB -5.0
max_dB 40.0
resolution 80
}
pcm.cap {
type plug
slave {
pcm “array_gain”
channels 4
}
route_policy sum
}
pcm.jack {
type hw
card ALSA
}
pcm.softvol {
type softvol
slave.pcm “jack”
control {
name Master
card 0
}
}
pcm.!default {
type asym
playback.pcm “plug:softvol”
capture.pcm {
type plug
slave.pcm “cap”
}
}

@Sikk
Try to run sudo alsamixer
It helped me

This alone did not work.

so i tried

sudo alsactl store

but it failed - apparently there is a problem with alsa and the micarray of the ps3 eyecam
so i only stored the settings for audio output on card 0

sudo alsactl store 0

and this seems to work :slight_smile:

EDIT: Also found a solution for “saving” the mic gain - i just lowered the resolution down to 3 (in asound.conf)- so it can only sit on 0%, 50% and 100% - now its on 100% after reboot, just have to adjust my max_dB in the config (40 is a little bit to much :smiley:)

2 Likes

@synesthesiam, I have asked the main dev of Hass.io and he said:

Someone needs to add volume support for the alsa implementation on the supervisor and expose it to the API for a slider on the frontend

So there is nothing yet. The current way (proposed in this topic) is too complicated for most people and quite a bad UX. It would be really great if you could make this slightly simpler :smiley:

1 Like

Just added a config option to the Hass.io add-on in 2.4.17 called “asoundrc”. The contents of the settings are copied to /root/.asoundrc when the add-on starts :slight_smile:

I don’t have a working Hass.io installation to test (SD card died), so you’ll have to let me know if it works or not :confused:

1 Like

Hi @synesthesiam
Thank you for this feature! I’ve tried with this config
"asoundrc": "Test"
And it works… almost :see_no_evil:

In run.sh could you change line
cat "${asoundrc}" > /root/.asoundrc
to
echo "${asoundrc}" > /root/.asoundrc
because in case of cat created file is empty

2 Likes

Wow, can’t believe I messed that up! Thanks! A fix has been pushed.

1 Like

It works now! :partying_face:

Just a note for others
As the new parameter is "str" and not ["str"] you should escape double quotes like this \" and replace line breaks with \n to have single line

As an example, here is my config

{
  "user_dir": "/share/rhasspy/profiles",
  "profile": "en",
  "ssl": false,
  "certfile": "fullchain.pem",
  "keyfile": "privkey.pem",
  "asoundrc": "\npcm.jack {\n  type hw\n  card ALSA\n}\npcm.array {\n  type hw\n  card CameraB409241\n}\npcm.softvol {\n  type softvol\n  slave.pcm \"jack\"\n  control {\n    name Master\n    card 0\n  }\n}\npcm.cap {\n  type plug\n  slave.pcm \"array\"\n  slave.channels 4\n  ttable {\n    0.0 15.0\n    1.1 15.0\n  }\n}\npcm.!default {\n    type asym\n    playback.pcm \"plug:softvol\"\n    capture.pcm {\n      type plug\n      slave.pcm \"cap\"\n    }\n}\n"
}
1 Like

Great! Should I change it to ["str"]?

As for me, it’s not required, because you will have to amend original asound file anyway…

 "asoundrc": [
"Line 1",
"Line 2",
"Etc..."
]

So it’s not possible just to copy and paste

But if you or anyone else here think it would be better, I have no objections :nerd_face: