Android Speech to Text Example

前端 未结 1 1844
情深已故
情深已故 2020-12-13 07:44

I\'ve looked at the Android example for VoiceRecognition, but I don\'t really understand what it is suppose to do or how it works. In the manifest there isn\'t any sort of m

相关标签:
1条回答
  • 2020-12-13 08:35

    I did it like that:

    in onCreate:

    List<ResolveInfo> activities = pm.queryIntentActivities(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
    

    In the method starting the voice recognition:

    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Voice recognition Demo...");
    startActivityForResult(intent, REQUEST_CODE);
    

    onActivityResult:

    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        if (requestCode == REQUEST_CODE && resultCode == RESULT_OK)
        {
            // Populate the wordsList with the String values the recognition engine thought it heard
            ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        }
    }
    

    Hope I'm not missing anything, been a time since. Drop me a note if something doesn't work. About the text output: I'm sure you can handle that once you have a populated matches array.

    0 讨论(0)
提交回复
热议问题