Example usage for android.speech RecognizerIntent EXTRA_RESULTS

List of usage examples for android.speech RecognizerIntent EXTRA_RESULTS

Introduction

In this page you can find the example usage for android.speech RecognizerIntent EXTRA_RESULTS.

Prototype

String EXTRA_RESULTS

To view the source code for android.speech RecognizerIntent EXTRA_RESULTS.

Click Source Link

Document

An ArrayList<String> of the recognition results when performing #ACTION_RECOGNIZE_SPEECH .

Usage

From source file:com.google.developers.actions.debugger.MainActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == RECOGNIZER_REQ_CODE && resultCode == RESULT_OK) {
        ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        if (!matches.isEmpty()) {
            for (String match : matches) {
                if (match.startsWith(PLAY_PREFIX)) {
                    askCayley(match.substring(PLAY_PREFIX.length()));
                    Toast.makeText(this, match, Toast.LENGTH_LONG).show();
                    break;
                }//  w w  w .j  av  a  2 s .c  om
            }
            //Result code for various error.
        } else if (resultCode == RecognizerIntent.RESULT_AUDIO_ERROR) {
            Utils.showError(MainActivity.this, "Audio Error");
        } else if (resultCode == RecognizerIntent.RESULT_CLIENT_ERROR) {
            Utils.showError(MainActivity.this, "Client Error");
        } else if (resultCode == RecognizerIntent.RESULT_NETWORK_ERROR) {
            Utils.showError(MainActivity.this, "Network Error");
        } else if (resultCode == RecognizerIntent.RESULT_NO_MATCH) {
            Utils.showError(MainActivity.this, "No Match");
        } else if (resultCode == RecognizerIntent.RESULT_SERVER_ERROR) {
            Utils.showError(MainActivity.this, "Server Error");
        }
    }
}

From source file:com.google.cast.sample.helloworld.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
        ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        if (matches.size() > 0) {
            Log.d(TAG, matches.get(0));//  w w w .  j a  v a  2 s  .  com
            sendMessage("{\"key\": \"search\", \"value\": \"" + matches.get(0) + "\"}");
        }
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:com.corumgaz.mobilsayac.VoiceRecognizer.VoiceRecognizer.java

/**
 * Handle the results from the recognition activity.
 *//*from  ww w.j ava 2 s  .  c o m*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        // Fill the list view with the strings the recognizer thought it could have heard
        ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

        returnSpeechResults(matches);
    } else {
        // Failure - Let the caller know
        this.callbackContext.error(Integer.toString(resultCode));
    }

    super.onActivityResult(requestCode, resultCode, data);
}

From source file:com.ipo.wiimote.SpeechRecognizer.java

/**
 * Handle the results from the recognition activity.
 *///from w ww. ja va 2 s  . c om
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        // Fill the list view with the strings the recognizer thought it could have heard
        ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        float[] confidence = data.getFloatArrayExtra(RecognizerIntent.EXTRA_CONFIDENCE_SCORES);

        if (confidence != null) {
            Log.d(LOG_TAG, "confidence length " + confidence.length);
            Iterator<String> iterator = matches.iterator();
            int i = 0;
            while (iterator.hasNext()) {
                Log.d(LOG_TAG, "Match = " + iterator.next() + " confidence = " + confidence[i]);
                i++;
            }
        } else {
            Log.d(LOG_TAG, "No confidence" + "");
        }

        ReturnSpeechResults(requestCode, matches);
    } else {
        // Failure - Let the caller know
        ReturnSpeechFailure(resultCode);
    }

    super.onActivityResult(requestCode, resultCode, data);
}

From source file:com.example.SpeechRecognizer.java

/**
 * Handle the results from the recognition activity.
 *///from w ww  .ja  v a2  s.  c om
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
        // Fill the list view with the strings the recognizer thought it could have heard
        ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        ReturnSpeechResults(requestCode, matches);
    } else {
        // Failure - Let the caller know
        ReturnSpeechFailure(resultCode);
    }

    super.onActivityResult(requestCode, resultCode, data);
}

From source file:in.codehex.arrow.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
    case Config.REQUEST_SPEECH_INPUT:
        if (resultCode == RESULT_OK && data != null) {
            ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            if (result.get(0).equalsIgnoreCase("emergency")) {
                String phone = userPreferences.getString(Config.KEY_PREF_PHONE, null);
                String message = "Emergency!\n" + userPreferences.getString(Config.KEY_PREF_NAME, null)
                        + " is at http://maps.google.com/maps?q=" + lat + "," + lng;
                try {
                    SmsManager smsManager = SmsManager.getDefault();
                    smsManager.sendTextMessage(phone, null, message, null, null);
                    textToSpeech.speak("Emergency alert sent!", TextToSpeech.QUEUE_FLUSH, null, null);
                } catch (Exception e) {
                    textToSpeech.speak("Unable to send alert message!", TextToSpeech.QUEUE_FLUSH, null, null);
                }//from  ww  w. ja v a 2s. co  m
            } else if (isDestinationAvailable) {
                if (result.get(0).equalsIgnoreCase("yes")) {
                    processDirection();
                    isDestinationAvailable = false;
                } else {
                    textToSpeech.speak(getString(R.string.prompt_speech_input_initial),
                            TextToSpeech.QUEUE_FLUSH, null, Config.UTTERANCE_ID_INITIAL);
                    isDestinationAvailable = false;
                }
            } else {
                speakData(result.get(0));
            }
        }
        break;
    case Config.REQUEST_CHECK_TTS:
        if (resultCode != TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
            intent = new Intent(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
            startActivity(intent);
        }
        break;
    }
}

From source file:net.olejon.mdapp.Icd10ChapterActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == VOICE_SEARCH_REQUEST_CODE && data != null) {
        ArrayList<String> voiceSearchArrayList = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

        String voiceSearchString = voiceSearchArrayList.get(0);

        populateListView(voiceSearchString);
    }//w w w. j a  va2 s  .co  m
}

From source file:com.mobicage.rogerthat.plugins.messaging.widgets.TextLineWidget.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_CODE_VOICE) {
        if (resultCode == Activity.RESULT_OK) {
            TextView txtLbl = (TextView) findViewById(R.id.edit_text);
            ArrayList<String> text = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            String txt = txtLbl.getText().toString();
            if (!"".equals(txt)) {
                txt = txt + " ";
            }//from  ww w  . j ava 2 s.  c  o  m
            for (String str : text) {
                txt = txt + str;
            }
            txtLbl.setText(txt);
        }
    }
}

From source file:org.musicbrainz.mobile.activity.DashboardActivity.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if (requestCode == IntentIntegrator.BARCODE_REQUEST) {
        IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
        if (scanResult.getContents() != null) {
            Intent barcodeResult = new Intent(this, ReleaseActivity.class);
            barcodeResult.putExtra(Extra.BARCODE, scanResult.getContents());
            startActivity(barcodeResult);
        }/* w  w w  . j  a  v a 2 s  .c  o  m*/
    } else if (requestCode == COLLECTION_LOGIN_REQUEST && isUserLoggedIn()) {
        startActivity(IntentFactory.getCollectionList(getApplicationContext()));
    } else if (intent != null) {
        if (resultCode == Activity.RESULT_OK) {
            ArrayList<String> matches = intent.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Did you say?");
            final ListView modeList = new ListView(this);
            String[] arrayMatches = matches.toArray(new String[matches.size()]);
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.activity_voicetotexts,
                    R.id.voicetotexts_item, arrayMatches);
            modeList.setAdapter(adapter);
            builder.setView(modeList);
            final Dialog dialog = builder.create();
            modeList.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    String selectedFromList = (String) (modeList.getItemAtPosition(position));
                    dialog.dismiss();
                    if (selectedFromList != null) {
                        FragmentManager fm = getSupportFragmentManager();
                        SearchFragment sf = (SearchFragment) fm.findFragmentById(R.id.search_fragment);
                        sf.setSearchField(selectedFromList);
                    }
                }
            });

            dialog.show();
        }
    }
}

From source file:com.example.casthelloworld.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
        ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        if (matches.size() > 0) {
            Log.d(TAG, matches.get(0));/*from w w w  .j av  a 2  s.  c o  m*/
            sendMessage(matches.get(0));
        }
    }
    super.onActivityResult(requestCode, resultCode, data);
}