Lars Blumberg
Lars Blumberg

Reputation: 21381

Is SpeechRecognizer only available when Android Wear is connected to smart phone?

I'm using android.speech.SpeechRecognizer and it only seems to work if it's connected to the paired phone via Bluetooth. If I disable the phone's Bluetooth, SpeechRecognizer will stop working. This holds for being paired with both an iPhone or with an Android phone. Is an active phone connection really a constraint?

Upvotes: 2

Views: 123

Answers (1)

adjuremods
adjuremods

Reputation: 2998

Checking on the documentation, it looks like it can still be done by just using the system's SpeechRecognizer activity.

You just need to call the startActivityForResult with the ACTION_RECOGNIZE_SPEECH set, which will start the Activity and return the data thru onActivityResult

private static final int SPEECH_REQUEST_CODE = 0;

// Create an intent that can start the Speech Recognizer activity
private void displaySpeechRecognizer() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
    RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    // Start the activity, the intent will be populated with the speech text
    startActivityForResult(intent, SPEECH_REQUEST_CODE);
}

// This callback is invoked when the Speech Recognizer returns.
// This is where you process the intent and extract the speech text from the intent.
@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);
        String spokenText = results.get(0);
        // Do something with spokenText
    }
    super.onActivityResult(requestCode, resultCode, data);
}

Upvotes: 1

Related Questions