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?
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.
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With