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.11k stars 1k forks source link

Snowboy not working with Respeaker 2 mic hat on raspberrypi3 b #422

Open Arrow66 opened 6 years ago

Arrow66 commented 6 years ago

i've tested all demo.py files and demo_arecord.py files with snowboy.umdl but it's not detecting as i expected .it took so many tries to detect my keyword .i'm pretty sure that my recording and playback is working fine . only problem is with detection . i tried to change the following line in snowboydecoder_arecord.py cmd = 'arecord -q -D plughw:1 -r %d -f S16_LE' % RECORD_RATE

recording is working fine when i tried this command in terminal .only problem is with snowboy detection . can someone help me out

even tried to increase sensitivity . But no help

cs301cs301 commented 6 years ago

Maybe it helps to record in mono instead of stereo? add - c 1 to the command line. If that helps, then you can mix/combine the channels with alsa.

Arrow66 commented 6 years ago

@cs301cs301 thanks for the reply i did it and made sure its mono 16bit pcm .still snow-boy cant detect my wakeword.

chenguoguo commented 6 years ago

I'm not sure if it was for your particular voice, e.g., I'm not sure if it's a model problem or setting problem. If you can save the audio before you send it to Snowboy for hotword detection, I can take a look on that.

Arrow66 commented 6 years ago

finally found a way to fix issue .how can i make this code run in background ``import pyaudio import time import audioop import snowboydetect import threading detector = snowboydetect.SnowboyDetect(resource_filename = '/home /pi/Python/resources /common.res'.encode(),model_str ='/home/pi/Desktop/snowboy-master/examples/Python/resources/ models /snowboy.umdl'.encode())

class SnowboyRec(threading.Thread): def init(self,channels = 2, rate = 16000, frames_per_buffer = 1024):

        threading.Thread.__init__(self)
        self.channels = channels

        self.rate = rate
        self.frames_per_buffer = frames_per_buffer
        self._pa = pyaudio.PyAudio()
        self.status = None 

        self._stream = None

def run(self):

     detector = snowboydetect.SnowboyDetect(resource_filename = '/home/pi/Desktop/snowboy-master/examples/Python/resources/common.res'.encode(),model_str ='/home/pi/Desktop/snowboy-master/examples/Python/resources/models/snowboy.umdl'.encode())
detector.SetAudioGain(5)
detector.ApplyFrontend(False)
detector.SetSensitivity('0.5'.encode())
print('entered')

self._stream = self._pa.open(format=pyaudio.paInt16,
                                    channels=self.channels,
                                    rate=self.rate,
                                    input=True,
                                    frames_per_buffer=self.frames_per_buffer,
                                    stream_callback=self.get_callback())

print('start')
self._stream.start_stream()
return self

def get_callback(self): def callback(in_data, frame_count, time_info, status): d = audioop.tomono(in_data, 2, 0, 1) self.status = detector.RunDetection(d) if self.status == 1: print('keyword spotted') return in_data, pyaudio.paContinue return callback def _start(self): checky = SnowboyRec() checky.start()

Arrow66 commented 6 years ago

@chenguoguo its 5.15 am in india , i have not slept yet .i've been trying to fix this issue. please help

chenguoguo commented 6 years ago

Running a particular script in the background is not really a Snowboy problem... Search on Google and you will see something like: https://askubuntu.com/questions/396654/how-to-run-the-python-program-in-the-background-in-ubuntu-machine

I saw you had def init(self, channels = 2, rate = 16000, frames_per_buffer = 1024):. I don't understand how this could work. Snowboy only works with single channel.

Arrow66 commented 6 years ago

i used d = audioop.tomono(in_data, 2, 0, 1) to extract mono from right channel because of my hardware limitation .

henriz commented 6 years ago

I have the Respeaker 2 mic Pi hat running on a pi zero W, with Alexa. Installed as per the default instructions, it ran fine the first go.

What might be the case, is that you have the default soundcard still enabled. I disabled it.

In your /boot/config.txt, change about the last line from: dtparam=audio=on to: dtparam=audio=off

This will disable the onboard sound, and you'll only keep the respeaker sound devices.

My /etc/asound.conf:

# The IPC key of dmix or dsnoop plugin must be unique
# If 555555 or 666666 is used by other processes, use another one

# use samplerate to resample as speexdsp resample is bad
defaults.pcm.rate_converter "samplerate"

pcm.!default {
    type asym
    playback.pcm "playback"
    capture.pcm "capture"
}

pcm.playback {
    type plug
    slave.pcm "dmixed"
}

pcm.capture {
    type plug
    slave.pcm "array"
}

pcm.dmixed {
    type dmix
    slave.pcm "hw:seeed2micvoicec"
    ipc_key 555555
}

pcm.array {
    type dsnoop
    slave {
        pcm "hw:seeed2micvoicec"
        channels 2
    }
    ipc_key 666666
}