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?