Search in sources :

Example 16 with KeyphraseSoundModel

use of android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel in project android_frameworks_base by crdroidandroid.

the class SoundTriggerTest method testKeyphraseSoundModelParcelUnparcel_zeroKeyphrases.

@SmallTest
public void testKeyphraseSoundModelParcelUnparcel_zeroKeyphrases() throws Exception {
    byte[] data = new byte[10];
    mRandom.nextBytes(data);
    KeyphraseSoundModel ksm = new KeyphraseSoundModel(UUID.randomUUID(), UUID.randomUUID(), data, new Keyphrase[0]);
    // Write to a parcel
    Parcel parcel = Parcel.obtain();
    ksm.writeToParcel(parcel, 0);
    // Read from it
    parcel.setDataPosition(0);
    KeyphraseSoundModel unparceled = KeyphraseSoundModel.CREATOR.createFromParcel(parcel);
    // Verify that they are the same
    assertEquals(ksm.uuid, unparceled.uuid);
    assertEquals(ksm.type, unparceled.type);
    assertTrue(Arrays.equals(ksm.keyphrases, unparceled.keyphrases));
    assertTrue(Arrays.equals(ksm.data, unparceled.data));
}
Also used : KeyphraseSoundModel(android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel) Parcel(android.os.Parcel) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 17 with KeyphraseSoundModel

use of android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel in project android_frameworks_base by crdroidandroid.

the class SoundTriggerTest method testKeyphraseSoundModelParcelUnparcel_zeroData.

@SmallTest
public void testKeyphraseSoundModelParcelUnparcel_zeroData() throws Exception {
    Keyphrase[] keyphrases = new Keyphrase[2];
    keyphrases[0] = new Keyphrase(1, 0, "en-US", "hello", new int[] { 0 });
    keyphrases[1] = new Keyphrase(2, 0, "fr-FR", "there", new int[] { 1, 2 });
    KeyphraseSoundModel ksm = new KeyphraseSoundModel(UUID.randomUUID(), UUID.randomUUID(), new byte[0], keyphrases);
    // Write to a parcel
    Parcel parcel = Parcel.obtain();
    ksm.writeToParcel(parcel, 0);
    // Read from it
    parcel.setDataPosition(0);
    KeyphraseSoundModel unparceled = KeyphraseSoundModel.CREATOR.createFromParcel(parcel);
    // Verify that they are the same
    assertEquals(ksm.uuid, unparceled.uuid);
    assertEquals(ksm.type, unparceled.type);
    assertTrue(Arrays.equals(ksm.keyphrases, unparceled.keyphrases));
    assertTrue(Arrays.equals(ksm.data, unparceled.data));
}
Also used : KeyphraseSoundModel(android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel) Parcel(android.os.Parcel) Keyphrase(android.hardware.soundtrigger.SoundTrigger.Keyphrase) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 18 with KeyphraseSoundModel

use of android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel in project android_frameworks_base by crdroidandroid.

the class TestEnrollmentActivity method onUnEnrollButtonClicked.

/**
     * Called when the user clicks the un-enroll button.
     * Clears the enrollment information for the user.
     */
public void onUnEnrollButtonClicked(View v) {
    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();
    }
}
Also used : KeyphraseSoundModel(android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel)

Example 19 with KeyphraseSoundModel

use of android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel in project android_frameworks_base by crdroidandroid.

the class TestEnrollmentActivity method onEnrollButtonClicked.

/**
     * Called when the user clicks the enroll button.
     * Performs a fresh enrollment.
     */
public void onEnrollButtonClicked(View v) {
    Keyphrase kp = new Keyphrase(KEYPHRASE_ID, RECOGNITION_MODES, BCP47_LOCALE, TEXT, new int[] { UserManager.get(this).getUserHandle() });
    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();
    }
}
Also used : KeyphraseSoundModel(android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel) Keyphrase(android.hardware.soundtrigger.SoundTrigger.Keyphrase) UUID(java.util.UUID)

Example 20 with KeyphraseSoundModel

use of android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel in project platform_frameworks_base by android.

the class SoundTriggerTest method testKeyphraseSoundModelParcelUnparcel_largeData.

@LargeTest
public void testKeyphraseSoundModelParcelUnparcel_largeData() throws Exception {
    Keyphrase[] keyphrases = new Keyphrase[2];
    keyphrases[0] = new Keyphrase(1, 0, "en-US", "hello", new int[] { 0 });
    keyphrases[1] = new Keyphrase(2, 0, "fr-FR", "there", new int[] { 1, 2 });
    byte[] data = new byte[200 * 1024];
    mRandom.nextBytes(data);
    KeyphraseSoundModel ksm = new KeyphraseSoundModel(UUID.randomUUID(), UUID.randomUUID(), data, keyphrases);
    // Write to a parcel
    Parcel parcel = Parcel.obtain();
    ksm.writeToParcel(parcel, 0);
    // Read from it
    parcel.setDataPosition(0);
    KeyphraseSoundModel unparceled = KeyphraseSoundModel.CREATOR.createFromParcel(parcel);
    // Verify that they are the same
    assertEquals(ksm.uuid, unparceled.uuid);
    assertEquals(ksm.type, unparceled.type);
    assertTrue(Arrays.equals(ksm.data, unparceled.data));
    assertTrue(Arrays.equals(ksm.keyphrases, unparceled.keyphrases));
}
Also used : KeyphraseSoundModel(android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel) Parcel(android.os.Parcel) Keyphrase(android.hardware.soundtrigger.SoundTrigger.Keyphrase) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

KeyphraseSoundModel (android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel)40 Keyphrase (android.hardware.soundtrigger.SoundTrigger.Keyphrase)20 Parcel (android.os.Parcel)20 SmallTest (android.test.suitebuilder.annotation.SmallTest)16 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)8 UUID (java.util.UUID)8 Cursor (android.database.Cursor)4 LargeTest (android.test.suitebuilder.annotation.LargeTest)4