public class AlwaysOnHotwordDetector extends Object
Modifier and Type | Class and Description |
---|---|
static class |
AlwaysOnHotwordDetector.Callback
Callbacks for always-on hotword detection.
|
static class |
AlwaysOnHotwordDetector.EventPayload
|
static interface |
AlwaysOnHotwordDetector.RecognitionFlags |
static interface |
AlwaysOnHotwordDetector.RecognitionModes |
Modifier and Type | Field and Description |
---|---|
static int |
MANAGE_ACTION_ENROLL
Indicates that we need to enroll.
|
static int |
MANAGE_ACTION_RE_ENROLL
Indicates that we need to re-enroll.
|
static int |
MANAGE_ACTION_UN_ENROLL
Indicates that we need to un-enroll.
|
static 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. |
static int |
RECOGNITION_FLAG_CAPTURE_TRIGGER_AUDIO
Recognition flag for
startRecognition(int) that indicates
whether the trigger audio for hotword needs to be captured. |
static int |
RECOGNITION_FLAG_NONE
Empty flag for
startRecognition(int) . |
static int |
RECOGNITION_MODE_USER_IDENTIFICATION
User identification performed with the keyphrase recognition.
|
static int |
RECOGNITION_MODE_VOICE_TRIGGER
Simple recognition of the key phrase.
|
static int |
STATE_HARDWARE_UNAVAILABLE
Indicates that recognition for the given keyphrase is not available on the system
because of the hardware configuration.
|
static int |
STATE_KEYPHRASE_ENROLLED
Indicates that the given keyphrase is currently enrolled and it's possible to start
recognition for it.
|
static int |
STATE_KEYPHRASE_UNENROLLED
Indicates that the given keyphrase is not enrolled.
|
static int |
STATE_KEYPHRASE_UNSUPPORTED
Indicates that recognition for the given keyphrase is not supported.
|
Constructor and Description |
---|
AlwaysOnHotwordDetector(String text,
Locale locale,
AlwaysOnHotwordDetector.Callback callback,
KeyphraseEnrollmentInfo keyphraseEnrollmentInfo,
IVoiceInteractionService voiceInteractionService,
IVoiceInteractionManagerService modelManagementService) |
Modifier and Type | Method and Description |
---|---|
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.
|
void |
dump(String prefix,
PrintWriter pw) |
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.
|
public static final int STATE_HARDWARE_UNAVAILABLE
public static final int STATE_KEYPHRASE_UNSUPPORTED
public static final int STATE_KEYPHRASE_UNENROLLED
public static final int STATE_KEYPHRASE_ENROLLED
public static final int MANAGE_ACTION_ENROLL
public static final int MANAGE_ACTION_RE_ENROLL
public static final int MANAGE_ACTION_UN_ENROLL
public static final int RECOGNITION_FLAG_NONE
startRecognition(int)
.public static final int RECOGNITION_FLAG_CAPTURE_TRIGGER_AUDIO
startRecognition(int)
that indicates
whether the trigger audio for hotword needs to be captured.public static final int RECOGNITION_FLAG_ALLOW_MULTIPLE_TRIGGERS
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.public static final int RECOGNITION_MODE_VOICE_TRIGGER
getSupportedRecognitionModes()
public static final int RECOGNITION_MODE_USER_IDENTIFICATION
getSupportedRecognitionModes()
public AlwaysOnHotwordDetector(String text, Locale locale, AlwaysOnHotwordDetector.Callback callback, KeyphraseEnrollmentInfo keyphraseEnrollmentInfo, IVoiceInteractionService voiceInteractionService, IVoiceInteractionManagerService modelManagementService)
text
- The keyphrase text to get the detector for.locale
- The java locale for the detector.callback
- A non-null Callback for receiving the recognition events.voiceInteractionService
- The current voice interaction service.modelManagementService
- A service that allows management of sound models.public int getSupportedRecognitionModes()
UnsupportedOperationException
- if the keyphrase itself isn't supported.
Callers should only call this method after a supported state callback on
AlwaysOnHotwordDetector.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.RECOGNITION_MODE_USER_IDENTIFICATION
,
RECOGNITION_MODE_VOICE_TRIGGER
public boolean startRecognition(int recognitionFlags)
recognitionFlags
- The flags to control the recognition properties.UnsupportedOperationException
- if the recognition isn't supported.
Callers should only call this method after a supported state callback on
AlwaysOnHotwordDetector.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.RECOGNITION_FLAG_CAPTURE_TRIGGER_AUDIO
,
RECOGNITION_FLAG_ALLOW_MULTIPLE_TRIGGERS
public boolean stopRecognition()
UnsupportedOperationException
- if the recognition isn't supported.
Callers should only call this method after a supported state callback on
AlwaysOnHotwordDetector.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.public Intent createEnrollIntent()
Activity.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.Intent
to start enrollment for the given keyphrase.UnsupportedOperationException
- if managing they keyphrase isn't supported.
Callers should only call this method after a supported state callback on
AlwaysOnHotwordDetector.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.public Intent createUnEnrollIntent()
Activity.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.Intent
to start un-enrollment for the given keyphrase.UnsupportedOperationException
- if managing they keyphrase isn't supported.
Callers should only call this method after a supported state callback on
AlwaysOnHotwordDetector.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.public Intent createReEnrollIntent()
Activity.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.Intent
to start re-enrollment for the given keyphrase.UnsupportedOperationException
- if managing they keyphrase isn't supported.
Callers should only call this method after a supported state callback on
AlwaysOnHotwordDetector.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.public void dump(String prefix, PrintWriter pw)