MicroPi not running properly

This all sounds like Rhasspy is not using pulseaudio to record from. As soon as Rhasspy accesses the microphone with alsa it will become unavailable to pulseaudio and pulseaudio will act like it doesn’t exist anymore. You won’t see it in pactl list and you can’t access it with any other program as long as Rhasspy is blocking it.

I think this is the same happening in reverse kind of. Sox is recoding from the pulseaudio sound server and as soon as Rhasspy starts it tries to access the device on the alsa level killing the device for pulseaudio.

It’s gonna have to be either all pulse or non.

Ok scrap all the pulseaudio and are you willing to try something?
I forgot all about dsnoop and dmix for alsa:

Can you change your asound.conf to something like:

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

pcm.speaker {
    type plug
    slave.pcm "hw:ALSA"
}

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

This should allow you to record from the same alsa device with both sox and Rhasspy directly. No pulseaudio needed.
You can just use the default device from both Rhasspy and sox / nodered.
Also clear your asoundrc so it doesn’t interfere with the asound.conf.

I had also tested with a asound.conf as suggested in the rhasspy documentation

pcm.!default {
    type pulse
    # If defaults.namehint.showall is set to off in alsa.conf, then this is
    # necessary to make this pcm show up in the list returned by
    # snd_device_name_hint or aplay -L
    hint.description "Default Audio Device"
}
ctl.!default {
    type pulse
}

and checked if my microphone is still there with pactl list even with rhasspy running.

The result is
sox FAIL formats: can't open input 'alsa_input.usb-OmniVision_Technologies__Inc._USB_Camera-B4.09.24.1-01.multichannel-input': can not open audio device: No such entity
So what?

Ok lets forget pulseaudio!

Ok then I changed asound.conf as you said, but...

Even with a sudo pulseaudio -D --system after booting, I have
sox FAIL formats: can't open input 'alsa_input.usb-OmniVision_Technologies__Inc._USB_Camera-B4.09.24.1-01.multichannel-input': can not open audio device: No such entity

pactl list says the device is there!

Did you change the asound.conf to the dsnoop one i posted?
Than just use:
-t alsa default in the sox record node and default device in Rhasspy.
That should work hopefully.

It is recording but I can't hear anything. Of course I checked audio output for analog, as I am using a headphone.

Rhasspy is running and it works as usual.

We are close to the solution :wink:

PS: I have set to -t alsa default in sox-record, but not in Rhasspy. For this, I should check with all the settings that allow it (only audio recording and audio playing apparently, but not for the wake word...)

Have you tried an asound conf like this?

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

pcm.speaker {
    type dmix
    ipc_key 555555
    slave {
        pcm "hw:Headphones"
    }
}

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

This would create a dmix pcm for the headphones which both Rhasspy and Nodered can use. This would be the system default than.
Dmix is the output equivalent to the dsnoop input.

Same problem.
I never used dmix and dsnoop.
And I don't know what the ipc_key stand for.

NB: Checking my .asoundrc file, I see that the system insists adding lines

pcm.output {
	type hw
	card 1
}

ctl.!default {
	type hw
	card 1
}

probably because I checked Analog in the settings on the screen's top right corner

Ok no need for dmix, it’s build in by default for the headphone output.
Did you read the link I posted above? It explains it. Dmix/Dsnoop are alsa plug-ins that enable the down mix of multiple streams to one sound device.
So working for me is this asound.conf:

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

pcm.speaker {
    type plug
    slave.pcm "hw:Headphones"
}

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

I verified that this works on two pi’s. But those are both headless minimal installations as I don’t actually have any Linux machine here running a desktop. There all headless unfortunately.
I just also pushed an update to the sox nodes to github. So if you update the nodes from your nodered directory with npm update johanneskropf/node-red-contrib-sox-utils you will be able to now also choose the define manual output device option in the play node.
So to make sure something plays to the headphones you can use something like -t alsa hw:Headphones if that’s the name of the headphones in aplay -l to play directly to them or you use -t alsa speaker to use the pcm defined above in the asound.conf.

No clue as I said I run minimal headless. What is card 1 if you do aplay -l? Im sorry won’t be able to help with that much but using the manual output device input I added to the play node should work around that.

Edit and Ps:
Verify that the hw name is Headphones in aplay -l, this is my output:

pi@testipi:~/.node-red $ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones]
  Subdevices: 7/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 1: ArrayUAC10 [ReSpeaker 4 Mic Array (UAC1.0)], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

So the name to use in either the asound.conf or the manual device input will be the one straight behind card 1: or card 2: etc.

Edit 2:
Did you confirm that it actually recorded anything by using something like FileZilla to transfer the recorded file over to another computer and play it there?

You mean -t alsa array. I tried that in the node and it gave an error 'busy'. So that I stopped rhasspy and it works!

Yes I read the documentation but I miss the basic to understand most of it. It's not like the docs of Rhasspy which I can work on.

Now we have it. The solution for having sox-record and Rhasspy side by side is to have both using dsnoop. I'll work on it.

Ok I just did. further testing and the asound.conf needed some more tuning. I also read a little bit in the Rhasspy docs for you.
What should work:

  • use the following asound.conf:
defaults.pcm.rate_converter "samplerate"

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

pcm.speaker {
    type plug
    slave.pcm "hw:Headphones"
}

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

pcm.dsnooparray {
    type dsnoop
    ipc_key 666666
    slave {
        pcm "hw:CameraB409241"
        channels 2
    }
}
  • in nodered in the sox record node record using manual source input with:
-t alsa array
  • in Rhasspy use the ALSA recording option that starts a local arecord command configured like this in your profile:
"microphone": {
  "system": "arecord",
  "arecord": {
    "device": "array"
  }
}
  • This should lead Rhasspy to use an arecord command as follows as its audio input:
arecord -D array -t raw -r 16000 -f S16_LE -c 1

which I just tested. I can record with the above arecord command from the commandline while simultaneously also recording with sox in nodered from the same device.
I tested by recording/streaming continuously with the sox record node in nodered and than running arecord -D array -t raw -r 16000 -f S16_LE -c 1 | sox -t raw -L -e signed-integer -c 1 -r 16000 -b 16 - btest.wav trim 0 10 on the commandline. This is nothing more than running the same command Rhasspy would run and piping it via sox into a wav file so that I could confirm it’s working.
As this works no problem I see no reason why it shouldn’t work with Rhasspy using the same command effectively.

Johannes

Johannes, thank you for your time.
But with these settings, I have no wake word (snowboy) and no intent recognition (fsticuffs), at least for the audio part.

I have also tested again with pulse. As you can see, there are several options offered with arecord...

At this point in time, I should probably look for help in the Rhasspy forum. What do you think?

With the asound.conf as above choosing arecord and the simple just default option should work. Or you look at the section for using a custom record command. There you could use sox or arecord as above.
For the question whether snowboy uses pyaudio no matter what you are better of over at the Rhasspy forum.
You can find me on the Rhasspy forum too, same user name.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.