cmusphinx / pocketsphinx-android

pocketsphinx build for Android
BSD 2-Clause "Simplified" License
235 stars 130 forks source link

Decoder.GetRawData stops updating after buffer is full. #27

Closed BeanStalka closed 7 years ago

BeanStalka commented 7 years ago

I use SetRawdataSize(300000) in the decoder settings.

I am using GetRawData() when a wake phrase is detected and after OnEndOfSpeech. The idea is to get the entire utterance that contains the wake phrase.

If the buffer is full when I call GetRawData() the raw data returned does not contain the wake word phrase. In fact is seems to contain nothing at all.

I have been trying different ways to reset this buffer during OnBeginningOfSpeech, but it has not worked.

I have also been working with StartListening("searchName", timeout) override to see if I can avoid this issue.

What is the best approach to avoid this issue?

If it involves a timeout, what is the correct Timeout and RawdataSize for 16000khz sample rate?

As always any help would be greatly appreciated.

BeanStalka commented 7 years ago

UPDATE I am currently starting a timer on OnBeginningOfSpeech and stopping it OnEndOfSpeech()

I am then trying to use this timespan to get the piece of the RawData Array that Has my complete wake phrase I think the equation for this is

bytes = seconds sample rate bit depth * channels

for pocket sphinx i think that translates to

bytes = seconds 16000 16 * 1

Is this correct?

Also, I'm thinking that I will need to divide that by two to map it to the short array.

I figured I would do some trial and error, but I wanted to make sure I had the bit depth correct. Or the entire equation for that matter.

TLDR, if you were going to slice out the data for a known length of time from the end of the data supplied by the GetRawData(), how would you do it?

Thank you for your time.

nshmyrev commented 7 years ago

The correct equation is seconds * 16000 * 2. 16000 is sample rate and 2 is bytes per sample (16bits = 2 bytes).