# Print output for @column tags ?> AlwaysOnHotwordDetector - Android SDK | Android Developers

Most visited

Recently visited

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 Callback#onDetected

class AlwaysOnHotwordDetector.ModelParamRange

A ModelParamRange is a representation of supported parameter range for a given loaded model. 

Constants

int AUDIO_CAPABILITY_ECHO_CANCELLATION

If set the underlying module supports AEC.

int AUDIO_CAPABILITY_NOISE_SUPPRESSION

If set, the underlying module supports noise suppression.

int MODEL_PARAM_THRESHOLD_FACTOR

Controls the sensitivity threshold adjustment factor for a given model.

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_FLAG_ENABLE_AUDIO_ECHO_CANCELLATION

Audio capabilities flag for startRecognition(int) that indicates if the underlying recognition should use AEC.

int RECOGNITION_FLAG_ENABLE_AUDIO_NOISE_SUPPRESSION

Audio capabilities flag for startRecognition(int) that indicates if the underlying recognition should use noise suppression.

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

This constant is deprecated. This is no longer a valid state. Enrollment can occur outside of KeyphraseEnrollmentInfo through another privileged application. We can no longer determine ahead of time if the keyphrase and locale are unsupported by the system.

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 getParameter(int modelParam)

Get a model specific ModelParams.

int getSupportedAudioCapabilities()

Get the audio capabilities supported by the platform which can be enabled when starting a recognition.

int getSupportedRecognitionModes()

Gets the recognition modes supported by the associated keyphrase.

AlwaysOnHotwordDetector.ModelParamRange queryParameter(int modelParam)

Determine if parameter control is supported for the given model handle.

int setParameter(int modelParam, int value)

Set a model specific ModelParams with the given value.

boolean startRecognition(int recognitionFlags)

Starts recognition for the associated keyphrase.

boolean stopRecognition()

Stops recognition for the associated keyphrase.

Inherited methods

Constants

AUDIO_CAPABILITY_ECHO_CANCELLATION

public static final int AUDIO_CAPABILITY_ECHO_CANCELLATION

If set the underlying module supports AEC. Returned by getSupportedAudioCapabilities()

Constant Value: 1 (0x00000001)

AUDIO_CAPABILITY_NOISE_SUPPRESSION

public static final int AUDIO_CAPABILITY_NOISE_SUPPRESSION

If set, the underlying module supports noise suppression. Returned by getSupportedAudioCapabilities()

Constant Value: 2 (0x00000002)

MODEL_PARAM_THRESHOLD_FACTOR

public static final int MODEL_PARAM_THRESHOLD_FACTOR

Controls the sensitivity threshold adjustment factor for a given model. Negative value corresponds to less sensitive model (high threshold) and a positive value corresponds to a more sensitive model (low threshold). Default value is 0.

Constant Value: 0 (0x00000000)

RECOGNITION_FLAG_ALLOW_MULTIPLE_TRIGGERS

public static final 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

public static final 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_FLAG_ENABLE_AUDIO_ECHO_CANCELLATION

public static final int RECOGNITION_FLAG_ENABLE_AUDIO_ECHO_CANCELLATION

Audio capabilities flag for startRecognition(int) that indicates if the underlying recognition should use AEC. This capability may or may not be supported by the system, and support can be queried by calling getSupportedAudioCapabilities(). The corresponding capabilities field for this flag is AUDIO_CAPABILITY_ECHO_CANCELLATION. If this flag is passed without the audio capability supported, there will be no audio effect applied.

Constant Value: 4 (0x00000004)

RECOGNITION_FLAG_ENABLE_AUDIO_NOISE_SUPPRESSION

public static final int RECOGNITION_FLAG_ENABLE_AUDIO_NOISE_SUPPRESSION

Audio capabilities flag for startRecognition(int) that indicates if the underlying recognition should use noise suppression. This capability may or may not be supported by the system, and support can be queried by calling getSupportedAudioCapabilities(). The corresponding capabilities field for this flag is AUDIO_CAPABILITY_NOISE_SUPPRESSION. If this flag is passed without the audio capability supported, there will be no audio effect applied.

Constant Value: 8 (0x00000008)

RECOGNITION_MODE_USER_IDENTIFICATION

public static final int RECOGNITION_MODE_USER_IDENTIFICATION

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

Constant Value: 2 (0x00000002)

RECOGNITION_MODE_VOICE_TRIGGER

public static final int RECOGNITION_MODE_VOICE_TRIGGER

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

Constant Value: 1 (0x00000001)

STATE_HARDWARE_UNAVAILABLE

public static final 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

public static final 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

public static final 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

public static final int STATE_KEYPHRASE_UNSUPPORTED

This constant is deprecated.
This is no longer a valid state. Enrollment can occur outside of KeyphraseEnrollmentInfo through another privileged application. We can no longer determine ahead of time if the keyphrase and locale are unsupported by the system.

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

public Intent createEnrollIntent ()

Creates an intent to start the enrollment for the associated keyphrase. This intent must be invoked using Context#startForegroundService(Intent). 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 Callback#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

public Intent createReEnrollIntent ()

Creates an intent to start the re-enrollment for the associated keyphrase. This intent must be invoked using Context#startForegroundService(Intent). 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 Callback#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

public Intent createUnEnrollIntent ()

Creates an intent to start the un-enrollment for the associated keyphrase. This intent must be invoked using Context#startForegroundService(Intent). 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 Callback#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.

getParameter

public int getParameter (int modelParam)

Get a model specific ModelParams. This parameter will keep its value for the duration the model is loaded regardless of starting and stopping recognition. Once the model is unloaded, the value will be lost. If the value is not set, a default value is returned. See ModelParams for parameter default values. AlwaysOnHotwordDetector#queryParameter should be checked first before calling this method. Caller must be the active voice interaction service via Settings.Secure.VOICE_INTERACTION_SERVICE.

Parameters
modelParam int: ModelParams Value is either 0 or MODEL_PARAM_THRESHOLD_FACTOR

Returns
int value of parameter

getSupportedAudioCapabilities

public int getSupportedAudioCapabilities ()

Get the audio capabilities supported by the platform which can be enabled when starting a recognition. Caller must be the active voice interaction service via Settings.Secure.VOICE_INTERACTION_SERVICE.

Returns
int Bit field encoding of the AudioCapabilities supported. Value is either 0 or a combination of AUDIO_CAPABILITY_ECHO_CANCELLATION, and AUDIO_CAPABILITY_NOISE_SUPPRESSION

See also:

getSupportedRecognitionModes

public int getSupportedRecognitionModes ()

Gets the recognition modes supported by the associated keyphrase.

Returns
int Value is either 0 or a combination of RECOGNITION_MODE_VOICE_TRIGGER, and RECOGNITION_MODE_USER_IDENTIFICATION

Throws
UnsupportedOperationException if the keyphrase itself isn't supported. Callers should only call this method after a supported state callback on Callback#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:

queryParameter

public AlwaysOnHotwordDetector.ModelParamRange queryParameter (int modelParam)

Determine if parameter control is supported for the given model handle. This method should be checked prior to calling AlwaysOnHotwordDetector#setParameter or AlwaysOnHotwordDetector#getParameter. Caller must be the active voice interaction service via Settings.Secure.VOICE_INTERACTION_SERVICE.

Parameters
modelParam int: ModelParams Value is either 0 or MODEL_PARAM_THRESHOLD_FACTOR

Returns
AlwaysOnHotwordDetector.ModelParamRange supported range of parameter, null if not supported

setParameter

public int setParameter (int modelParam, 
                int value)

Set a model specific ModelParams with the given value. This parameter will keep its value for the duration the model is loaded regardless of starting and stopping recognition. Once the model is unloaded, the value will be lost. AlwaysOnHotwordDetector#queryParameter should be checked first before calling this method. Caller must be the active voice interaction service via Settings.Secure.VOICE_INTERACTION_SERVICE.

Parameters
modelParam int: ModelParams Value is either 0 or MODEL_PARAM_THRESHOLD_FACTOR

value int: Value to set

Returns
int - SoundTrigger#STATUS_OK in case of success - SoundTrigger#STATUS_NO_INIT if the native service cannot be reached - SoundTrigger#STATUS_BAD_VALUE invalid input parameter - SoundTrigger#STATUS_INVALID_OPERATION if the call is out of sequence or if API is not supported by HAL

startRecognition

public boolean startRecognition (int recognitionFlags)

Starts recognition for the associated keyphrase. Caller must be the active voice interaction service via Settings.Secure.VOICE_INTERACTION_SERVICE.

Parameters
recognitionFlags int: The flags to control the recognition properties. Value is either 0 or a combination of android.service.voice.AlwaysOnHotwordDetector.RECOGNITION_FLAG_NONE, RECOGNITION_FLAG_CAPTURE_TRIGGER_AUDIO, RECOGNITION_FLAG_ALLOW_MULTIPLE_TRIGGERS, RECOGNITION_FLAG_ENABLE_AUDIO_ECHO_CANCELLATION, and RECOGNITION_FLAG_ENABLE_AUDIO_NOISE_SUPPRESSION

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 Callback#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

public boolean stopRecognition ()

Stops recognition for the associated keyphrase. Caller must be the active voice interaction service via Settings.Secure.VOICE_INTERACTION_SERVICE.

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 Callback#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.