Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ACTION_RECOGNIZE_SPEECH intent never finishes after long speech

Tags:

I started intent and wait for the result. It works pretty well on short speech but it does not give me the answer of the speech if it is too long. (nearly 1 min)

final Intent searchIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

    searchIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "tr");
    searchIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, true);
    searchIntent.putExtra(RecognizerIntent.EXTRA_ONLY_RETURN_LANGUAGE_PREFERENCE, true);

    startActivityForResult(searchIntent, VOICE_REQUEST_CODE);

Is there a way other than SpeechRecognizer to get results from ACTION_RECOGNIZE_SPEECH intent?

like image 428
Efe Budak Avatar asked Dec 13 '16 15:12

Efe Budak


2 Answers

Here's a working solution:

final Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, yourPackageHere);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 1000);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US");
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Your Prompt");
startActivityForResult(intent,REQUEST_CODE);

But before use this feature you should check if user granted the RECORD_AUDIO permission and device has ACTION_RECOGNIZE_SPEECH available.

Recognise Speech has an interesting behaviour with long speech. If you give a small number to MAX_RESULTS recognise speech screen freezes after a long speech. So you need to keep number bigger and you get a result in onActivityResult with List<String> results from recognise speech intent. You can get results with a loop and than use.

like image 136
savepopulation Avatar answered Sep 23 '22 16:09

savepopulation


Try this google text to speech intent launcher,

Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak Now");
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, REQUEST_CODE);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US");
startActivityForResult(intent,REQUEST_CODE);

Hope this helps :)

like image 21
Ritik Avatar answered Sep 24 '22 16:09

Ritik