# Configuring the Sphinx-4 Front End

The main design goal of the Sphinx-4 front end is flexibility. The front end should be modeled as a pipeline of data processors, and the entire composition of the pipeline should be configurable from the configuration file. Other design requirements include allowing multiple instances of the same data processor in the same front end, where each can be configured differently. Moreover, the possibility of multiple front ends should be allowed.

### A Simple Example

To enable all these capabilities, the following scheme is devised to specify the front end in the configuration file. Lets work with the example of a standard Mel Frequency Cepstral Coefficients (MFCC) front end, followed by an explanation:

    <component name="mfcFrontEnd" type="edu.cmu.sphinx.frontend.FrontEnd">
        <propertylist name="pipeline">
            <item>preemphasizer</item>
            <item>windower</item>
            <item>dft</item>
            <item>melFilterBank</item>
            <item>dct</item>
            <item>batchCMN</item>
    	<item>featureExtractor</item>
        </propertylist>
    </component>

    <component name="preemphasizer" type="edu.cmu.sphinx.frontend.filter.Preemphasizer"/>
    <component name="windower" type="edu.cmu.sphinx.frontend.window.RaisedCosineWindower"/>

    <component name="dft" type="edu.cmu.sphinx.frontend.transform.DiscreteFourierTransform">
        <property name="numberFftPoints" value="512"/>
    </component>

    <component name="melFilterBank" type="edu.cmu.sphinx.frontend.frequencywarp.MelFrequencyFilterBank"/>
    <component name="dct" type="edu.cmu.sphinx.frontend.transform.DiscreteCosineTransform"/>
    <component name="batchCMN" type="edu.cmu.sphinx.frontend.feature.BatchCMN"/>
    <component name="featureExtractor" type="edu.cmu.sphinx.frontend.feature.DeltasFeatureExtractor"/>

Example 1: Specifying a standard MFCC front end.

The first component specifies all the front end proceessors. "mfcFrontEnd" is the name of our MFCC front end pipeline, followed by the Java class type of the front end. It is then followed by a list of the data processors, using a `propertylist` called `pipeline`, which you will see is a property of the FrontEnd class.

The rest of the components specify each of the data processors in turn. They mainly specify the Java class type of the processor, but it can also specify the properties of the data processor. For example, in the case of the DFT data processor, the number of FFT points is specified as 512. If you look at the DiscreteFourierTransform class, you will notice that `numberFftPoints` is a property of the class.

### Multiple Instances of the Same DataProcessor

The name of a component is also useful if we have multiple instances of the same data processor class. For example, suppose that we perform Discrete Fourier Transform two times in a row, but each with a different number of FFT points, we would specify the following:

    <component name="mfcFrontEnd" type="edu.cmu.sphinx.frontend.FrontEnd">
        <propertylist name="pipeline">
            <item>preemphasizer</item>
            <item>windower</item>
            <item>dft_1</item>
            <item>dft_2</item>
            <item>melFilterBank</item>
            <item>dct</item>
            <item>batchCMN</item>
    	<item>featureExtractor</item>
        </propertylist>
    </component>

    <component name="dft_1" type="edu.cmu.sphinx.frontend.transform.DiscreteFourierTransform">
        <property name="numberFftPoints" value="128"/>
    </component>

    <component name="dft_2" type="edu.cmu.sphinx.frontend.transform.DiscreteFourierTransform">
        <property name="numberFftPoints" value="256"/>
    </component>

Example 2: Specifying a front-end pipeline with two DataProcessors of the same class, but different properties.

When the first DiscreteFourierTransform class is initialized in the 'initialize()' method, the 'name' argument will be 'dft_1'. Calling DiscreteFourierTransform.getName() on it will return 'dft_1'.

### Multiple Front Ends

Multiple front ends are simply specified as separate components:

    <component name="mfcFrontEnd" type="edu.cmu.sphinx.frontend.FrontEnd">
        <propertylist name="pipeline">
            <item>preemphasizer</item>
            <item>windower</item>
            <item>dft</item>
            <item>melFilterBank</item>
            <item>dct</item>
            <item>batchCMN</item>
    	<item>featureExtractor</item>
        </propertylist>
    </component>

    <component name="plpFrontEnd" type="edu.cmu.sphinx.frontend.FrontEnd">
        <propertylist name="pipeline">
            <item>preemphasizer</item>
            <item>windower</item>
            <item>dft</item>
            <item>plpFilterBank</item>
            <item>plpCepstrumProducer</item>
            <item>batchCMN</item>
    	<item>featureExtractor</item>
        </propertylist>
    </component>

    ... // define the components of both front ends

Example 3: Specifying multiple front-end pipelines.

That is, you specify the different pipelines, and then just specify each pipeline as you would individually.