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:edu.nimbus.glass.robotvoicecontrol.VoiceControlActivity.java

@Override
protected void onResume() {
    super.onResume();

    //Get the voice results and send them to the server.
    String command = "";
    ArrayList<String> voiceResults = getIntent().getExtras().getStringArrayList(RecognizerIntent.EXTRA_RESULTS);

    for (int i = 0; i < voiceResults.size(); i++) {
        Log.d("Voice Results", voiceResults.get(i));
        command = voiceResults.get(i);/*from   w ww  .j ava  2s  .  c  om*/
    }
    Card card1 = new Card(getBaseContext());
    card1.setText("Sending Command:\n" + command);
    // Don't call this if you're using TimelineManager
    View card1View = card1.toView();
    sendMessage(command);
    setContentView(card1View);
}

From source file:MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_SPEECH && resultCode == RESULT_OK && data != null) {
        ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

        TextView textView = (TextView) findViewById(R.id.textView);
        if (result.size() > 0) {
            textView.setText("");
            for (String item : result) {
                textView.append(item + "\n");
            }//w w  w  .ja  v a 2s  .  c om
        }
    }
}

From source file:com.mobilevangelist.glass.helloworld.GetTheWeatherActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ArrayList<String> voiceResults = getIntent().getExtras().getStringArrayList(RecognizerIntent.EXTRA_RESULTS);
    if (voiceResults != null && voiceResults.size() > 0) {
        spokenText = voiceResults.get(0);
    }/*from w w  w. j  ava2  s.co m*/

    Log.i("TEST: ", spokenText);

    _speech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int status) {
            //          _speech.speak("The weather is" + mCurrent + "Fahrenheit and" + mDescription, TextToSpeech.QUEUE_FLUSH, null);
        }
    });

    setContentView(R.layout.layout_get_the_weather);
    _weatherIconImageView = (ImageView) findViewById(R.id.weatherIconImageView);
    _mainTextView = (TextView) findViewById(R.id.main_text_view);
    new FetchWeather().execute();
}

From source file:com.manueldeveloper.SpeechRecognizer.java

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Check the request code
    if (requestCode == REQUEST_CODE) {
        // Check the result code
        if (resultCode == Activity.RESULT_OK) {
            // Get the results
            this.results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            sendResults();/*from w ww.  j a v  a  2 s  .  co  m*/
        } else {
            if (this.speechRecognizerCallbackContext != null) {
                switch (resultCode) {
                case RecognizerIntent.RESULT_NETWORK_ERROR:
                    this.speechRecognizerCallbackContext.error("NETWORK_ERROR");
                    break;
                case RecognizerIntent.RESULT_CLIENT_ERROR:
                    this.speechRecognizerCallbackContext.error("CLIENT_ERROR");
                    break;
                case RecognizerIntent.RESULT_SERVER_ERROR:
                    this.speechRecognizerCallbackContext.error("SERVER_ERROR");
                    break;
                case RecognizerIntent.RESULT_AUDIO_ERROR:
                    this.speechRecognizerCallbackContext.error("AUDIO_ERROR");
                    break;
                case RecognizerIntent.RESULT_NO_MATCH:
                    this.speechRecognizerCallbackContext.error("NO_MATCH");
                    break;
                }
            }
        }
    }
}

From source file:com.manotaurgames.castro.sample.MainFragment.java

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

From source file:com.hollowsoft.smarthome.view.MainScreen.java

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {

    if (requestCode == 1337) {

        if (resultCode == RESULT_OK) {

            final TextView textView = (TextView) findViewById(R.id.text_name);

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

            final StringBuilder builder = new StringBuilder();

            for (final String string : textList) {

                builder.append(string).append("\n");
            }/*  ww w .j  a  v a  2  s. c  o m*/

            textView.setText(builder.toString());
        }
    }
}

From source file:com.perm.DoomPlay.SearchVkActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == 23 && resultCode == RESULT_OK) {
        editQuery.setText(data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS).get(0));
    }//from w  w  w .j a v  a2  s. c  o m
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:com.sunildhaker.watch.heart.ConnectActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == SPEECH_REQUEST_CODE && resultCode == RESULT_OK) {
        List<String> results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
        spokenText = results.get(0);//from w  w  w  .j av  a2  s . c om
        gotText = true;
        btn.setImageDrawable(getResources().getDrawable(R.drawable.send));
        // Do something with spokenText
        Toast.makeText(this, spokenText, Toast.LENGTH_SHORT).show();
    } else {

        Toast.makeText(this, "Didn't caught anything :(", Toast.LENGTH_SHORT).show();
    }
    super.onActivityResult(requestCode, resultCode, data);
}

From source file:com.uphyca.android.nagiharae.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
        ArrayList<String> results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

        if (results.size() > 0) {
            if (results.get(0).equals("????")) {
                sendCommandFlag = true;//from   w  w w .  j a v a2  s .com
                try {
                    mSocketClientFragment.sendCommand("NAGIHARAE");
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            Toast.makeText(this, results.get(0), Toast.LENGTH_SHORT).show();
        } else {
            Log.d(TAG, "result.size() = 0");
        }
    } else {
        Log.d(TAG, requestCode + ", " + requestCode);
    }
}

From source file:me.willowcheng.makerthings.core.OpenHABVoiceService.java

private String extractVoiceCommand(Intent data) {
    String voiceCommand = "";
    List<String> textMatchList = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
    if (!textMatchList.isEmpty()) {
        voiceCommand = textMatchList.get(0);
    }/*w ww  .  j  a v a  2s  .  c  o m*/
    Log.i(TAG, "Recognized text: " + voiceCommand);
    showToast(getString(R.string.info_voice_recognized_text, voiceCommand));
    return voiceCommand;
}