Kitt-AI / snowboy

Future versions with model training module will be maintained through a forked version here: https://github.com/seasalt-ai/snowboy
Other
3.07k stars 997 forks source link

Segmentation fault #180

Open max246 opened 7 years ago

max246 commented 7 years ago

I am trying to implement Snowboy with my Google Assistant sdk, but because both of them needs to access to the microphone, I cant run both of them at the same time.

The solution I came up is to "looking for my hotword" with Snowboy then use the terminate method to kill the process.

The run my Voice detection with Google and when it has finished, I start again looking for a a hotword.

The whole ecosystem works, but when the Snowboy detects the word at the second stage, it returns a fatal errror:

DEBUG:snowboy:detecting... Segmentation fault

If I dont speak, it keeps trying to detect the word but until I say the word, which it finds because the crash happens when the word has been found, the Segmentation fault is raised.

This can be reproduced easily without any google sdk by 1) start the snowboy 2) stop after 5 second 3) start again and speak

I am running the code on Raspberry Pi with latest software and version.

chenguoguo commented 7 years ago

If you can post your script to reproduce the bug on raspberry pi, we can take a look.

max246 commented 7 years ago

I made the simple steps to reproduce but here is a little wrapped I made:

` class Wakeup:

def __init__(self,model,cb):
    self._detector = snowboydecoder.HotwordDetector(model, sensitivity=0.5)
    self._interruped = False
    self._cb = cb

def run(self):
    #snowboydecoder.play_audio_file
    self._detector.start(detected_callback=self._cb,
           interrupt_check=self.interrupt_callback,
           sleep_time=0.03)
    self._detector.terminate()

def interrupt_callback(self):
    return self._interruped

def stop(self):
    self._interruped = True`

and by doing

wakeup = Wakeup("ok_house.pmdl",foundHotWord) wakeup.run()

Then make it stop and repeat the same code again.

I had this in a thread as the run is an infinite loop and was calling stop() from my wrapped to stop it.

One interesting thing is a quick fix: Because I need to restart only the audio capture, I moved the stream_in into a function and I avoid to create self.detector again, this so far worked, but for some reason if you terminate and initialise the whole class, something doesnt get unloaded.

Maybe the smarter way is to manage to share the same audio stream between snowboy and Google sdk.

max246 commented 7 years ago

I shared the Wakeup.py wrapper here: https://pastebin.com/JbxRJqnp And the main.py here: https://pastebin.com/tNzx4EiY

When it print "Speak again", try to say the word jarvis ( remember to download the file ) and it will print "Segmentation fault"

This only happens on the raspberry pi, not on desktop

chenguoguo commented 7 years ago

Thanks, I'll take a look.

chenguoguo commented 7 years ago

It was caused by threading. One of the modules we used does not support it. I did a quick fix and pushed the library to the master branch. The module is only used in the raspberry pi library, so that's why you only see this from raspberry pi. We plan to provide the module for all libraries soon, of course after fixing the threading issue.

Let me know if it works for you now.

andreaskoelsch commented 7 years ago

I am also having the issue of Segmentation Faults on a Raspberry Pi. It happens iff I call snowboydetect.SnowboyDetect(...) twice.

Would love to test your fix, but can't get the self-compiled version to work though, because I am getting issue #18

Please let me know when a precompiled version is available. Until then I will use 1.1.1

chenguoguo commented 7 years ago

We will include the fix to the pre-compiled libraries in the next release.