Add getData() member to SoundTriggerDetector.EventPayload.
If the HAL populates the recognition event with data that isn't trigger audio, it's currently impossible for clients to actually read that opaque data. By adding this getter, clients who understand how the detection engine works can react to whatever is in the data blob. Test: Modify SoundTriggerTestApp to verify that the data is accessible. Change-Id: I8a9feccab98e2d15653dd55f28a43095f8ee1e44
This commit is contained in:
@@ -137,7 +137,7 @@ public final class SoundTriggerDetector {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the raw audio that triggered the keyphrase.
|
||||
* Gets the raw audio that triggered the detector.
|
||||
* This may be null if the trigger audio isn't available.
|
||||
* If non-null, the format of the audio can be obtained by calling
|
||||
* {@link #getCaptureAudioFormat()}.
|
||||
@@ -153,6 +153,24 @@ public final class SoundTriggerDetector {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the opaque data passed from the detection engine for the event.
|
||||
* This may be null if it was not populated by the engine, or if the data is known to
|
||||
* contain the trigger audio.
|
||||
*
|
||||
* @see #getTriggerAudio
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@Nullable
|
||||
public byte[] getData() {
|
||||
if (!mTriggerAvailable) {
|
||||
return mData;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the session ID to start a capture from the DSP.
|
||||
* This may be null if streaming capture isn't possible.
|
||||
|
||||
@@ -689,8 +689,20 @@ public class SoundTriggerTestService extends Service {
|
||||
AudioFormat format = event.getCaptureAudioFormat();
|
||||
result = result + "AudioFormat: " + ((format == null) ? "null" : format.toString());
|
||||
byte[] triggerAudio = event.getTriggerAudio();
|
||||
result = result + "TriggerAudio: " + (triggerAudio == null ? "null" : triggerAudio.length);
|
||||
result = result + "CaptureSession: " + event.getCaptureSession();
|
||||
result = result + ", TriggerAudio: " + (triggerAudio == null ? "null" : triggerAudio.length);
|
||||
byte[] data = event.getData();
|
||||
result = result + ", Data: " + (data == null ? "null" : data.length);
|
||||
if (data != null) {
|
||||
try {
|
||||
String decodedData = new String(data, "UTF-8");
|
||||
if (decodedData.chars().allMatch(c -> (c >= 32 && c < 128) || c == 0)) {
|
||||
result = result + ", Decoded Data: '" + decodedData + "'";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "Failed to decode data");
|
||||
}
|
||||
}
|
||||
result = result + ", CaptureSession: " + event.getCaptureSession();
|
||||
result += " )";
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user