Most visited

Recently visited

Added in API level 21

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.

See also:

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.

See also:

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.

Hooray!