cmusphinx / sphinx4

Pure Java speech recognition library
cmusphinx.sourceforge.net
Other
1.4k stars 586 forks source link

frontend.feature.LiveCMN does not properly handle `DataStartSignal`s #87

Open timobaumann opened 5 years ago

timobaumann commented 5 years ago

In contrast to most other processors, LiveCMN does not forget its cache of internal values when a DataStartSignal comes around. Thus, it will churn out stale data even though a new DataStartSignal would indicate that everything before it is probably irrelevant by now. In combination with endpointing (as in #82), this yields stale null objects that immediately end recognition in the decoder.

The following fixes this:

    public Data getData() throws DataProcessingException {

        Data input, output;

        // Collect initial data for estimation
        if (sum == null) {
            while (initialList.size() < initialCmnWindow) {
                input = getPredecessor().getData();
                if (input instanceof DataStartSignal)
                    initialList.clear();
                initialList.add(input);
                if (input instanceof SpeechEndSignal
                        || input instanceof DataEndSignal)
                    break;
            }
            initMeansSums();
            output = initialList.remove(0);
        } else if (!initialList.isEmpty()) {
            // Return the previously collected data
            output = initialList.remove(0);
        } else {
            // Process normal frame
            output = getPredecessor().getData();
            if (output instanceof DataStartSignal) {
                initialList.clear();
                sum = null;
                initialList.add(output);
                output = getData();
            }
        }

        normalize(output);
        return output;
    }