Android 12 Developer Preview is here! Try it out, and give us your feedback!

Voice input

Every Wear OS device comes with a microphone, so users can use their voice to interact with the device. You can divide these into three types of interactions:

  • Record audio
  • Get free-form speech input
  • Voice actions

Record audio

Recording audio on a Wear OS device works the same way as it would on a phone. Refer to the MediaRecorder documentation to learn more about recording audio on Android. You can also look at a sample implementation in the Wear Speaker sample on Github.

Get free-form speech input

Call the system's built-in Speech Recognizer activity to get speech input from users. Use speech input to send messages or perform searches.

In your app, call startActivityForResult() using the ACTION_RECOGNIZE_SPEECH action. This starts the speech recognition activity, and you can then handle the result in onActivityResult().

The following code sample shows how to start and handle a speech recognition activity.

Kotlin

private const val SPEECH_REQUEST_CODE = 0
...
// Create an intent that can start the Speech Recognizer activity
private fun displaySpeechRecognizer() {
    val intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).apply {
        putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
    }
    // This starts the activity and populates the intent 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 fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
    if (requestCode == SPEECH_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
        val spokenText: String? =
                data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS).let { results ->
                    results[0]
                }
        // Do something with spokenText.
    }
    super.onActivityResult(requestCode, resultCode, data)
}

Java

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);
// This starts the activity and populates the intent 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);
}

Voice Actions

Voice Actions and Assistant App Actions aren't supported at this time except for Wear OS apps in China. Read more about Voice Actions support for China.