Stream music or radio

There is always going to be some need for an audio-service but to be honest I am the same as @koan as have never ran snapcast or mopidy.

I am sort of curious to how this is handled in server/satelite situations as being a Rhasspy noob not sure how its handled or what future plans are.

Each satelite has a microphone and vad to stop streaming on no voice and on multiple satelites obviously makes huge savings in bandwidth.
You might have a 5:1 or 7:1 or whatever mutichannel audio is in flavour, as that also makes a wide area mic array, so that can be a lot of bandwidth to save.
So presuming there will always be an audio-service even if just input.

You might still have 2 tier recognition with an authoritative server or a satelite model.
So even though its been modularized doesn’t the need reapear because it can now be partitioned into tiers?

My head is spinning a bit because with media its likely to be streaming channels with at least a single stream channel accompanied by a room echo channel + mic channel.
If you have a satelite mode then audio duck/cork initially is processed locally and continues duck/cork until server authorisation or releases to normal.
Thats a local audio process isn’t it and Rasspy process? As thought I would ask as not sure of what snapcast or mopidity do or even have any function or awareness for the need of a room echo channel, or input.

I have had a brief look over snapcast which looks awesome and the default audio backend whilst apps like mopidity are just audio clients to push streams onto snapcast.
Can you stream channels to and from snapcast or does each client pull the whole stream and then can be assigned a channel?

Thanks, it looks like this can do the same:

When creating a program which can be used as PLAY_COMMAND and puts the output to the /tmp/pipefifo
This also might be possible with sox as play_command, the rhasspy-speakers-cli-hermes runs the play_command in a subprocess. You could use aplay for example.

Thanks for the link.

I’ve opened an issue for the make docker command which isn’t working.
Anyway I’ve installed it using make debian and it’s working so far.

So far so good. To be honest I haven’t completely understood how this plugin is working. I thought it will publish everything coming in from the play-command at the right topic. As a result I will hear the sound over the speaker which I configured inside rhasspy.

I have no clue whether it’s good what running following command is telling me or not. But there’s no sound coming from my speakers.

(.venv) pi@raspberrypi:~ $ rhasspy-speakers-cli-hermes --play-command "play /home/pi/Documents/testSong.mp3" --debug
[DEBUG:2020-04-22 14:15:20,587] rhasspyspeakers_cli_hermes: Namespace(debug=True, host='localhost', list_command=None, log_format='[%(levelname)s:%(asctime)s] %(name)s: %(message)s', password=None, play_command='play /home/pi/Documents/testSong.mp3', port=1883, site_id=None, username=None)
[DEBUG:2020-04-22 14:15:20,589] asyncio: Using selector: EpollSelector
[DEBUG:2020-04-22 14:15:20,590] rhasspyspeakers_cli_hermes: Connecting to localhost:1883
[DEBUG:2020-04-22 14:15:20,600] asyncio: Using selector: EpollSelector
[DEBUG:2020-04-22 14:15:20,601] rhasspyspeakers_cli_hermes: Connected to MQTT broker
[DEBUG:2020-04-22 14:15:20,602] rhasspyspeakers_cli_hermes: Subscribed to hermes/audioServer/+/playBytes/#
[DEBUG:2020-04-22 14:15:20,603] rhasspyspeakers_cli_hermes: Subscribed to hermes/audioServer/toggleOff
[DEBUG:2020-04-22 14:15:20,603] rhasspyspeakers_cli_hermes: Subscribed to rhasspy/audioServer/getDevices
[DEBUG:2020-04-22 14:15:20,604] rhasspyspeakers_cli_hermes: Subscribed to hermes/audioServer/toggleOn

Afterwards I thought that maybe adding a siteId would solve it with no success.

(.venv) pi@raspberrypi:~ $ rhasspy-speakers-cli-hermes --play-command "play /home/pi/Documents/testSong.mp3" --debug --siteId "default"
usage: rhasspy-speakers-cli-hermes [-h] --play-command PLAY_COMMAND
                                   [--list-command LIST_COMMAND] [--host HOST]
                                   [--port PORT] [--username USERNAME]
                                   [--password PASSWORD] [--site-id SITE_ID]
                                   [--debug] [--log-format LOG_FORMAT]
rhasspy-speakers-cli-hermes: error: unrecognized arguments: --siteId default

I’ve configured rhasspy to use the external mosquitto broker which is running on the pi:
Screenshot 2020-04-22 at 14.26.03

Any hint what I am doing wrong?

I do not know yet, but I think the play command is what is needed to play the INCOMING mqqt stream to a “device”

For instance play_command could be aplay.
I think you have a misconception about the play command, be the looks of it, is the the process which is taken input from stdin (which is actually your mqtt stream) and then OUTPUT is to something.

In your case, try:

rhasspy-speakers-cli-hermes --play-command “aplay” and publish to audio to the playBytes topic.

Hopefully that will take the incoming audio and play that with the raspbian command “aplay”
You can also add parameter to aplay to play on different speaker, but without it, it takes the system default
You can try on your Pi to play a wav with:

aplay test.wav

Obivously you should have test.wav on the Pi as a file.

Well I have no problems at all using the play command of sox to play a song over command line.

Anyway how do you mean and publish to audio? As far as I understood that’s the part I need to do myself. rhasspy-speakers-cli-hermes isn’t capable of doing this or am I wrong?

I meant publish your audio to the playBytes topic.
The playBytes topic also gets the audio from your TextToSpeech, but you can publish wave files as well.

Huge huge thanks to @romkabouter. After hours of playing around with him it’s finally working.

Now it’s possible to hear rhasspy and music from mopidy at the same time.

For everyone who wants to reach the same here is my asound.conf located in /etc/asound.conf

asound.conf:

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

pcm.ossmix {
    type dmix
    ipc_perm 0666
    ipc_key 1024 # must be unique!
    slave {
        pcm "hw:1,0"      # you cannot use a "plug" device here, darn.
        period_time 0
        period_size 1024 # must be power of 2
        buffer_size 8192  # dito. It
    }
    bindings {
        0 0 # from 0 => to 0
        1 1 # from 1 => to 1
    }
}

ctl.!default {
  type plug
}

Adjust the pcm “hw:1,0” line to your needs.

make sure the timer under /dev/snd has the correct rights. In case of errors run:

chmod a+wr /dev/snd/timer
enables every user to use aplay command

Next change the audio output inside rhasspy to mqtt/hermes and start rhasspy-speakers-cli-hermes using:

rhasspy-speakers-cli-hermes --play-command aplay

EDIT: for everyone who’s coming around this post! My setup is rhasspy 2.5 in docker on a pi4 with mopidy running as service on the pi itself.

3 Likes

Is that located inside the (Rhasspy?) docker container, or on the host?

on the host so in my case on the pi

In the end we had the following:

  • Mopidy playing music with config:

[audio]
output = alsasink device=default

  • Installed and running rhasspy-speakers-cli-hermes:
    https://github.com/rhasspy/rhasspy-speakers-cli-hermes
    The docker does not work, so build from source and run:
    rhasspy-speakers-cli-hermes --host 192.168.43.54 --username xxxx --password xxxx --site-id default --debug --play-command aplay

The host is the MQTT broker you have set Rhasspy to connect to, site-id is the id in the settings of Rhasspy

Both were working correct, Mopidy was playing through the speakers and rhasspy-speaker was also correctly playing.
The problem was mixing those, so rhasspy could play audio while mopidy was playing music.

Without modification, this would not would without modification because both need to use the audio device.
This can be done however with dmix type device

We have changed /etc/asound.conf on the Pi like Bozor indicated.
But there still was a permission error, which prevented mopdiy and the user pi (running rhasspy-speaker) to access the dmix device

We checjed the permissions with:

ls -la /dev/snd

Probably the output will be something like:

drwxr-xr-x 4 root root 180 Apr 24 14:53 .
drwxr-xr-x 16 root root 3860 Apr 24 14:54 …
drwxr-xr-x 2 root root 60 Apr 24 14:53 by-id
drwxr-xr-x 2 root root 60 Apr 24 14:53 by-path
crw-rw---- 1 root audio 116, 32 Apr 24 14:54 controlC1
crw-rw---- 1 root audio 116, 56 Apr 24 14:54 pcmC1D0c
crw-rw---- 1 root audio 116, 48 Apr 24 14:54 pcmC1D0p
crw-rw---- 1 root 18 116, 1 Apr 24 14:54 seq
crw-rw---- 1 root 18 116, 33 Apr 24 14:54 timer

The last line is the problem, the group audio does not have access to the timer.
Also, the user pi is normally not in the group audio (mopidy user is when following installation)
So, add pi to audio group with:

usermod pi -G audio

We gave permission to all users to /dev/snd/timer with:

chmod a+wr /dev/snd/timer

But I think only giving acces to the audio group would be better.

Bozo could now play music from Mopidy through the speakers and Rhasspy would also be able to play sound, mixed together!

Currently, I have taken it a step further and my output is not a speaker, but the snapcast server

2 Likes

Oh man. I’ve just rebooted today since my last session and the last step of our solution seems to be not persistent.

Any idea on how to fix this?

I had to run:

usermod pi -G audio

Afterwards everything worked again.

And a new funny fact is that docker seems to loose his permissions somehow.

I am following in here, but it seems over my head right now. I am trying to get away from my Echos. I am not getting MyCroft what I would like it to do, so I need a voice assistant that can play music (thru spotify etc…) and also communicate with HA and or NodeRed which it seems Rhasspy can do. I am worried about music streaming. Can you guys recap everything that you have done and is working well now? Thanks!!

To be honest, I’ve paused working actively on my Rhasspy atm. I plan to start again pretty soon.
Last time I had a lot of false positives with my wakeword so I thought waiting a bit more will solve the issue with a better wakeword engine coming up.

Sorry that I can’t help you atm.

Though happy to hear your progress.

Have you had a chance to look into this more? Seems like Rhasspy isnt setup to play music really.

Well I haven’t had spare time yet. Pretty busy on work ATM.
Did you have any success?

So I got it to stream music thru pulse audio and it wakes up fine actually. But the sound cracks. Alot on wifi and a little when connect with cable. Did your method with Mopidy crack?

I can’t remember any cracking during music or voice output.

The discussion above looks confusing. Is it pretty easy to try and set this up?

Thanks!
Joshua

Well it will take some time and probably some tweaks. But it’s not that hard if you have some basic Linux knowledge I would say.

Just wanted to share - this post led me down the road to success as well.
I wanted a combined system, and previously used custom handler in Rhasspy to play music.
The downside is that while playing, Rhasspy couldn’t wake… so I wanted to try and duplicate what you did here.

I have Rhasspy and Mopidy installed both in containers.
it took some learning to setup Mopidy correctly… but once I had that I was close.
I use Node-Red for automation - so I have accomplished this all by just doing automation…
Rhasspy controls Mopidy through Node-Red automation… and the wake work stops the music.

There were a few work arounds…

  1. Mopidy apparently can’t queue up from a playlist via it’s API… at least I couldn’t get it to work.
    To work around this, I pull the tracks form the playlist and then push them to the tracklist.add.

  2. Pausing Mopidy did not allow Rhasspy to use the speaker… had to stop playback.
    To fix this, I saved the current position in the song, and then seek it when I start playing again.

So far (1 day in) I am happy with what I have achieved! I’m sure I’ll find problems - but it has been an awesome adventure to replicate what I think is a complex setup from cloud type speakers. The last thing I haven’t finished is passing the single song to Mopidy… I the song name retrieval in Rhasspy already setup from previous work… just have get it passed to Mopidy.

Here is what it looks like in node red…

Cheers! and thanks for the inspiration!
DeadEnd

2 Likes