<commit_before>package edu.cmu.pocketsphinx.demo;

import android.app.Activity;

import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder;

import android.os.AsyncTask;
import android.os.Bundle;

import android.view.View;

import android.widget.TextView;
import android.widget.ToggleButton;

import edu.cmu.pocketsphinx.Config;
import edu.cmu.pocketsphinx.Decoder;
import edu.cmu.pocketsphinx.Hypothesis;

import static edu.cmu.pocketsphinx.sphinxbase.setLogFile;


public class PocketSphinxAndroidDemo extends Activity {

    private class RecognitionTask
            extends AsyncTask<AudioRecord, Void, Hypothesis> {

        private final Decoder decoder;

        public RecognitionTask() {
            Config config = Decoder.defaultConfig();
            config.setString("-hmm", DATA_PATH + "hmm/hub4wsj_sc_8k");
            config.setString("-dict", DATA_PATH + "lm/hub4.5000.dic");
            config.setString("-lm", DATA_PATH + "lm/hub4.5000.DMP");
            config.setString("-rawlogdir", DATA_PATH);
            config.setFloat("-samprate", SAMPLE_RATE);
            config.setInt("-maxhmmpf", 10000);
            config.setBoolean("-backtrace", true);
            config.setBoolean("-bestpath", false);
            config.setBoolean("-remove_noise", false);
            decoder = new Decoder(config);
        }

        protected Hypothesis doInBackground(AudioRecord... recorder) {
            int nread;
            short[] buf = new short[1024];
            decoder.startUtt(null);

            while ((nread = recorder[0].read(buf, 0, buf.length)) > 0)
                decoder.processRaw(buf, nread, false, false);

            decoder.endUtt();
            return decoder.hyp();
        }

        protected void onPostExecute(Hypothesis hypothesis) {
            if (null != hypothesis)
                speechResult.append("\n" + hypothesis.getHypstr());
            else
                throw new IllegalStateException("no hypothesis");
        }
    }

    private static final String DATA_PATH =
        "/sdcard/Android/data/edu.cmu.pocketsphinx/";<commit_msg>Do not throw exception if no hypothesis<commit_after>package edu.cmu.pocketsphinx.demo;

import android.app.Activity;

import android.media.AudioFormat;
import android.media.AudioRecord;
import android.media.MediaRecorder;

import android.os.AsyncTask;
import android.os.Bundle;

import android.view.View;

import android.widget.TextView;
import android.widget.ToggleButton;

import edu.cmu.pocketsphinx.Config;
import edu.cmu.pocketsphinx.Decoder;
import edu.cmu.pocketsphinx.Hypothesis;

import static edu.cmu.pocketsphinx.sphinxbase.setLogFile;


public class PocketSphinxAndroidDemo extends Activity {

    private class RecognitionTask
            extends AsyncTask<AudioRecord, Void, Hypothesis> {

        private final Decoder decoder;

        public RecognitionTask() {
            Config config = Decoder.defaultConfig();
            config.setString("-hmm", DATA_PATH + "hmm/hub4wsj_sc_8k");
            config.setString("-dict", DATA_PATH + "lm/hub4.5000.dic");
            config.setString("-lm", DATA_PATH + "lm/hub4.5000.DMP");
            config.setString("-rawlogdir", DATA_PATH);
            config.setFloat("-samprate", SAMPLE_RATE);
            config.setInt("-maxhmmpf", 10000);
            config.setBoolean("-backtrace", true);
            config.setBoolean("-bestpath", false);
            config.setBoolean("-remove_noise", false);
            decoder = new Decoder(config);
        }

        protected Hypothesis doInBackground(AudioRecord... recorder) {
            int nread;
            short[] buf = new short[1024];
            decoder.startUtt(null);

            while ((nread = recorder[0].read(buf, 0, buf.length)) > 0)
                decoder.processRaw(buf, nread, false, false);

            decoder.endUtt();
            return decoder.hyp();
        }

        protected void onPostExecute(Hypothesis hypothesis) {
            if (null != hypothesis)
                speechResult.append("\n" + hypothesis.getHypstr());
            else
                speechResult.append("\n<no speech>");
        }
    }

    private static final String DATA_PATH =
        "/sdcard/Android/data/edu.cmu.pocketsphinx/";
{'fraction_non_alphanumeric': 0.11407199625993455, 'fraction_numerical': 0.011220196353436185, 'mean_word_length': 2.562864279766861, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, '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': '6099869', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1226, 'n_words': 239}