<commit_before>package com.kasparpeterson.globalwave

import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.speech.RecognitionListener
import android.speech.RecognizerIntent
import android.speech.SpeechRecognizer
import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.widget.TextView

/**
 * Created by kaspar on 31/01/2017.
 */
class SpeechRecognitionActivity : AppCompatActivity(), RecognitionListener {

    val TAG = SpeechRecognitionActivity::class.java.simpleName

    val LISTENING_DELAY = 2000L

    var handler: Handler? = null

    var speechRecognizer: SpeechRecognizer? = null
    var recognizerIntent: Intent? = null

    var lastText = ""

    var resultTextView: TextView? = null
    var lastTextTextView: TextView? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_speech_recognition)

        handler = Handler()

        resultTextView = findViewById(R.id.speech_recognition_result_text_view) as TextView
        lastTextTextView = findViewById(R.id.speech_recognition_last_text_text_view) as TextView

        speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this)
        speechRecognizer!!.setRecognitionListener(this)

        recognizerIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
        recognizerIntent!!.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en")
        recognizerIntent!!.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, this.packageName)
        recognizerIntent!!.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3)
        recognizerIntent!!.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH)

        startListening()
    }

    override fun onRmsChanged(rmsdB: Float) {
        Log.d(TAG, "onRmsChanged")
    }

    override fun onEndOfSpeech() {
        Log.d(TAG, "onEndOfSpeech")
    }

    override fun onReadyForSpeech(params: Bundle?) {
        Log.d(TAG, "onReadyForSpeech")
        resultTextView?.text = getString(R.string.speech_recognition_listening)
        lastTextTextView?.text = lastText
    }

    override fun onBufferReceived(buffer: ByteArray?) {
        Log.d(TAG, "onBufferReceived")
    }

    override fun onPartialResults(partialResults: Bundle?) {
        Log.d(TAG, "onPartialResults")
    }

    override fun onEvent(eventType: Int, params: Bundle?) {
        Log.d(TAG, "onEvent")
    }

    override fun onBeginningOfSpeech() {
        Log.d(TAG, "onBeginningOfSpeech")
    }

    override fun onError(error: Int) {
        val errorText = getErrorText(error)
        resultTextView?.text = errorText
        Log.e(TAG, "onError, message: " + errorText)
        startListening()
    }

    override fun onResults(results: Bundle?) {
        if (results != null) {
            val matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION)
            var text = ""
            for (match in matches) {
                text += match + "\n"
            }
            Log.e(TAG, "Result: " + text)
            resultTextView?.text = matches[0]
            lastText = matches[0]
        }
        startListening()
    }

    private fun startListening() {
        handler!!.postDelayed((Runnable {
            speechRecognizer!!.startListening(recognizerIntent)
        }), LISTENING_DELAY)
    }

}<commit_msg>Fixes service busy error<commit_after>package com.kasparpeterson.globalwave

import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.speech.RecognitionListener
import android.speech.RecognizerIntent
import android.speech.SpeechRecognizer
import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.widget.TextView

/**
 * Created by kaspar on 31/01/2017.
 */
class SpeechRecognitionActivity : AppCompatActivity(), RecognitionListener {

    val TAG = SpeechRecognitionActivity::class.java.simpleName

    val LISTENING_DELAY = 2000L

    var handler: Handler? = null

    var speechRecognizer: SpeechRecognizer? = null
    var recognizerIntent: Intent? = null

    var lastText = ""

    var resultTextView: TextView? = null
    var lastTextTextView: TextView? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_speech_recognition)

        handler = Handler()

        resultTextView = findViewById(R.id.speech_recognition_result_text_view) as TextView
        lastTextTextView = findViewById(R.id.speech_recognition_last_text_text_view) as TextView

        speechRecognizer = SpeechRecognizer.createSpeechRecognizer(this)
        speechRecognizer!!.setRecognitionListener(this)

        recognizerIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
        recognizerIntent!!.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en")
        recognizerIntent!!.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, this.packageName)
        recognizerIntent!!.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 3)
        recognizerIntent!!.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH)

        startListening()
    }

    override fun onRmsChanged(rmsdB: Float) {
        Log.d(TAG, "onRmsChanged")
    }

    override fun onEndOfSpeech() {
        Log.d(TAG, "onEndOfSpeech")
    }

    override fun onReadyForSpeech(params: Bundle?) {
        Log.d(TAG, "onReadyForSpeech")
        resultTextView?.text = getString(R.string.speech_recognition_listening)
        lastTextTextView?.text = lastText
    }

    override fun onBufferReceived(buffer: ByteArray?) {
        Log.d(TAG, "onBufferReceived")
    }

    override fun onPartialResults(partialResults: Bundle?) {
        Log.d(TAG, "onPartialResults")
    }

    override fun onEvent(eventType: Int, params: Bundle?) {
        Log.d(TAG, "onEvent")
    }

    override fun onBeginningOfSpeech() {
        Log.d(TAG, "onBeginningOfSpeech")
    }

    override fun onError(error: Int) {
        val errorText = getErrorText(error)
        resultTextView?.text = errorText
        Log.e(TAG, "onError, message: " + errorText)
        startListening()
    }

    override fun onResults(results: Bundle?) {
        if (results != null) {
            val matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION)
            var text = ""
            for (match in matches) {
                text += match + "\n"
            }
            Log.e(TAG, "Result: " + text)
            resultTextView?.text = matches[0]
            lastText = matches[0]
        }
        startListening()
    }

    private fun startListening() {
        speechRecognizer!!.cancel()
        handler!!.postDelayed((Runnable {
            speechRecognizer!!.startListening(recognizerIntent)
        }), LISTENING_DELAY)
    }

}
{'fraction_non_alphanumeric': 0.09192921881743633, 'fraction_numerical': 0.004603654150481945, 'mean_word_length': 3.1282660332541568, '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': '5713632', 'n_tokens_mistral': 2159, 'n_tokens_neox': 1988, 'n_words': 364}