Android APIs
public class

AlwaysOnHotwordDetector

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

Class Overview

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.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int RECOGNITION_FLAG_ALLOW_MULTIPLE_TRIGGERS

Added in API level 21

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)

public static final int RECOGNITION_FLAG_CAPTURE_TRIGGER_AUDIO

Added in API level 21

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

Constant Value: 1 (0x00000001)

public static final int RECOGNITION_MODE_USER_IDENTIFICATION

Added in API level 21

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

Constant Value: 2 (0x00000002)

public static final int RECOGNITION_MODE_VOICE_TRIGGER

Added in API level 21

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

Constant Value: 1 (0x00000001)

public static final int STATE_HARDWARE_UNAVAILABLE

Added in API level 21

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)

public static final int STATE_KEYPHRASE_ENROLLED

Added in API level 21

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

Constant Value: 2 (0x00000002)

public static final int STATE_KEYPHRASE_UNENROLLED

Added in API level 21

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

Constant Value: 1 (0x00000001)

public static final int STATE_KEYPHRASE_UNSUPPORTED

Added in API level 21

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

public Intent createEnrollIntent ()

Added in API level 21

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
  • 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.

public Intent createReEnrollIntent ()

Added in API level 21

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
  • 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.

public Intent createUnEnrollIntent ()

Added in API level 21

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
  • 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.

public int getSupportedRecognitionModes ()

Added in API level 21

Gets the recognition modes supported by the associated keyphrase.

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.

public boolean startRecognition (int recognitionFlags)

Added in API level 21

Starts recognition for the associated keyphrase.

Parameters
recognitionFlags The flags to control the recognition properties.
Returns
  • 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.

public boolean stopRecognition ()

Added in API level 21

Stops recognition for the associated keyphrase.

Returns
  • 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.