synesthesiam / rhasspy

Rhasspy voice assistant for offline home automation
https://rhasspy.readthedocs.io
MIT License
944 stars 101 forks source link

Error arecord: main:828: audio open error: Device or resource busy #90

Closed KiboOst closed 4 years ago

KiboOst commented 4 years ago

Here is full console debug from an error I have after starting rhasspy and saying wakword for first timae. Also happend time to time. Come back to regarding around 20sec later.

DEBUG:ARecordAudioRecorder:Recording from microphone (arecord)
[2019-12-16 18:08:11,025] Error in ASGI Framework
Traceback (most recent call last):
  File "/home/pi/rhasspy/.venv/lib/python3.7/site-packages/hypercorn/asgi/wsproto.py", line 91, in handle_asgi_app
    await asgi_instance(self.asgi_receive, self.asgi_send)
  File "/home/pi/rhasspy/.venv/lib/python3.7/site-packages/quart/asgi.py", line 106, in __call__
    await _cancel_tasks(pending)
  File "/home/pi/rhasspy/.venv/lib/python3.7/site-packages/quart/asgi.py", line 189, in _cancel_tasks
    raise task.exception()
  File "/home/pi/rhasspy/.venv/lib/python3.7/site-packages/quart/asgi.py", line 157, in handle_websocket
    'code': 1000,
  File "/home/pi/rhasspy/.venv/lib/python3.7/site-packages/hypercorn/asgi/wsproto.py", line 149, in asgi_send
    await self.asend(CloseConnection(code=int(message["code"])))
  File "/home/pi/rhasspy/.venv/lib/python3.7/site-packages/hypercorn/asyncio/wsproto.py", line 93, in asend
    self.write(self.connection.send(event))
  File "/home/pi/rhasspy/.venv/lib/python3.7/site-packages/wsproto/__init__.py", line 64, in send
    data += self.connection.send(event)
  File "/home/pi/rhasspy/.venv/lib/python3.7/site-packages/wsproto/connection.py", line 101, in send
    "Connection cannot be closed in state %s" % self.state
wsproto.utilities.LocalProtocolError: Connection cannot be closed in state ConnectionState.CLOSED
ERROR:quart.serving:Error in ASGI Framework
Traceback (most recent call last):
  File "/home/pi/rhasspy/.venv/lib/python3.7/site-packages/hypercorn/asgi/wsproto.py", line 91, in handle_asgi_app
    await asgi_instance(self.asgi_receive, self.asgi_send)
  File "/home/pi/rhasspy/.venv/lib/python3.7/site-packages/quart/asgi.py", line 106, in __call__
    await _cancel_tasks(pending)
  File "/home/pi/rhasspy/.venv/lib/python3.7/site-packages/quart/asgi.py", line 189, in _cancel_tasks
    raise task.exception()
  File "/home/pi/rhasspy/.venv/lib/python3.7/site-packages/quart/asgi.py", line 157, in handle_websocket
    'code': 1000,
  File "/home/pi/rhasspy/.venv/lib/python3.7/site-packages/hypercorn/asgi/wsproto.py", line 149, in asgi_send
    await self.asend(CloseConnection(code=int(message["code"])))
  File "/home/pi/rhasspy/.venv/lib/python3.7/site-packages/hypercorn/asyncio/wsproto.py", line 93, in asend
    self.write(self.connection.send(event))
  File "/home/pi/rhasspy/.venv/lib/python3.7/site-packages/wsproto/__init__.py", line 64, in send
    data += self.connection.send(event)
  File "/home/pi/rhasspy/.venv/lib/python3.7/site-packages/wsproto/connection.py", line 101, in send
    "Connection cannot be closed in state %s" % self.state
wsproto.utilities.LocalProtocolError: Connection cannot be closed in state ConnectionState.CLOSED
arecord: main:828: audio open error: Device or resource busy

Config:

  • Raspberry Pi4 Raspbian Buster Lite
  • ReSpeaker 2Mic with seed drivers
  • Virtual env installed Settings:
  • Listen for wake word on start-up
  • Custom wake word Snowboy
  • Use webrtcvad and listen for silence
  • Do speech recognition with pocketsphinx on this device
  • Do intent recognition with OpenFST on this device
  • Use pico-tts on this device : fr-FR
  • Use arecord directly (ALSA) / Default Device
  • Use aplay directly (ALSA) / Default Device

Started : rhasspy/run-venv.sh --profile fr

synesthesiam commented 4 years ago

I was just testing a very similar set up with a Pi 3 (Buster, 2Mic Respeaker, etc) and was having success with arecord. Are you able to use arecord on the command line without error?

KiboOst commented 4 years ago
arecord -d 10 /tmp/test-mic.wav
aplay /tmp/test-mic.wav

works perfectly

synesthesiam commented 4 years ago

Hmmmm...maybe I need to get a Pi 4 to test.

KiboOst commented 4 years ago

Any idea ? I've not seen this error lately, but always got this when start/restart rhasspy and saying hotword few seconds after. If I say the hotword a minute or so after startup, no problem

DEBUG:DialogueManager:decoder started DEBUG:DialogueManager:Actors loaded DEBUG:DialogueManager:loading -> ready INFO:DialogueManager:Automatically listening for wake word DEBUG:DialogueManager:ready -> asleep DEBUG:SnowboyWakeListener:loaded -> listening DEBUG:ARecordAudioRecorder:started -> recording DEBUG:ARecordAudioRecorder:['arecord', '-q', '-r', '16000', '-f', 'S16_LE', '-c', '1', '-t', 'raw', '-D', 'sysdefault:CARD=seeed2micvoicec'] DEBUG:ARecordAudioRecorder:Recording from microphone (arecord) INFO:main:Started DEBUG:main:Starting web server at http://0.0.0.0:12101 Running on https://0.0.0.0:12101 (CTRL + C to quit) [2019-12-20 11:32:20,596] ASGI Framework Lifespan error, continuing without Lifespan support WARNING:quart.serving:ASGI Framework Lifespan error, continuing without Lifespan support DEBUG:SnowboyWakeListener:Hotword(s) detected: ['snowboy/hey_brigitte.pmdl'] [2019-12-20 11:32:35,013] 192.168.0.10:57516 GET /api/events/log 1.1 101 - 14364628 INFO:quart.serving:192.168.0.10:57516 GET /api/events/log 1.1 101 - 14364628 DEBUG:DialogueManager:Awake! DEBUG:DialogueManager:asleep -> awake DEBUG:SnowboyWakeListener:listening -> loaded DEBUG:WebrtcvadCommandListener:Will timeout in 30 second(s) DEBUG:ARecordAudioRecorder:recording -> started DEBUG:APlayAudioPlayer:['aplay', '-q', '/home/pi/rhasspy/etc/wav/beep_hi.wav'] DEBUG:WebrtcvadCommandListener:loaded -> listening DEBUG:ARecordAudioRecorder:Stopped recording from microphone (arecord) DEBUG:ARecordAudioRecorder:started -> recording DEBUG:ARecordAudioRecorder:['arecord', '-q', '-r', '16000', '-f', 'S16_LE', '-c', '1', '-t', 'raw', '-D', 'sysdefault:CARD=seeed2micvoicec'] DEBUG:ARecordAudioRecorder:Recording from microphone (arecord) arecord: main:828: audio open error: Device or resource busy

Will testing/training it's really a pain ;-)

synesthesiam commented 4 years ago

I'm getting this too occasionally with my 2mic HAT. I wonder if there's a bug in the driver?

This may be fixed in the future when splitting Rhasspy into services, since the recording service will always be on. Starting and stopping arecord too quickly may be causing the problem.

frkos commented 4 years ago

I have Pi 3b+ and ps3eye as a mic. And I see the same issue Device or resource busy

What I've found is that I see this issue when I use a wakeword... Maybe wakeword doesn't release mic properly, so Rhasspy can't start listen to a command?

If I disable the wakeword and use button "Wake" it works perfectly

Will testing/training it's really a pain ;-)

If you need just to test your Rhasspy try to use "Wake" button with disabled wakeword in settings

synesthesiam commented 4 years ago

I've pushed a (possible) fix for this. By default now, Rhasspy will not close/re-open the microphone after hearing the wake word. It will just keep recording from the microphone until Rhasspy is closed.

Let me know if this helps!

synesthesiam commented 4 years ago

Also suggested by @jthomasdewald: add to /boot/config.txt to disable Pi built-in audio:

##turn off onboard alsa interface
dtparam=audio=off