Search in sources :

Example 41 with GenericSoundModel

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

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 42 with GenericSoundModel

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

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 43 with GenericSoundModel

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

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 44 with GenericSoundModel

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

the class SoundTriggerDbHelper method deleteGenericSoundModel.

public boolean deleteGenericSoundModel(UUID model_uuid) {
    synchronized (this) {
        GenericSoundModel soundModel = getGenericSoundModel(model_uuid);
        if (soundModel == null) {
            return false;
        }
        // Delete all sound models for the given keyphrase and specified user.
        SQLiteDatabase db = getWritableDatabase();
        String soundModelClause = GenericSoundModelContract.KEY_MODEL_UUID + "='" + soundModel.uuid.toString() + "'";
        try {
            return db.delete(GenericSoundModelContract.TABLE, soundModelClause, null) != 0;
        } finally {
            db.close();
        }
    }
}
Also used : GenericSoundModel(android.hardware.soundtrigger.SoundTrigger.GenericSoundModel) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

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