No audio is recorded, wakeword works fine!

Hello everyone! I’m new to this forum and this is my first post.
I’m having problems with pyaudio and voice recognition past the wake word stage.

I am using a Raspberry Pi 4 with the latest RaspberryOS and rhasspy installed on it (no container).
The microphone is a ReSpeaker 4-mic pihat.
Wakeword software is snowboy.

No audio is being recorded and the listen-recording is empty (44 byte wav header). When I test the driver it responds with this error a couple of times, as well as an “unavailable” error.

[ERROR:2021-01-28 22:08:44,255] rhasspymicrophone_pyaudio_hermes: get_microphone_working ({device_name})
Traceback (most recent call last):
  File "/usr/lib/rhasspy/rhasspy-microphone-pyaudio-hermes/rhasspymicrophone_pyaudio_hermes/__init__.py", line 280, in get_microphone_working
    input=True,
  File "/usr/lib/rhasspy/usr/local/lib/python3.7/site-packages/pyaudio.py", line 750, in open
    stream = Stream(self, *args, **kwargs)
  File "/usr/lib/rhasspy/usr/local/lib/python3.7/site-packages/pyaudio.py", line 441, in __init__
    self._stream = pa.open(**arguments)
OSError: [Errno -9998] Invalid number of channels

I’ve researched a bit and it seems to be a problem with the audio driver. However! It responds to my hotword just fine! MQTT confirms this for me.

And if I close down rhasspy I can record myself through a custom python script:

import pyaudio
import wave
 
RESPEAKER_RATE = 16000
RESPEAKER_CHANNELS = 4
RESPEAKER_WIDTH = 2
# run getDeviceInfo.py to get index
RESPEAKER_INDEX = 2  # refer to input device id
CHUNK = 1024
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "output.wav"
 
p = pyaudio.PyAudio()
 
stream = p.open(
            rate=RESPEAKER_RATE,
            format=p.get_format_from_width(RESPEAKER_WIDTH),
            channels=RESPEAKER_CHANNELS,
            input=True,
            input_device_index=RESPEAKER_INDEX,)
 
print("* recording")
 
frames = []
 
for i in range(0, int(RESPEAKER_RATE / CHUNK * RECORD_SECONDS)):
    data = stream.read(CHUNK)
    frames.append(data)
 
print("* done recording")
 
stream.stop_stream()
stream.close()
p.terminate()
 
wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(RESPEAKER_CHANNELS)
wf.setsampwidth(p.get_sample_size(p.get_format_from_width(RESPEAKER_WIDTH)))
wf.setframerate(RESPEAKER_RATE)
wf.writeframes(b''.join(frames))
wf.close()

Do any one of you have any idea of why when rhasspy is running, nothing but the snowboy hotword can listen through it?

Have you tried using arecord instead of PyAudio?
With arecord (although running in a docker container) the Respeaker 4-mic round array works for me…
Just select the seeed4voicecard entry in the dropdown list after hitting the Refresh button.

Maybe give it a try!
BR
Martin

Have you installed the full desktop version of RaspiOS which now has Pulse audio installed as default or did you pick the headless lite version which does not?

After reviewing my problem i think I’ve got conflicting installations from a previous test environment. I’ll try a fresh installation later and get back with results!

Appearently I didn’t have a problem at all, I just had to configure the Speech to Text service, even though I just want to fetch the wav file and perform that action elsewhere. When I selected Kaldi just as a placeholder everything worked flawlessly!

Alright, it appear I had conflicting installs somehow. I’ve tried to have different versions of rhasspy on the same machine and my linux skills are far too low to understand how that should be handled.

I did a full reset on everything and cleanly installed it. Now it works flawlessly! :slight_smile:

1 Like