Rhasspy offline voice assistant toolkit

Maybe we could write an automation to switch to Zoidberg sounds when the wife leaves…:smiley:

1 Like

Maybe we could write an automation to switch to Zoidberg sounds when the wife leaves…:smiley:

Accompanied by the woop-woop-woop sound of Zoodberg? Definitely! :rofl: :heart_eyes:

Seriously… You just have to exchange the wav file - a restart of rhasspy is not necessary. It works quite simply - I’ve added an option that allows not only a Zoidbergfication but also a Barneyfication. The logic is as follows: Wife leaves the house, then rhasspy is provided with the appropriate wav according to the input select.

Rhasspy Side
Filesystem

  1. Active wav (error.wav, recorded.wav, wake.wav) files are in:
    /docker/Rhasspy/de/wav/
  2. Wav files with the same name (error.wav, recorded.wav, wake.wav), but folder-dependent content in corresponding subfolders:
    /docker/Rhasspy/de/wav/regular/
    /docker/Rhasspy/de/wav/zoidberg/
    /docker/Rhasspy/de/wav/barney/

Frontend - settings - point to corresponding files
${RHASSPY_PROFILE_DIR}/wav/error.wav
${RHASSPY_PROFILE_DIR}/wav/recorded.wav
${RHASSPY_PROFILE_DIR}/wav/wake.wav

Home Assistant Side
input_select.rhasspy_feedback

name: Rhasspy Feedback
options:
 - Normal
 - Zoidberg
 - Barney

shell_command

docker_master_rhasspy_feedback_regular: "ssh [email protected] 'rsync -r /docker/Rhasspy/de/wav/regular/ /docker/Rhasspy/de/wav/'"
docker_master_rhasspy_feedback_zoidberg: "ssh [email protected] 'rsync -r /docker/Rhasspy/de/wav/zoidberg/ /docker/Rhasspy/de/wav/'"
docker_master_rhasspy_feedback_barney: "ssh [email protected] 'rsync -r /docker/Rhasspy/de/wav/barney/ /docker/Rhasspy/de/wav/'"

automation

- alias: rhasspy_zoidbergfication
  initial_state: true
  trigger:
    platform: state
    entity_id: person.wife
  action:
    - service_template: >-
        {%- if states.person.wife.state == "home" -%}
          shell_command.docker_master_rhasspy_feedback_regular
        {%- else -%}
          {%- if states.input_select.rhasspy_feedback.state == "Zoidberg" -%}
            shell_command.docker_master_rhasspy_feedback_zoidberg
          {%- elif states.input_select.rhasspy_feedback.state == "Barney" -%}
            shell_command.docker_master_rhasspy_feedback_barney
          {%- else -%}
            shell_command.docker_master_rhasspy_feedback_regular
          {%- endif %}
        {%- endif %}
3 Likes

(SOLVED see below) I am attempting to get Rhasspy running on a Respeaker Core v2.0 using the docker method. It looks like it is hearing the wake word but not able to play sound. So far googling it hasn’t helped me, the host is able to run aplay/arecord and the libraries appear to be installed.

Here is the error:

[ERROR:899591] APlayAudioPlayer: on_receive
Traceback (most recent call last):
  File "/usr/share/rhasspy/rhasspy/actor.py", line 169, in on_receive
    self._state_method(message, sender)
  File "/usr/share/rhasspy/rhasspy/audio_player.py", line 67, in in_started
    self.play_file(message.wav_path)
  File "/usr/share/rhasspy/rhasspy/audio_player.py", line 90, in play_file
    subprocess.run(aplay_cmd, check=True)
  File "/usr/lib/python3.6/subprocess.py", line 438, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['aplay', '-q', '/usr/share/rhasspy/etc/wav/beep_hi.wav']' returned non-zero exit status 1.

I am also seeing these errors in the docker log on startup:

[2020-01-01 19:32:18,189] ASGI Framework Lifespan error, continuing without Lifespan support,
WARNING:quart.serving:ASGI Framework Lifespan error, continuing without Lifespan support,
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front,
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear,
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe,
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side,
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21,
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21,
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround40,
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround41,
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround50,
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround51,
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround71,
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958,
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958,
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958,
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi,
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi,
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem,
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem,
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline,
ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline,
ALSA lib pcm_dmix.c:1052:(snd_pcm_dmix_open) unable to open slave,

This is the error I get if I try to run aplay from within the container:

aplay beep_hi.wav
aplay: main:788: audio open error: No such file or directory

This however does play within the container:

aplay -Dplughw:0,1 beep_error.wav
Playing WAVE 'beep_error.wav' : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo

SOLVED with the following asound.conf file:

pcm.!default {
  type plug
  slave {
    pcm "hw:0,1"
  }
}
ctl.!default {
  type hw
  card 1
}

Added this as a volume to the docker command:

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

I need to adapt this as a Rhasspy tutorial for the docs :smiley:

1 Like

I’d be honored! :grin:
Suitable wav files can be downloaded here:
Soundboard
Soundboard #2

I recommend files from Soundboard #2 because the quality is much better and the files have a suitable length. Proposal for a selection:

wake
Zoidberg - Go on.wav

recorded
Zoidberg - Hooray.wav
Zoidberg - Aha.wav

error
Zoidberg - Whoop.wav

Hi, thanks a lot for your work on Rhasspy ! Using the official doc and the info here I managed to have a basically working setup. (I basically do everything as in the previously cited post except that I don’t use NodeRed, instead I use AppDaemon for advanced automation.)

My only problem is that the system seems not to hear the first word after the wakeword. For example, I say “Maison, allume la lumière”, which is French for “Home, turn on the light” (“Maison” is my wake word), and according to the dialogue manager Rhasspy only understands “la lumière” (“the light”).

Initially I thought it was the wakeword detection that was erratic or slow, but no, it works excellently and waiting between the wakeword and the command doesn’t change anything (“maison allume la lumière” produces the same behavior). On the other hand, adding some random speech before the command (“maison blah allume la lumière”) works (“blah” is discarded and Rhasspy gets the full command).

So I currently think the issue is with the VAD component, that it’s too slow or too aggressive. But I had a look at the code and saw that by default, webrtcvad is already set to the least aggressive setting (vad_mode = 0).

Any idea what could cause the problem or how to fix it ? I’ve tried searching for people with similar issues but those forums are quite confusing, and I don’t see anyone complaining about webrtcvad.

If my diagnosis is correct, a hack would be to start listening immediately after Snowboy detects a wake word, and only use webrtcvad to detects when to stop listening. Would it seem reasonable to you ?

Can you post your message directly on Rhasspy’s community at https://community.rhasspy.org

I too had strange issues with the « allume la lumière » intent. The ASR seems to transcribe the utterance correctly returning « allume la lumière » (OK) the intent is recognized correctly too but the raw_text in the payload is just « la lumière ».

Regarding webrtcvad… maybe using Kaldi decoder endpointing can help to avoid using it at all…

We’ll sort it out over to the Rhasspy community :wink:

2 Likes

Hi I tried everything I could find but I don’t think I can make it work the mini USB microphone .
Tried the above (.asoundrc) The test says working ( see attached) but Either I’m confused how to find if is working - tried the tab Speech with Use Rhasspy microphone nothing happens
If I use the the browser microphone - The Sentence field gets it.
So How can I use the USB Microphone? - I don’t have any other mike

I can use
Drives me nuts - Started fresh 2x the Buster + Rhasspy. 1st time was the same - I was playing with the profile.json as found here and the Microphone settings in the web GUI was broken - it only showed Default . As of now the profile looks like this

    "microphone": {
        "arecord": {
            "device": "null"
        },
        "pyaudio": {
            "device": "2"
        },
        "system": "arecord"
    }
}

Wanted to add that Using the browser microphone which works BTW- is using the USB Microphone plugged in the RPI4 from Chromium localhost:12101 - but no success with Use Rhasspy microphone on

Yes, my mistake, that’s clearly a Rhasspy question, it has nothing to do with the HA integration. Thanks.

Mmh, I was just giving that exemple but the problem seems to occur with all sentences. “éteins la lumière” has the same problème. “bonne nuit” gets shortened to just “nuit”. “quelle heure est-il” becomes “heure est-il”.

Good idea, will try, thanks !

EDIT: I tried, Kaldi is really great ! It seems it doesn’t completely solve the problem but it mitigates it a lot, and the general recognition rate is much better. On the other end, Kaldi is much slower, it takes 5-7 seconds to process a command (on a Rasberry Pi 4) whereas pocketsphinx is almost instant.

I had some similar issues initially, with the browser microphone working but neither pyaudio nor arecord. It turned out to be some permissions issue, the easiest solution for me was simply to run the Docker container with --privileged. (That’s probably a bad idea from a security point of view, there is certainly a better way to give just the right permissions to the container.)

Interesting - and how you do that? - Looks like Rhasspy is using systemd
No idea where i have to add --privileged
on
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock ?
Thx
PS
Using the .asoundrc config disabled the volume control on Buster desktop but at least is available on alsamixer

Not there - that’s the script that starts the Docker daemon (dockerd), not your container. You need to add --privileged to the command line that starts the Rhasspy container, which starts with docker run.
Personally I just used the command line from the official doc and added --privileged to the arguments.

I’m sorry - I cannot find this script - Actually I cannot find how rhasspy is autostarted - i grepped the whole Card grep -R rhasspy * | grep docker
nada

Actually why Rhasspy is auto started? - It s’d be an option to do so or not - changing the start options like this w’d be the way

Mmh, how did you start/install Rhasspy originally ? I initially started my Rhasspy by running the docker container (with docker run ...) and it is autostarted because I specifed --restart unless-stopped so Docker restarts it automatically at boot (unless I stopped it with docker stop) - I don’t know how Docker does that exactly, I’m no Docker expert.

If you are in a similar situation, you should probably stop the current container with docker stop <container id> (, delete it with docker rm), and restart a new one with docker run ... (follow the command line from the doc) and specify --privileged that time.

Ok Stopped all docker containers - BTW there were 3 synesthesiam/rhasspy-server:latest
And used the --privileged option
Rhasppy behave like a fresh install asked me to download and train
But the USB microphone - same
NOT WORKING
Browser mike with same USB mike works
I think I’ll pass… goodbye Rhasspy at least for now - way too much time wasted on it :frowning:
Even with the browser mike working only 'feedback " i get is the field sentence which display what i said and the Raw Intent JSON log - I want to hear the REPLY! - no reply whatsoever - where is it? how to enable it?
…meanwhile I installed mycroft and works amazingly well with the USB mike - but it looks that not as “open” to customization as Rhasspy - anyway I just had a glimpse of it

FYI, the first non-browser microphone I managed to make work is the GStreamer one. If you have some basic knowledge of GStreamer it is quite straightforward. The only catch is to open the corresponding UDP port in the container.

What replies ? You need to get something to generate the replies in question - Rhasspy doesn’t do that, it’s the job of whatever system handles your intents e.g. Home Assistant. Rhasspy looks for a “speech” key in the JSON returned by the intention handling backend and speaks if there is something there.

1 Like

Regarding Kaldi speed, you can try the TDNN 250 model from Paul Guyot (for french)

For now Rhasspy used the TDNN full model that weight 60MB. The 250 version performs pretty much the same and only weight 12MB. Tweaking the decode.sh script in the Rhasspy Kaldi profile folder I’m able to get ASR to return in less than a second.

@synesthesiam will probably switch to this version of the acoustic model in a future release.

See this for more info:

Hope this helps.

2 Likes

Excellent ! I will definitely try this when I have time to tweak and rebuild the docker image. Many thanks for your help.