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:org.botlibre.sdk.activity.ChatActivity.java

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

    switch (requestCode) {
    case CAPTURE_IMAGE: {

        if (resultCode == RESULT_OK) {
            //TODO Make camera intent stop app from reseting
            //Uri photoUri = data.getData();
            //Do what we like with the photo - send to bot, etc

        } else if (resultCode == RESULT_CANCELED) {
            textView.setText("Cancelled");
            submitChat();//from  w  w w. j  a  va2s  .c o  m
        }

        break;
    }
    case CAPTURE_VIDEO: {
        if (resultCode == RESULT_OK) {
            Uri videoUri = data.getData();
            //Do what we would like with the video

        } else if (resultCode == RESULT_CANCELED) {
            textView.setText("Cancelled");
            submitChat();
        }
        break;
    }
    case RESULT_SPEECH: {
        if (resultCode == RESULT_OK && data != null) {

            ArrayList<String> text = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

            textView.setText(text.get(0));
            submitChat();
        }
        break;
    }
    }
    IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
    if (scanResult != null) {
        textView.setText("lookup " + scanResult.getContents());
        submitChat();
        if (scanResult.getContents().startsWith("http")) {
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(scanResult.getContents()));
            startActivity(intent);
        }
    }
}

From source file:org.gots.ui.NewSeedActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if ((requestCode == REQUEST_LOAD_IMAGE || requestCode == REQUEST_TAKE_PHOTO) && resultCode == RESULT_OK
            && null != data) {//from   w  w w . j a  v  a2  s  .  co  m

        if (!validateSeed()) {
            Toast.makeText(getApplicationContext(), "Seed must be validable to execute this action",
                    Toast.LENGTH_LONG).show();
            return;
        }
        Uri selectedImage = data.getData();
        String[] filePathColumn = { MediaStore.Images.Media.DATA };

        Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
        cursor.moveToFirst();

        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        picturePath = cursor.getString(columnIndex);

        Bitmap bitmap = FileUtilities.decodeScaledBitmapFromSdCard(picturePath, 100, 100);

        ImageView image = (ImageView) findViewById(R.id.imageNewVariety);
        image.setImageBitmap(bitmap);

        cursor.close();

    } else if (requestCode == REQUEST_DISEASES || requestCode == REQUEST_ENVIRONMENT
            || requestCode == REQUEST_GROWTH || requestCode == REQUEST_HARVEST) {
        ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        if (matches.size() > 0)
            switch (requestCode) {
            case REQUEST_GROWTH:
                descriptionGrowth.setText(matches.get(0));
                newSeed.setDescriptionGrowth(matches.toArray().toString());
                break;
            case REQUEST_DISEASES:
                descriptionDiseases.setText(matches.get(0));
                newSeed.setDescriptionDiseases(matches.toArray().toString());
                break;
            case REQUEST_ENVIRONMENT:
                descriptionEnvironment.setText(matches.get(0));
                newSeed.setDescriptionCultivation(matches.toArray().toString());
                break;
            case REQUEST_HARVEST:
                descriptionHarvest.setText(matches.get(0));
                newSeed.setDescriptionHarvest(matches.toArray().toString());
                break;
            default:
                break;
            }

    } else {
        IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
        if (scanResult != null && scanResult.getContents() != "") {
            Log.i("Scan result", scanResult.toString());
            textViewBarCode.setText(scanResult.getContents());
            newSeed.setBareCode(textViewBarCode.getText().toString());
        } else {

        }
    }
}

From source file:com.eugene.fithealthmaingit.UI.ChooseAddMealTabsFragment.java

/**
 * Set the text based on google voice then implement search
 *//*from  w  w  w.j av  a  2  s  .com*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQ_CODE_SPEECH_INPUT) {
        if (resultCode == Activity.RESULT_OK && null != data) {
            ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            if (SEARCH_VOICE.equals("MANUAL")) {
                manualSearch.setText(result.get(0));
            }
            if (SEARCH_VOICE.equals("FAVORITE")) {
                favSearch.setText(result.get(0));
            }
        }
    }
}

From source file:br.liveo.searchliveo.SearchLiveo.java

public void resultVoice(int requestCode, int resultCode, Intent data) {
    if (requestCode == SearchLiveo.REQUEST_CODE_SPEECH_INPUT) {
        if (resultCode == Activity.RESULT_OK && null != data) {
            ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            mEdtSearch.setText(result.get(0));
        }//from   ww  w  .  ja va  2 s . c o  m
    }
}

From source file:com.android.dialer.DialtactsActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ACTIVITY_REQUEST_CODE_VOICE_SEARCH) {
        if (resultCode == RESULT_OK) {
            final ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            if (matches.size() > 0) {
                final String match = matches.get(0);
                mVoiceSearchQuery = match;
            } else {
                Log.e(TAG, "Voice search - nothing heard");
            }//from  www. j  a v a 2s  . c  o m
        } else {
            Log.e(TAG, "Voice search failed");
        }
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:br.liveo.searchliveo.SearchCardLiveo.java

public void resultVoice(int requestCode, int resultCode, Intent data) {
    if (requestCode == SearchCardLiveo.REQUEST_CODE_SPEECH_INPUT) {
        if (resultCode == Activity.RESULT_OK && null != data) {
            ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            mEdtSearch.setText(result.get(0));
        }/*from  w ww  .j a v  a 2s .c  om*/
    }
}

From source file:onion.chat.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_OK)
        return;/*from   w ww.j av  a  2  s  .  co  m*/
    if (requestCode == REQUEST_QR) {
        Bitmap bitmap = (Bitmap) data.getExtras().get("data");
        int width = bitmap.getWidth(), height = bitmap.getHeight();
        int[] pixels = new int[width * height];
        bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
        bitmap.recycle();
        RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
        BinaryBitmap bBitmap = new BinaryBitmap(new HybridBinarizer(source));
        MultiFormatReader reader = new MultiFormatReader();
        try {
            Result result = reader.decode(bBitmap);
            String str = result.getText();
            Log.i("ID", str);

            String[] tokens = str.split(" ", 3);

            if (tokens.length < 2 || !tokens[0].equals("Its Ur's")) {
                snack(getString(R.string.qr_invalid));
                return;
            }

            String id = tokens[1].toLowerCase();

            if (id.length() != 16) {
                snack(getString(R.string.qr_invalid));
                return;
            }

            if (db.hasContact(id)) {
                snack(getString(R.string.contact_already_added));
                return;
            }

            String name = "";
            if (tokens.length > 2) {
                name = tokens[2];
            }

            addContact(id, name);

            return;

        } catch (Exception ex) {
            snack(getString(R.string.qr_invalid));
            ex.printStackTrace();
        }
    } else if (requestCode == VOICE_RECOGNITION_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            ArrayList<String> textMatchList = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            String[] textTyped = new String[textMatchList.size()];
            String typeText = "";
            for (int i = 0; i < textMatchList.size(); i++) {
                textTyped[i] = textMatchList.get(i);
                typeText += textTyped[i];
            }
            if (!textMatchList.isEmpty()) {

                if (textMatchList.get(0).contains("open") || textMatchList.get(0).contains("OPEN")) {
                    String contName = "";
                    if (typeText.contains("open chat")) {
                        if (textMatchList.size() >= 2) {
                            contName = textMatchList.get(2);
                        }
                        if (contName != "") {
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("chat:" + contName),
                                    getApplicationContext(), ChatActivity.class));
                        }
                    }
                    listen();
                } else if (textMatchList.get(0).contains("password")
                        || textMatchList.get(0).contains("PASSWORD")) {
                    String password = "password";

                    if (textMatchList.size() >= 2) {

                        password = textMatchList.get(0).replaceFirst("password ", "");

                    } else if (textMatchList.size() >= 1) {

                        password = textMatchList.get(0).replaceFirst("password ", "");

                    }
                    db.setPassword(password);
                    update();
                    String toSpeak = "password changed successfully to " + password;
                    Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
                    listen();

                } else if (textMatchList.get(0).contains("change") || textMatchList.get(0).contains("CHANGE")) {
                    String name = "";
                    if (textMatchList.size() >= 2) {
                        name = textMatchList.get(2);
                    }
                    db.setName(name);
                    update();
                    snack(getString(R.string.snack_alias_changed));
                    String toSpeak = "Alias changed to " + name;
                    Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
                    t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
                    listen();
                } else if (textMatchList.get(0).contains("tell") || textMatchList.get(0).contains("tell")) {
                    String id1 = "";
                    id1 = (tor.getID());
                    Toast.makeText(getApplicationContext(), id1, Toast.LENGTH_SHORT).show();
                    //t1.speak(id1, TextToSpeech.QUEUE_FLUSH, null);
                    listen();
                } else if (textMatchList.get(0).contains("enter") || textMatchList.get(0).contains("ENTER")) {
                    String id1 = "Yet to come";
                    Toast.makeText(getApplicationContext(), id1, Toast.LENGTH_SHORT).show();
                    //t1.speak(id1, TextToSpeech.QUEUE_FLUSH, null);
                    listen();
                } else if (textMatchList.get(0).contains("HELP") || textMatchList.get(0).contains("help")) {
                    String toSpeak = "Voice Commands that can be used are 1 Open chat with contact name 2 change with alias name 3 tell";
                    Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
                    t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
                    listen();
                }

                else if (textMatchList.get(0).contains("close") || textMatchList.get(0).contains("CLOSE")) {
                    String toSpeak = "Closing Voice command";
                    Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
                    t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
                }

                else {
                    // poString
                    String toSpeak = "I Can't Understand";
                    Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
                    // t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
                    listen();
                }

            }
            //Result code for various error.
        } else if (resultCode == RecognizerIntent.RESULT_AUDIO_ERROR) {

            String toSpeak = "Audio Error";
            Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
            t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
        } else if (resultCode == RecognizerIntent.RESULT_CLIENT_ERROR) {

            String toSpeak = "Client Error";
            Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
            t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
        } else if (resultCode == RecognizerIntent.RESULT_NETWORK_ERROR) {

            String toSpeak = "Network Error";
            Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
            t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
        } else if (resultCode == RecognizerIntent.RESULT_NO_MATCH) {

            String toSpeak = "No Match";
            Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
            t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
        } else if (resultCode == RecognizerIntent.RESULT_SERVER_ERROR) {

            String toSpeak = "Server Error";
            Toast.makeText(getApplicationContext(), toSpeak, Toast.LENGTH_SHORT).show();
            t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
        }

    }

}

From source file:com.wizardsofm.deskclock.alarms.AlarmActivity.java

public void onActivityResult(int requestCode, int resultCode, Intent i) {

    super.onActivityResult(requestCode, resultCode, i);
    switch (requestCode) {
    case 100://from  ww w.j a  v  a  2  s.  co  m
        if (resultCode == RESULT_OK && i != null) {
            ArrayList<String> result = i.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

            if (result.get(0).toUpperCase().contains("SHUT UP".toUpperCase())) {
                r.stop();
                alarmStopped = true;
            } else {
            }
        }
        break;
    default:
        break;
    }

}

From source file:indrora.atomic.activity.ConversationActivity.java

/**
 * On activity result/*w  w w.  ja  v  a2 s.c  om*/
 */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != RESULT_OK) {
        // ignore other result codes
        return;
    }

    switch (requestCode) {
    case REQUEST_CODE_SPEECH:
        ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        if (matches.size() > 0) {
            ((EditText) findViewById(R.id.input)).setText(matches.get(0));
        }
        break;
    case REQUEST_CODE_JOIN:
        joinChannelBuffer = data.getExtras().getString("channel");
        break;
    case REQUEST_CODE_NICK_COMPLETION:
        insertNickCompletion((EditText) findViewById(R.id.input), data.getExtras().getString(Extra.USER));
        break;
    }
}

From source file:com.google.android.apps.paco.ExperimentExecutorCustomRendering.java

private void handleSpeechRecognitionActivityResult(int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK && null != data) {
        ArrayList<String> guesses = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        notifySpeechRecognitionListeners(guesses);
    }/*from w ww.  j  a  v a  2 s  . c  o m*/
}