FileDocCategorySizeDatePackage
EnrollmentUtil.javaAPI DocAndroid 5.1 API7617Thu Mar 12 22:22:44 GMT 2015com.android.test.voiceenrollment

EnrollmentUtil

public class EnrollmentUtil extends Object
Utility class for the enrollment operations like enroll;re-enroll & un-enroll.

Fields Summary
private static final String
TAG
public static final String
ACTION_MANAGE_VOICE_KEYPHRASES
Activity Action: Show activity for managing the keyphrases for hotword detection. This needs to be defined by an activity that supports enrolling users for hotword/keyphrase detection.
public static final String
EXTRA_VOICE_KEYPHRASE_ACTION
Intent extra: The intent extra for the specific manage action that needs to be performed. Possible values are {@link AlwaysOnHotwordDetector#MANAGE_ACTION_ENROLL}, {@link AlwaysOnHotwordDetector#MANAGE_ACTION_RE_ENROLL} or {@link AlwaysOnHotwordDetector#MANAGE_ACTION_UN_ENROLL}.
public static final String
EXTRA_VOICE_KEYPHRASE_HINT_TEXT
Intent extra: The hint text to be shown on the voice keyphrase management UI.
public static final String
EXTRA_VOICE_KEYPHRASE_LOCALE
Intent extra: The voice locale to use while managing the keyphrase.
public static final int
RECOGNITION_MODE_VOICE_TRIGGER
Simple recognition of the key phrase
public static final int
RECOGNITION_MODE_USER_IDENTIFICATION
Trigger only if one user is identified
private final com.android.internal.app.IVoiceInteractionManagerService
mModelManagementService
Constructors Summary
public EnrollmentUtil()


      
        mModelManagementService = IVoiceInteractionManagerService.Stub.asInterface(
                ServiceManager.getService(Context.VOICE_INTERACTION_MANAGER_SERVICE));
    
Methods Summary
public booleanaddOrUpdateSoundModel(android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel soundModel)
Adds/Updates a sound model. The sound model must contain a valid UUID, exactly 1 keyphrase, and users for which the keyphrase is valid - typically the current user.

param
soundModel The sound model to add/update.
return
{@code true} if the call succeeds, {@code false} otherwise.

        if (!verifyKeyphraseSoundModel(soundModel)) {
            return false;
        }

        int status = SoundTrigger.STATUS_ERROR;
        try {
            status = mModelManagementService.updateKeyphraseSoundModel(soundModel);
        } catch (RemoteException e) {
            Log.e(TAG, "RemoteException in updateKeyphraseSoundModel", e);
        }
        return status == SoundTrigger.STATUS_OK;
    
public booleandeleteSoundModel(int keyphraseId, java.lang.String bcp47Locale)
Deletes the sound model for the given keyphrase id.

param
keyphraseId The keyphrase ID to look-up the sound model for.
return
{@code true} if the call succeeds, {@code false} otherwise.

        if (keyphraseId <= 0) {
            Log.e(TAG, "Keyphrase must have a valid ID");
            return false;
        }

        int status = SoundTrigger.STATUS_ERROR;
        try {
            status = mModelManagementService.deleteKeyphraseSoundModel(keyphraseId, bcp47Locale);
        } catch (RemoteException e) {
            Log.e(TAG, "RemoteException in updateKeyphraseSoundModel");
        }
        return status == SoundTrigger.STATUS_OK;
    
public android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModelgetSoundModel(int keyphraseId, java.lang.String bcp47Locale)
Gets the sound model for the given keyphrase, null if none exists. This should be used for re-enrollment purposes. If a sound model for a given keyphrase exists, and it needs to be updated, it should be obtained using this method, updated and then passed in to {@link #addOrUpdateSoundModel(KeyphraseSoundModel)} without changing the IDs.

param
keyphraseId The keyphrase ID to look-up the sound model for.
param
bcp47Locale The locale for with to look up the sound model for.
return
The sound model if one was found, null otherwise.

        if (keyphraseId <= 0) {
            Log.e(TAG, "Keyphrase must have a valid ID");
            return null;
        }

        KeyphraseSoundModel model = null;
        try {
            model = mModelManagementService.getKeyphraseSoundModel(keyphraseId, bcp47Locale);
        } catch (RemoteException e) {
            Log.e(TAG, "RemoteException in updateKeyphraseSoundModel");
        }

        if (model == null) {
            Log.w(TAG, "No models present for the gien keyphrase ID");
            return null;
        } else {
            return model;
        }
    
private booleanverifyKeyphraseSoundModel(android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel soundModel)

        if (soundModel == null) {
            Log.e(TAG, "KeyphraseSoundModel must be non-null");
            return false;
        }
        if (soundModel.uuid == null) {
            Log.e(TAG, "KeyphraseSoundModel must have a UUID");
            return false;
        }
        if (soundModel.data == null) {
            Log.e(TAG, "KeyphraseSoundModel must have data");
            return false;
        }
        if (soundModel.keyphrases == null || soundModel.keyphrases.length != 1) {
            Log.e(TAG, "Keyphrase must be exactly 1");
            return false;
        }
        Keyphrase keyphrase = soundModel.keyphrases[0];
        if (keyphrase.id <= 0) {
            Log.e(TAG, "Keyphrase must have a valid ID");
            return false;
        }
        if (keyphrase.recognitionModes < 0) {
            Log.e(TAG, "Recognition modes must be valid");
            return false;
        }
        if (keyphrase.locale == null) {
            Log.e(TAG, "Locale must not be null");
            return false;
        }
        if (keyphrase.text == null) {
            Log.e(TAG, "Text must not be null");
            return false;
        }
        if (keyphrase.users == null || keyphrase.users.length == 0) {
            Log.e(TAG, "Keyphrase must have valid user(s)");
            return false;
        }
        return true;