synesthesiam / rhasspy

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

Mycroft Precise Wake Word engine not working #169

Closed KarBC closed 4 years ago

KarBC commented 4 years ago

Thanks for this great project!

I installed latest (2.4.17) Rhasspy in a virtual Python environment on a Pi3 running Buster and using a Respeaker 4-Mic Array. With Snowboy as wake word engine, everything runs fine.

I tried to switch to Mycroft Precise Engine as described in the manual. However after installing all dependencies and adjusting the shell path (to find the precise-engine), the following error occurs on Rhasspy startup:

Exception in thread Thread-77: Traceback (most recent call last): File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner self.run() File "/usr/lib/python3.7/threading.py", line 865, in run self._target(*self._args, **self._kwargs) File "/home/kh/rhasspy/.venv/lib/python3.7/site-packages/precise_runner/runner.py", line 236, in _handle_predictions prob = self.engine.get_prediction(chunk) File "/home/kh/rhasspy/.venv/lib/python3.7/site-packages/precise_runner/runner.py", line 64, in get_prediction raise ValueError('Invalid chunk size: ' + str(len(chunk))) ValueError: Invalid chunk size: 0

It seems that the chunk with audio data is empty? Is there a way to fix this?

Thanks!

synesthesiam commented 4 years ago

I'll have to investigate this further. Are you using PyAudio or arecord?

KarBC commented 4 years ago

I used arecord. I just tried with PyAudio, but it produces the same error. Both, arecord and PyAudio work with snowboy. I also tried both options as root. Let me know if it helps to post the whole output of rhasspy.

Thanks!

synesthesiam commented 4 years ago

I've added a check for an empty chunk in the (upcoming) Rhasspy 2.4.18. Once that's released, please try it again. It still doesn't explain though how an empty audio chunk is getting in there...

KarBC commented 4 years ago

I researched more on the issue and the problem is an underlying bug in the precise-engine. In the 'read' function of the stream there is a timeout defined:

runner.py line 99: return_time = 1e10 if timeout is None else ( timeout + time.time() ) runner.py line 100: if not self.write_event.wait(return_time - time.time()): return b''

For whatever reason, the program enters the code after the if not ... wait() statement. Most probably there is an overflow because 1e10-time.time() is too big for the parameter of Python's Event.wait(). But I'm not a Python expert.

There is a work around for this precise-runner bug: Just exchange runner.py line 99 with: return_time = 40000 + time.time() if timeout is None else ( timeout + time.time() )

Then precise engine will work.

I will try to notify the folks at Mycroft on this problem.

patrickjane commented 4 years ago

Is there any news on this? I've fixed the line as advised, however I have nothing in the logs and no reaction at all when saying "Hey Mycroft" with this beeing my profile:

{
   "text_to_speech": {
      "system": "wavenet",
      "wavenet": {
         "voice": "de-DE-Wavenet-C"
      }
   },
   "wake": {
      "system": "precise",
      "precise": {
         "model": "hey-mycroft.pb",
         "sensitivity": 0.5,
         "trigger_level": 3,
         "chunk_size": 2048
      }
   },
   "rhasspy": {
      "listen_on_start": true
   }
}

Using the official model from here: https://github.com/MycroftAI/precise-data/tree/models

If this is another problem, should I create a new issue for this?

KarBC commented 4 years ago

Did you install Mycroft-precise and tensorflow? I installed them as described here (source install): https://github.com/MycroftAI/mycroft-precise#source-install

Make sure that precise works (e.g. precise-listen). For Precise to work within Rhasspy you need to cp the "precise-engine" binary to "/usr/local/bin". You will find the binary in ".../mycroft-precise/.venv/bin" after successful installation of mycroft-precise.

When I start Rhasspy it states that precise was loaded:

DEBUG:PreciseWakeListener:Loaded Mycroft Precise (model=/home/rhasspy/.config/rhasspy/profiles/de/model.pb, sensitivity=0.65, trigger_level=3)

I also receive some warnings from Tensorflow, but it works without problems:

DEBUG:DialogueManager:wake started /home/rhasspy/mycroft-precise/.venv/lib/python3.7/site-packages/tensorflow_core/python/framework/dtypes.py:516: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; i n a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.

It's all worth the efforts, because precise is for my opinion the best wakeword system in rhasspy, especially if you plan to use a custom wakeword!

patrickjane commented 4 years ago

Ah, thanks for the hint. It was not clear to me from the docs & the logs that I had to install mycroft precise myself (the other stuff mostly got installed by rhasspy). So I will try that.

patrickjane commented 4 years ago

Okay thanks again, indeed I was missing the precise installation. In addition, I made some indentation mistake in the above manual fix. With both issues resolved, the mycroft-precise wake word detection is now working.