<commit_before>/*
 * Copyright 2011 <NAME> and <NAME>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *              http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package root.gast.speech;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognitionListener;
import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer;
import android.util.Log;

/**
 * abstract class for getting speech, handles some boiler plate code. Any
 * Activity that uses speech should extend this, or utilize the methods in
 * {@link SpeechRecognitionUtil}
 * 
 * @author gmilette
 */
public abstract class SpeechRecognizingActivity extends Activity implements
        RecognitionListener
{
    private static final String TAG = "SpeechRecognizingActivity";

    /**
     * code to identify return recognition results
     */
    public static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;

    public static final int UNKNOWN_ERROR = -1;

    private SpeechRecognizer recognizer;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        boolean recognizerIntent =
                SpeechRecognitionUtil.isSpeechAvailable(this);
        if (!recognizerIntent)
        {
            speechNotAvailable();
        }
        boolean direct = SpeechRecognizer.isRecognitionAvailable(this);
        if (!direct)
        {
            directSpeechNotAvailable();
        }
    }

    protected void checkForLanguage(final Locale language)
    {
        OnLanguageDetailsListener andThen = new OnLanguageDetailsListener()
        {
            @Override
            public void onLanguageDetailsReceived(LanguageDetailsChecker data)
            {
                // do a best match
                String languageToUse = data.matchLanguage(language);
                languageCheckResult(languageToUse);
            }
        };
        SpeechRecognitionUtil.getLanguageDetails(this, andThen);
    }

    /**
     * execute the RecognizerIntent, then call
     * {@link #receiveWhatWasHeard(List, List)} when done
     */
    public void recognize(Intent recognizerIntent)
    {
        startActivityForResult(recognizerIntent, 
                VOICE_RECOGNITION_REQUEST_CODE);
    }

    /**
     * Handle the results from the RecognizerIntent.
     */<commit_msg>updated comment<commit_after>/*
 * Copyright 2011 <NAME> and <NAME>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *              http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package root.gast.speech;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognitionListener;
import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer;
import android.util.Log;

/**
 * abstract class for getting speech, handles some boiler plate code. Any
 * Activity that uses speech should extend this, or utilize the methods in
 * {@link SpeechRecognitionUtil}
 * 
 * @author gmilette
 */
public abstract class SpeechRecognizingActivity extends Activity implements
        RecognitionListener
{
    private static final String TAG = "SpeechRecognizingActivity";

    /**
     * code to identify return recognition results
     */
    public static final int VOICE_RECOGNITION_REQUEST_CODE = 1234;

    public static final int UNKNOWN_ERROR = -1;

    private SpeechRecognizer recognizer;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        boolean recognizerIntent =
                SpeechRecognitionUtil.isSpeechAvailable(this);
        if (!recognizerIntent)
        {
            speechNotAvailable();
        }
        boolean direct = SpeechRecognizer.isRecognitionAvailable(this);
        if (!direct)
        {
            directSpeechNotAvailable();
        }
    }

    protected void checkForLanguage(final Locale language)
    {
        OnLanguageDetailsListener andThen = new OnLanguageDetailsListener()
        {
            @Override
            public void onLanguageDetailsReceived(LanguageDetailsChecker data)
            {
                // do a best match
                String languageToUse = data.matchLanguage(language);
                languageCheckResult(languageToUse);
            }
        };
        SpeechRecognitionUtil.getLanguageDetails(this, andThen);
    }

    /**
     * execute the RecognizerIntent, then call
     * {@link #receiveWhatWasHeard(List, List)} when done
     * might throw a {@link ActivityNotFoundException} if the
     * device cannot respond to the Intent
     */
    public void recognize(Intent recognizerIntent)
    {
            startActivityForResult(recognizerIntent,
                VOICE_RECOGNITION_REQUEST_CODE);
    }

    /**
     * Handle the results from the RecognizerIntent.
     */
{'fraction_non_alphanumeric': 0.07123834886817576, 'fraction_numerical': 0.004327563249001331, 'mean_word_length': 2.851923076923077, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2766608', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1464, 'n_words': 481}