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

runing demo_arecord.py error on RPi #370

Open michalkravcik opened 6 years ago

michalkravcik commented 6 years ago

Hi everybody,

i would like to ask for any advice how to fix a issue with Snowboy on Raspberry pi Zero, with I2S microphone (SPH0645). Microphone works well with arecord command. So I use a demo_arecord.py, but I can't go through this errors

^Cpi@pi:~/snowboy/snowboy/examples/Python $ sudo python demo_arecord.py snowboy.umdl Listening... Press Ctrl+C to exit Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner self.run() File "/usr/lib/python2.7/threading.py", line 754, in run self.__target(*self.__args, **self.__kwargs) File "/home/pi/snowboy/snowboy/examples/Python/snowboydecoder_arecord.py", line 99, in record_proc wav = wave.open(process.stdout, 'rb') File "/usr/lib/python2.7/wave.py", line 511, in open return Wave_read(f) File "/usr/lib/python2.7/wave.py", line 164, in __init__ self.initfp(f) File "/usr/lib/python2.7/wave.py", line 129, in initfp self._file = Chunk(file, bigendian = 0) File "/usr/lib/python2.7/chunk.py", line 63, in __init__ raise EOFError EOFError

Do have anybody idea how to fix it? I already try it with my pmdl from snowboy website. Swig/Python already completed. thank you.

chenguoguo commented 6 years ago

I haven't seen this error personally. Can you try to run it without sudo?

michalkravcik commented 6 years ago

with sudo and without sudo, its still to same.

chenguoguo commented 6 years ago

are you able to run the arecord command with something like arecord -q -r 16000 -f S16_LE -t wav test.wav? It's possible that your microphone doesn't support the 16k sampling rate that we require.

michalkravcik commented 6 years ago

Hi, thank you for an answer.

arecord -q -r 16000 -f S16_LE -t wav test.wav gave me reply arecord: main:722: audio open error: no such file or directory

I use SPH0645 I2S microphone, which I default can use for record sounds with arecord -D dmic_sv -c2 -r 44100 -f S32_LE -t wav mono -v test.wav

Also 16kHz sampling works arecord -D dmic_sv -c2 -r16000 -f S32_LE -t wav mono -v test.wav S16_LE make a reply: arecord: set_params:1233: Sample format non available. \n Available formats: - S32_LE

michalkravcik commented 6 years ago

maybe it will help if you can describe if some steps needs to be done.. for example setup.py have no note in guide. It will help?

chenguoguo commented 6 years ago

There isn't really "steps" that we should follow other than http://docs.kitt.ai/snowboy/#set-up-audio.

snowboydecoder_arecord.py basically takes audio from arecord and sends it to Snowboy for detection. So as long as arecord can properly capture audio from your device, it should just work. That's why I was asking you to try out those arecord commands.

By looking at the error below

line 99, in record_proc wav = wave.open(process.stdout, 'rb') File 

it seems to me that there might be something wrong with process.stdout, which relates to the arecord command.

The original command (https://github.com/Kitt-AI/snowboy/blob/master/examples/Python/snowboydecoder_arecord.py#L95) used in snowboydecoder_arecord.py is

cmd = 'arecord -q -r %d -f S16_LE' % RECORD_RATE

The required audio format is S16_LE. I searched the error on Google, and you may be able to fix that by following (which is similar to our audio setup step in the documentation): https://stackoverflow.com/questions/36208176/arecord-set-params1233-sample-format-non-available-available-formats-s16-l

You can also try other microphones.

michalkravcik commented 6 years ago

Hi chenguoguo ,

thank you so much for tip! editing snowboydetector_arecord.py erase all errors.

Unfortunately, i can not get callback with custom model or with snowboy.umdl model. on terminal is only Listening... Press Ctrl+C to exit .

I inserted print(console output of self.recording) for checking if this part of detection is working.

in code def record_proc(self): CHUNK = 2048 RECORD_RATE = 16000 cmd = 'arecord -D dmic_sv -c2 -r %d -f S32_LE' %RECORD_RATE process = subprocess.Popen(cmd.split(' '), stdout = subprocess.PIPE, stderr = subprocess.PIPE) wav = wave.open(process.stdout, 'rb') while self.recording: print('console output of self.recording') data = wav.readframes(CHUNK) self.ring_buffer.extend(data) process.terminate() so in console/terminal I got: Listening... Press Ctrl+C to exit console output of self.recording console output of self.recording console output of self.recording console output of self.recording

but no text outputs form if interrupt_check(): logger.debug("detect voice return") return or logger.debug("detecting...") or logger.debug("detect voice break") what is in snowboydecoder_arecord.py code.

Please, can you give me any advice how to debug/check out any detection process?

Thank you.

chenguoguo commented 6 years ago

It's possible that you were sending the wrong format audio to Snowboy. How did you edit snowboydecoder_arecord.py?

Make sure you send audio with 16k sampling rate, single channel, 16bit signed integer.

michalkravcik commented 6 years ago

Hi, 16000kHz its sets, but it looks like that problem is S32_LE format. SPH0645 memes I2s microphone doesn’t support S16_LE format. Is that any possibility to use S32_LE in snowboydetector_arecor.py?

michalkravcik commented 6 years ago

in snowboy documentation is 32bit support, or did i understand it wrong? Audio format Supported audio format is WAVE (with linear PCM, 8-bits unsigned integer, 16-bits signed integer or 32-bits signed integer). The actual audio format to be used is decided by Snowboy. See SampleRate(), NumChannels() and BitsPerSample() for the required sampling rate, number of channels and bits per sample values.

chenguoguo commented 6 years ago

The C++ code supports 32 bit yes, but the Python wrapper only supports 16 bit. See here: https://github.com/Kitt-AI/snowboy/blob/master/include/snowboy-detect.h#L89

Perhaps, you can modify the code, and convert S32_LE manually to S16_LE in your code, and then send it to Snowboy.

yexinliang commented 6 years ago

Hi man, would mind tell me how did you edit snowboydetector_arecord.py?

DaleMitchell commented 5 years ago

Bump. I'm having the same issue now.

alex-randles commented 5 years ago

Hi,

I was having the same issue I fixed it by adding os.system("killall arecord") on below line 90 in snowboydecoder_arecord.py. I believe chunks coming in from a different arecord process are causing the error.

    def record_proc(self):
        os.system("killall arecord")
        CHUNK = 1024
        RECORD_RATE = 16000