Android Open Source - CS160-Speech-Tutor Speech Recognizer Recorder Setup






From Project

Back to project page CS160-Speech-Tutor.

License

The source code is released under:

GNU General Public License

If you think the Android project CS160-Speech-Tutor listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.speechtutor;
//w  ww  .  j  a va  2s  .  com
import static edu.cmu.pocketsphinx.Decoder.defaultConfig;
import static edu.cmu.pocketsphinx.Decoder.fileConfig;

import java.io.File;

import edu.cmu.pocketsphinx.Config;


public class SpeechRecognizerRecorderSetup {

    static {
        System.loadLibrary("pocketsphinx_jni");
    }

    private final Config config;
    private String audioStorageDirectory = "PocketSphinxTemp";

    /**
     * Creates new speech recognizer builder with default configuration.
     */
    public static SpeechRecognizerRecorderSetup defaultSetup() {
        return new SpeechRecognizerRecorderSetup(defaultConfig());
    }

    /**
     * Creates new speech recognizer builder from configuration file.
     * Configuration file should consist of lines containing key-value pairs.
     *
     * @param configFile configuration file
     */
    public static SpeechRecognizerRecorderSetup setupFromFile(File configFile) {
        return new SpeechRecognizerRecorderSetup(fileConfig(configFile.getPath()));
    }

    private SpeechRecognizerRecorderSetup(Config config) {
        this.config = config;
    }

    public SpeechRecognizerRecorder getRecognizer() {
        return new SpeechRecognizerRecorder(config, audioStorageDirectory);
    }

    public SpeechRecognizerRecorderSetup setAcousticModel(File model) {
        return setString("-hmm", model.getPath());
    }

    public SpeechRecognizerRecorderSetup setDictionary(File dictionary) {
        return setString("-dict", dictionary.getPath());
    }

    public SpeechRecognizerRecorderSetup setSampleRate(int rate) {
        return setFloat("-samprate", rate);
    }

    public SpeechRecognizerRecorderSetup setRawLogDir(File dir) {
        return setString("-rawlogdir", dir.getPath());
    }

    public SpeechRecognizerRecorderSetup setKeywordThreshold(float threshold) {
        return setFloat("-kws_threshold", threshold);
    }

    public SpeechRecognizerRecorderSetup setBoolean(String key, boolean value) {
        config.setBoolean(key, value);
        return this;
    }

    public SpeechRecognizerRecorderSetup setInteger(String key, int value) {
        config.setInt(key, value);
        return this;
    }

    public SpeechRecognizerRecorderSetup setFloat(String key, float value) {
        config.setFloat(key, value);
        return this;
    }

    public SpeechRecognizerRecorderSetup setString(String key, String value) {
        config.setString(key, value);
        return this;
    }
    
    public SpeechRecognizerRecorderSetup setAudioStorageDirectory(String audioStorageDirectory) {
      this.audioStorageDirectory = audioStorageDirectory;
      return this;
    }
}




Java Source Code List

com.example.speechtutor.ExpandableListAdapter.java
com.example.speechtutor.Playback.java
com.example.speechtutor.Record.java
com.example.speechtutor.RecordingData.java
com.example.speechtutor.Settings.java
com.example.speechtutor.SpeechRecognizerRecorderSetup.java
com.example.speechtutor.SpeechRecognizerRecorder.java
com.example.speechtutor.Statistics.java