Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Let me cut and paste a bit to show you what code you will need. </p> <p>EDIT: you can also download a handy abstract class from <a href="https://github.com/gast-lib/gast-lib/blob/master/library/src/root/gast/speech/SpeechRecognizingAndSpeakingActivity.java" rel="noreferrer">this project</a>.</p> <p>You will need this intent (parameterize as you see fit):</p> <pre><code>public Intent getRecognizeIntent(String promptToUse, int maxResultsToReturn) { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); intent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, maxResultsToReturn); intent.putExtra(RecognizerIntent.EXTRA_PROMPT, promptToUse); return intent; } </code></pre> <p>Then you need to send your intent to the speech recognition activity like so,</p> <pre><code>public void gatherSpeech(String prompt) { Intent recognizeIntent = getRecognizeIntent(prompt); try { startActivityForResult(recognizeIntent, SpeechGatherer.VOICE_RECOGNITION_REQUEST_CODE); } catch (ActivityNotFoundException actNotFound) { Log.w(D_LOG, "did not find the speech activity, not doing it"); } } </code></pre> <p>Then you will need to have your activity handle the speech result:</p> <pre><code>protected void onActivityResult(int requestCode, int resultCode, Intent data) { Log.d("Speech", "GOT SPEECH RESULT " + resultCode + " req: " + requestCode); if (requestCode == SpeechGatherer.VOICE_RECOGNITION_REQUEST_CODE) { if (resultCode == RESULT_OK) { ArrayList&lt;String&gt; matches = data .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); Log.d(D_LOG, "matches: "); for (String match : matches) { Log.d(D_LOG, match); } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload