Removing zero silence, seems like Sphinx doesn't like it

See http://cmusphinx.sourceforge.net/wiki/faq#qwhy_my_accuracy_is_poor
I couldn't reproduce the original problem, but it doesn't seem to hurt, either.
This commit is contained in:
Daniel Wolf 2016-01-08 16:44:03 +01:00
parent 31cb3b195c
commit 0f33fcfbd0
1 changed files with 13 additions and 3 deletions

View File

@ -90,10 +90,20 @@ void processAudioStream(AudioStream& audioStream16kHzMono, ps_decoder_t& recogni
do {
// Read to buffer
buffer.clear();
int16_t lastSample = INT16_MIN;
while (buffer.size() < capacity) {
float sample;
if (!audioStream16kHzMono.getNextSample(sample)) break;
buffer.push_back(floatSampleToInt16(sample));
// Read sample
float floatSample;
if (!audioStream16kHzMono.getNextSample(floatSample)) break;
int16_t sample = floatSampleToInt16(floatSample);
// Remove zero silence (see http://cmusphinx.sourceforge.net/wiki/faq#qwhy_my_accuracy_is_poor)
if (sample == lastSample) {
sample += (sample < INT16_MAX) ? 1 : -1;
}
lastSample = sample;
buffer.push_back(sample);
}
// Analyze buffer