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 { do {
// Read to buffer // Read to buffer
buffer.clear(); buffer.clear();
int16_t lastSample = INT16_MIN;
while (buffer.size() < capacity) { while (buffer.size() < capacity) {
float sample; // Read sample
if (!audioStream16kHzMono.getNextSample(sample)) break; float floatSample;
buffer.push_back(floatSampleToInt16(sample)); 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 // Analyze buffer