Search in sources :

Example 21 with GenericSoundModel

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

the class GenericSoundModelTest method testTriggerGenericSoundModel.

@LargeTest
public void testTriggerGenericSoundModel() throws Exception {
    GenericSoundModel model = new_sound_model();
    boolean captureTriggerAudio = true;
    boolean allowMultipleTriggers = true;
    RecognitionConfig config = new RecognitionConfig(captureTriggerAudio, allowMultipleTriggers, null, null);
    TestRecognitionStatusCallback spyCallback = spy(new TestRecognitionStatusCallback());
    // Update and start sound model
    soundTriggerService.updateSoundModel(model);
    loadedModelUuids.add(model.uuid);
    soundTriggerService.startRecognition(new ParcelUuid(model.uuid), spyCallback, config);
    // Send trigger to stub HAL
    Socket socket = new Socket(InetAddress.getLocalHost(), 14035);
    DataOutputStream out = new DataOutputStream(socket.getOutputStream());
    out.writeBytes("trig " + model.uuid.toString() + "\r\n");
    out.flush();
    socket.close();
    // Verify trigger was received
    verify(spyCallback, timeout(100)).onGenericSoundTriggerDetected(any());
}
Also used : ParcelUuid(android.os.ParcelUuid) GenericSoundModel(android.hardware.soundtrigger.SoundTrigger.GenericSoundModel) DataOutputStream(java.io.DataOutputStream) RecognitionConfig(android.hardware.soundtrigger.SoundTrigger.RecognitionConfig) Socket(java.net.Socket) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 22 with GenericSoundModel

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

the class SoundTriggerTestService method loadModel.

public synchronized void loadModel(UUID modelUuid) {
    ModelInfo modelInfo = mModelInfoMap.get(modelUuid);
    if (modelInfo == null) {
        postError("Could not find model for: " + modelUuid.toString());
        return;
    }
    postMessage("Loading model: " + modelInfo.name);
    GenericSoundModel soundModel = createNewSoundModel(modelInfo);
    boolean status = mSoundTriggerUtil.addOrUpdateSoundModel(soundModel);
    if (status) {
        postToast("Successfully loaded " + modelInfo.name + ", UUID=" + soundModel.uuid);
        setModelState(modelInfo, "Loaded");
    } else {
        postErrorToast("Failed to load " + modelInfo.name + ", UUID=" + soundModel.uuid + "!");
        setModelState(modelInfo, "Failed to load");
    }
}
Also used : GenericSoundModel(android.hardware.soundtrigger.SoundTrigger.GenericSoundModel)

Example 23 with GenericSoundModel

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

the class SoundTriggerDbHelper method getGenericSoundModel.

public GenericSoundModel getGenericSoundModel(UUID model_uuid) {
    synchronized (this) {
        // Find the corresponding sound model ID for the keyphrase.
        String selectQuery = "SELECT  * FROM " + GenericSoundModelContract.TABLE + " WHERE " + GenericSoundModelContract.KEY_MODEL_UUID + "= '" + model_uuid + "'";
        SQLiteDatabase db = getReadableDatabase();
        Cursor c = db.rawQuery(selectQuery, null);
        try {
            if (c.moveToFirst()) {
                do {
                    byte[] data = c.getBlob(c.getColumnIndex(GenericSoundModelContract.KEY_DATA));
                    String vendor_uuid = c.getString(c.getColumnIndex(GenericSoundModelContract.KEY_VENDOR_UUID));
                    return new GenericSoundModel(model_uuid, UUID.fromString(vendor_uuid), data);
                } while (c.moveToNext());
            }
        } finally {
            c.close();
            db.close();
        }
    }
    return null;
}
Also used : GenericSoundModel(android.hardware.soundtrigger.SoundTrigger.GenericSoundModel) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor)

Example 24 with GenericSoundModel

use of android.hardware.soundtrigger.SoundTrigger.GenericSoundModel in project android_frameworks_base by DirtyUnicorns.

the class GenericSoundModelTest method new_sound_model.

GenericSoundModel new_sound_model() {
    // Create sound model
    byte[] data = new byte[1024];
    random.nextBytes(data);
    UUID modelUuid = UUID.randomUUID();
    UUID mVendorUuid = UUID.randomUUID();
    return new GenericSoundModel(modelUuid, mVendorUuid, data);
}
Also used : GenericSoundModel(android.hardware.soundtrigger.SoundTrigger.GenericSoundModel) UUID(java.util.UUID)

Example 25 with GenericSoundModel

use of android.hardware.soundtrigger.SoundTrigger.GenericSoundModel in project android_frameworks_base by DirtyUnicorns.

the class GenericSoundModelTest method testUpdateGenericSoundModel.

@SmallTest
public void testUpdateGenericSoundModel() throws Exception {
    GenericSoundModel model = new_sound_model();
    // Update sound model
    soundTriggerService.updateSoundModel(model);
    loadedModelUuids.add(model.uuid);
    // Confirm it was updated
    GenericSoundModel returnedModel = soundTriggerService.getSoundModel(new ParcelUuid(model.uuid));
    assertEquals(model, returnedModel);
}
Also used : ParcelUuid(android.os.ParcelUuid) GenericSoundModel(android.hardware.soundtrigger.SoundTrigger.GenericSoundModel) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

GenericSoundModel (android.hardware.soundtrigger.SoundTrigger.GenericSoundModel)44 ParcelUuid (android.os.ParcelUuid)20 RecognitionConfig (android.hardware.soundtrigger.SoundTrigger.RecognitionConfig)12 LargeTest (android.test.suitebuilder.annotation.LargeTest)12 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)8 SmallTest (android.test.suitebuilder.annotation.SmallTest)8 DataOutputStream (java.io.DataOutputStream)8 Socket (java.net.Socket)8 UUID (java.util.UUID)8 Cursor (android.database.Cursor)4 ArrayList (java.util.ArrayList)4 Random (java.util.Random)4