Android Recognition App for Android

I am creating an application that takes commands from the user and records it in real time. What would be the best option for me? Third party software like sphinx or should I use the built-in (Android speech recognition)?

Secondly, I want it to be recorded in real time, for example, when I speak, does it start to write?

+2


source to share


2 answers


You must use Android's built-in speech recognition. Specifically, you will need to use the SpeechRecognier API so that there is no popup dialog.

Also, don't expect SpeechRecognizer to return anything in onPartialResults () . This rarely happens.

You can try using Sphinx, but it seems other developers have a hard time getting it to work on Android. However, sphinx will be your only option if you want your application to run without an internet connection.



Below is the piece of code you need to use the SpeechRecognizer:

 public void recognizeDirectly(Intent recognizerIntent)
    {
        // SpeechRecognizer requires EXTRA_CALLING_PACKAGE, so add if it not
        // here
        if (!recognizerIntent.hasExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE))
        {
            recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
                    "com.dummy");
        }
        SpeechRecognizer recognizer = getSpeechRecognizer();
        recognizer.startListening(recognizerIntent);
    }

    @Override
    public void onResults(Bundle results)
    {
        Log.d(TAG, "full results");
        receiveResults(results);
    }

    @Override
    public void onPartialResults(Bundle partialResults)
    {
        Log.d(TAG, "partial results");
        receiveResults(partialResults);
    }

    /**
     * common method to process any results bundle from {@link SpeechRecognizer}
     */
    private void receiveResults(Bundle results)
    {
        if ((results != null)
                && results.containsKey(SpeechRecognizer.RESULTS_RECOGNITION))
        {
            List<String> heard =
                    results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
            float[] scores =
                    results.getFloatArray(SpeechRecognizer.CONFIDENCE_SCORES);
            receiveWhatWasHeard(heard, scores);
        }
    }

    @Override
    public void onError(int errorCode)
    {
        recognitionFailure(errorCode);
    }

    /**
     * stop the speech recognizer
     */
    @Override
    protected void onPause()
    {
        if (getSpeechRecognizer() != null)
        {
            getSpeechRecognizer().stopListening();
            getSpeechRecognizer().cancel();
            getSpeechRecognizer().destroy();
        }
        super.onPause();
    }

    /**
     * lazy initialize the speech recognizer
     */
    private SpeechRecognizer getSpeechRecognizer()
    {
        if (recognizer == null)
        {
            recognizer = SpeechRecognizer.createSpeechRecognizer(this);
            recognizer.setRecognitionListener(this);
        }
        return recognizer;
    }

    // other unused methods from RecognitionListener...

    @Override
    public void onReadyForSpeech(Bundle params)
    {
        Log.d(TAG, "ready for speech " + params);
    }

    @Override
    public void onEndOfSpeech()
    {
    }

      

+6


source


gregm is correct, but the main "live recording" part of the response received no response. You need to add an extra one to indicate that you are interested in returning part of the result:

Adding extra to intents for me



intent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);

      

Warning. Only the new material, as well as the previous one, is partially not returned. So you need to do the diff check yourself ...

+4


source







All Articles