<commit_before>/*
 * Copyright 1999-2002 Carnegie Mellon University.  
 * Portions Copyright 2002 Sun Microsystems, Inc.  
 * Portions Copyright 2002 Mitsubishi Electronic Research Laboratories.
 * All Rights Reserved.  Use is subject to license terms.
 * 
 * See the file "license.terms" for information on usage and
 * redistribution of this file, and for a DISCLAIMER OF ALL 
 * WARRANTIES.
 *
 */

package tests.live;

import edu.cmu.sphinx.decoder.Decoder;

import edu.cmu.sphinx.frontend.BatchCMN;
import edu.cmu.sphinx.frontend.Cepstrum;
import edu.cmu.sphinx.frontend.CepstrumSource;
import edu.cmu.sphinx.frontend.FrontEnd;
import edu.cmu.sphinx.frontend.LiveCMN;
import edu.cmu.sphinx.frontend.Microphone;
import edu.cmu.sphinx.frontend.NonSpeechFilter;
import edu.cmu.sphinx.frontend.Signal;

import edu.cmu.sphinx.util.SphinxProperties;
import edu.cmu.sphinx.result.Result;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import javax.sound.sampled.LineUnavailableException;

import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

import tests.frontend.CepstraPanel;
import tests.frontend.CepstrumMonitor;


/**
 * A live-mode Decoder. A LiveDecoder might contain a transcript file
 * that specifies a list of words to test.
 */
public class LiveDecoder extends Decoder {

    private final Live live;
    private Microphone microphone;
    private String testFile;
    private List referenceList;
    private ListIterator iterator;


    /**
     * Constructs a live mode Decoder.
     *
     * @param context the context of this LiveDecoder
     * @param microphone the Microphone used by this LiveDecoder
     */
    public LiveDecoder(String context, Live live) throws
    IOException, LineUnavailableException {
        super(context);
        this.live = live;
        referenceList = new LinkedList();
    }


    /**
     * Initializes this LiveDecoder.
     */
    public void initialize(Microphone microphone) throws IOException {
        if (!isInitialized()) {
            this.microphone = microphone;
            super.initialize(microphone);
            if (hasEnergyEndpointer()) {
                insertEnergyEndpointViewer();
            }
        }
    }


    /**
     * Inserts an EnergyEndpoint viewer, called CepstraGroupProducer.
     * This is a FrontEnd processor that is positioned after the
     * EnergyEndpointer, and before the NonSpeechFilter. It "watches" the
     * endpointed Cepstra coming out of the EnergyEndpointer, and
     * plots the speech energy levels and speech endpoints.
     * It is so called because this processor groups the watched
     * Cepstra together to form a CepstraGroup, and feeds the CepstraGroup
     * to the CepstraPanel of the LiveFrame for plotting. 
     */
    private void insertEnergyEndpointViewer() {
        FrontEnd frontend = getRecognizer().getFrontEnd();

        CepstrumSource predecessor = (CepstrumSource) frontend.getProcessor
            ("EnergyEndpointer");

        // create the viewer
        CepstrumSource monitor = new CepstrumMonitor
            ("CepstrumMonitor", getContext(), predecessor) {

            // Implements the abstract cepstrumMonitor()
            // of CepstrumMonitor. Here, it updates the 
            // CepstraPanel of the LiveFrame with the cepstrum.
            public void cepstrumMonitored(Cepstrum cepstrum) {<commit_msg>The LiveDecoder uses the FrontEnd interface and SimpleFrontEnd class.<commit_after>/*
 * Copyright 1999-2002 Carnegie Mellon University.  
 * Portions Copyright 2002 Sun Microsystems, Inc.  
 * Portions Copyright 2002 Mitsubishi Electronic Research Laboratories.
 * All Rights Reserved.  Use is subject to license terms.
 * 
 * See the file "license.terms" for information on usage and
 * redistribution of this file, and for a DISCLAIMER OF ALL 
 * WARRANTIES.
 *
 */

package tests.live;

import edu.cmu.sphinx.decoder.Decoder;

import edu.cmu.sphinx.frontend.BatchCMN;
import edu.cmu.sphinx.frontend.Cepstrum;
import edu.cmu.sphinx.frontend.CepstrumSource;
import edu.cmu.sphinx.frontend.FrontEnd;
import edu.cmu.sphinx.frontend.LiveCMN;
import edu.cmu.sphinx.frontend.Microphone;
import edu.cmu.sphinx.frontend.NonSpeechFilter;
import edu.cmu.sphinx.frontend.Signal;
import edu.cmu.sphinx.frontend.SimpleFrontEnd;

import edu.cmu.sphinx.util.SphinxProperties;
import edu.cmu.sphinx.result.Result;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import javax.sound.sampled.LineUnavailableException;

import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

import tests.frontend.CepstraPanel;
import tests.frontend.CepstrumMonitor;


/**
 * A live-mode Decoder. A LiveDecoder might contain a transcript file
 * that specifies a list of words to test.
 */
public class LiveDecoder extends Decoder {

    private final Live live;
    private Microphone microphone;
    private String testFile;
    private List referenceList;
    private ListIterator iterator;


    /**
     * Constructs a live mode Decoder.
     *
     * @param context the context of this LiveDecoder
     * @param microphone the Microphone used by this LiveDecoder
     */
    public LiveDecoder(String context, Live live) throws
    IOException, LineUnavailableException {
        super(context);
        this.live = live;
        referenceList = new LinkedList();
    }


    /**
     * Initializes this LiveDecoder.
     */
    public void initialize(Microphone microphone) throws IOException {
        if (!isInitialized()) {
            this.microphone = microphone;
            super.initialize(microphone);
            if (hasEnergyEndpointer()) {
                insertEnergyEndpointViewer();
            }
        }
    }


    /**
     * Inserts an EnergyEndpoint viewer, called CepstraGroupProducer.
     * This is a FrontEnd processor that is positioned after the
     * EnergyEndpointer, and before the NonSpeechFilter. It "watches" the
     * endpointed Cepstra coming out of the EnergyEndpointer, and
     * plots the speech energy levels and speech endpoints.
     * It is so called because this processor groups the watched
     * Cepstra together to form a CepstraGroup, and feeds the CepstraGroup
     * to the CepstraPanel of the LiveFrame for plotting. 
     */
    private void insertEnergyEndpointViewer() {
        SimpleFrontEnd frontend = (SimpleFrontEnd) 
	    getRecognizer().getFrontEnd();

        CepstrumSource predecessor = (CepstrumSource) frontend.getProcessor
            ("EnergyEndpointer");

        // create the viewer
        CepstrumSource monitor = new CepstrumMonitor
            ("CepstrumMonitor", getContext(), predecessor) {

            // Implements the abstract cepstrumMonitor()
            // of CepstrumMonitor. Here, it updates the 
            // CepstraPanel of the LiveFrame with the cepstrum.
            public void cepstrumMonitored(Cepstrum cepstrum) {
{'fraction_non_alphanumeric': 0.07540137614678899, 'fraction_numerical': 0.0045871559633027525, 'mean_word_length': 3.1162241887905604, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3598753', 'n_tokens_mistral': 2098, 'n_tokens_neox': 1957, 'n_words': 591}