Skip to content

Most visited

Recently visited

navigation

AlwaysOnHotwordDetector

public class AlwaysOnHotwordDetector
extends Object

java.lang.Object
   ↳ android.service.voice.AlwaysOnHotwordDetector


A class that lets a VoiceInteractionService implementation interact with always-on keyphrase detection APIs.

Summary

Nested classes

class AlwaysOnHotwordDetector.Callback

Callbacks for always-on hotword detection. 

class AlwaysOnHotwordDetector.EventPayload

Additional payload for onDetected(AlwaysOnHotwordDetector.EventPayload)

Constants

int RECOGNITION_FLAG_ALLOW_MULTIPLE_TRIGGERS

Recognition flag for startRecognition(int) that indicates whether the recognition should keep going on even after the keyphrase triggers.

int RECOGNITION_FLAG_CAPTURE_TRIGGER_AUDIO

Recognition flag for startRecognition(int) that indicates whether the trigger audio for hotword needs to be captured.

int RECOGNITION_MODE_USER_IDENTIFICATION

User identification performed with the keyphrase recognition.

int RECOGNITION_MODE_VOICE_TRIGGER

Simple recognition of the key phrase.

int STATE_HARDWARE_UNAVAILABLE

Indicates that recognition for the given keyphrase is not available on the system because of the hardware configuration.

int STATE_KEYPHRASE_ENROLLED

Indicates that the given keyphrase is currently enrolled and it's possible to start recognition for it.

int STATE_KEYPHRASE_UNENROLLED

Indicates that the given keyphrase is not enrolled.

int STATE_KEYPHRASE_UNSUPPORTED

Indicates that recognition for the given keyphrase is not supported.

Public methods

Intent createEnrollIntent()

Creates an intent to start the enrollment for the associated keyphrase.

Intent createReEnrollIntent()

Creates an intent to start the re-enrollment for the associated keyphrase.

Intent createUnEnrollIntent()

Creates an intent to start the un-enrollment for the associated keyphrase.

int getSupportedRecognitionModes()

Gets the recognition modes supported by the associated keyphrase.

boolean startRecognition(int recognitionFlags)

Starts recognition for the associated keyphrase.

boolean stopRecognition()

Stops recognition for the associated keyphrase.

Inherited methods

From class java.lang.Object

Constants

RECOGNITION_FLAG_ALLOW_MULTIPLE_TRIGGERS

added in API level 21
int RECOGNITION_FLAG_ALLOW_MULTIPLE_TRIGGERS

Recognition flag for startRecognition(int) that indicates whether the recognition should keep going on even after the keyphrase triggers. If this flag is specified, it's possible to get multiple triggers after a call to startRecognition(int) if the user speaks the keyphrase multiple times. When this isn't specified, the default behavior is to stop recognition once the keyphrase is spoken, till the caller starts recognition again.

Constant Value: 2 (0x00000002)

RECOGNITION_FLAG_CAPTURE_TRIGGER_AUDIO

added in API level 21
int RECOGNITION_FLAG_CAPTURE_TRIGGER_AUDIO

Recognition flag for startRecognition(int) that indicates whether the trigger audio for hotword needs to be captured.

Constant Value: 1 (0x00000001)

RECOGNITION_MODE_USER_IDENTIFICATION

added in API level 21
int RECOGNITION_MODE_USER_IDENTIFICATION

User identification performed with the keyphrase recognition. Returned by getSupportedRecognitionModes()

Constant Value: 2 (0x00000002)

RECOGNITION_MODE_VOICE_TRIGGER

added in API level 21
int RECOGNITION_MODE_VOICE_TRIGGER

Simple recognition of the key phrase. Returned by getSupportedRecognitionModes()

Constant Value: 1 (0x00000001)

STATE_HARDWARE_UNAVAILABLE

added in API level 21
int STATE_HARDWARE_UNAVAILABLE

Indicates that recognition for the given keyphrase is not available on the system because of the hardware configuration. No further interaction should be performed with the detector that returns this availability.

Constant Value: -2 (0xfffffffe)

STATE_KEYPHRASE_ENROLLED

added in API level 21
int STATE_KEYPHRASE_ENROLLED

Indicates that the given keyphrase is currently enrolled and it's possible to start recognition for it.

Constant Value: 2 (0x00000002)

STATE_KEYPHRASE_UNENROLLED

added in API level 21
int STATE_KEYPHRASE_UNENROLLED

Indicates that the given keyphrase is not enrolled. The caller may choose to begin an enrollment flow for the keyphrase.

Constant Value: 1 (0x00000001)

STATE_KEYPHRASE_UNSUPPORTED

added in API level 21
int STATE_KEYPHRASE_UNSUPPORTED

Indicates that recognition for the given keyphrase is not supported. No further interaction should be performed with the detector that returns this availability.

Constant Value: -1 (0xffffffff)

Public methods

createEnrollIntent

added in API level 21
Intent createEnrollIntent ()

Creates an intent to start the enrollment for the associated keyphrase. This intent must be invoked using startActivityForResult(Intent, int). Starting re-enrollment is only valid if the keyphrase is un-enrolled, i.e. STATE_KEYPHRASE_UNENROLLED, otherwise createReEnrollIntent() should be preferred.

Returns
Intent An Intent to start enrollment for the given keyphrase.

Throws
UnsupportedOperationException if managing they keyphrase isn't supported. Callers should only call this method after a supported state callback on onAvailabilityChanged(int) to avoid this exception.
IllegalStateException if the detector is in an invalid state. This may happen if another detector has been instantiated or the VoiceInteractionService hosting this detector has been shut down.

createReEnrollIntent

added in API level 21
Intent createReEnrollIntent ()

Creates an intent to start the re-enrollment for the associated keyphrase. This intent must be invoked using startActivityForResult(Intent, int). Starting re-enrollment is only valid if the keyphrase is already enrolled, i.e. STATE_KEYPHRASE_ENROLLED, otherwise invoking this may result in an error.

Returns
Intent An Intent to start re-enrollment for the given keyphrase.

Throws
UnsupportedOperationException if managing they keyphrase isn't supported. Callers should only call this method after a supported state callback on onAvailabilityChanged(int) to avoid this exception.
IllegalStateException if the detector is in an invalid state. This may happen if another detector has been instantiated or the VoiceInteractionService hosting this detector has been shut down.

createUnEnrollIntent

added in API level 21
Intent createUnEnrollIntent ()

Creates an intent to start the un-enrollment for the associated keyphrase. This intent must be invoked using startActivityForResult(Intent, int). Starting re-enrollment is only valid if the keyphrase is already enrolled, i.e. STATE_KEYPHRASE_ENROLLED, otherwise invoking this may result in an error.

Returns
Intent An Intent to start un-enrollment for the given keyphrase.

Throws
UnsupportedOperationException if managing they keyphrase isn't supported. Callers should only call this method after a supported state callback on onAvailabilityChanged(int) to avoid this exception.
IllegalStateException if the detector is in an invalid state. This may happen if another detector has been instantiated or the VoiceInteractionService hosting this detector has been shut down.

getSupportedRecognitionModes

added in API level 21
int getSupportedRecognitionModes ()

Gets the recognition modes supported by the associated keyphrase.

Returns
int

Throws
UnsupportedOperationException if the keyphrase itself isn't supported. Callers should only call this method after a supported state callback on onAvailabilityChanged(int) to avoid this exception.
IllegalStateException if the detector is in an invalid state. This may happen if another detector has been instantiated or the VoiceInteractionService hosting this detector has been shut down.

startRecognition

added in API level 21
boolean startRecognition (int recognitionFlags)

Starts recognition for the associated keyphrase.

Parameters
recognitionFlags int: The flags to control the recognition properties.

Returns
boolean Indicates whether the call succeeded or not.

Throws
UnsupportedOperationException if the recognition isn't supported. Callers should only call this method after a supported state callback on onAvailabilityChanged(int) to avoid this exception.
IllegalStateException if the detector is in an invalid state. This may happen if another detector has been instantiated or the VoiceInteractionService hosting this detector has been shut down.

stopRecognition

added in API level 21
boolean stopRecognition ()

Stops recognition for the associated keyphrase.

Returns
boolean Indicates whether the call succeeded or not.

Throws
UnsupportedOperationException if the recognition isn't supported. Callers should only call this method after a supported state callback on onAvailabilityChanged(int) to avoid this exception.
IllegalStateException if the detector is in an invalid state. This may happen if another detector has been instantiated or the VoiceInteractionService hosting this detector has been shut down.
This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)