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

TestEnrollmentActivity

public class TestEnrollmentActivity extends android.app.Activity

Fields Summary
private static final String
TAG
private static final boolean
DBG
private static final int
KEYPHRASE_ID
Keyphrase related constants, must match those defined in enrollment_application.xml
private static final int
RECOGNITION_MODES
private static final String
BCP47_LOCALE
private static final String
TEXT
private EnrollmentUtil
mEnrollmentUtil
private Random
mRandom
Constructors Summary
Methods Summary
protected voidonCreate(android.os.Bundle savedInstanceState)


    
        
        if (DBG) Log.d(TAG, "onCreate");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mEnrollmentUtil = new EnrollmentUtil();
        mRandom = new Random();
    
public voidonEnrollButtonClicked(android.view.View v)
Called when the user clicks the enroll button. Performs a fresh enrollment.

        Keyphrase kp = new Keyphrase(KEYPHRASE_ID, RECOGNITION_MODES, BCP47_LOCALE, TEXT,
                new int[] { UserManager.get(this).getUserHandle() /* current user */});
        UUID modelUuid = UUID.randomUUID();
        // Generate a fake model to push.
        byte[] data = new byte[1024];
        mRandom.nextBytes(data);
        KeyphraseSoundModel soundModel = new KeyphraseSoundModel(modelUuid, null, data,
                new Keyphrase[] { kp });
        boolean status = mEnrollmentUtil.addOrUpdateSoundModel(soundModel);
        if (status) {
            Toast.makeText(
                    this, "Successfully enrolled, model UUID=" + modelUuid, Toast.LENGTH_SHORT)
                    .show();
        } else {
            Toast.makeText(this, "Failed to enroll!!!" + modelUuid, Toast.LENGTH_SHORT).show();
        }
    
public voidonReEnrollButtonClicked(android.view.View v)
Called when the user clicks the re-enroll button. Uses the previously enrolled sound model and makes changes to it before pushing it back.

        KeyphraseSoundModel soundModel = mEnrollmentUtil.getSoundModel(KEYPHRASE_ID, BCP47_LOCALE);
        if (soundModel == null) {
            Toast.makeText(this, "Sound model not found!!!", Toast.LENGTH_SHORT).show();
            return;
        }
        // Generate a fake model to push.
        byte[] data = new byte[2048];
        mRandom.nextBytes(data);
        KeyphraseSoundModel updated = new KeyphraseSoundModel(soundModel.uuid,
                soundModel.vendorUuid, data, soundModel.keyphrases);
        boolean status = mEnrollmentUtil.addOrUpdateSoundModel(updated);
        if (status) {
            Toast.makeText(this, "Successfully re-enrolled, model UUID=" + updated.uuid,
                    Toast.LENGTH_SHORT)
                    .show();
        } else {
            Toast.makeText(this, "Failed to re-enroll!!!", Toast.LENGTH_SHORT).show();
        }
    
public voidonUnEnrollButtonClicked(android.view.View v)
Called when the user clicks the un-enroll button. Clears the enrollment information for the user.

        KeyphraseSoundModel soundModel = mEnrollmentUtil.getSoundModel(KEYPHRASE_ID, BCP47_LOCALE);
        if (soundModel == null) {
            Toast.makeText(this, "Sound model not found!!!", Toast.LENGTH_SHORT).show();
            return;
        }
        boolean status = mEnrollmentUtil.deleteSoundModel(KEYPHRASE_ID, BCP47_LOCALE);
        if (status) {
            Toast.makeText(this, "Successfully un-enrolled, model UUID=" + soundModel.uuid,
                    Toast.LENGTH_SHORT)
                    .show();
        } else {
            Toast.makeText(this, "Failed to un-enroll!!!", Toast.LENGTH_SHORT).show();
        }