Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7554ff0e authored by Chris Thornton's avatar Chris Thornton
Browse files

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
parent 9328f323
Loading
Loading
Loading
Loading
+19 −1
Original line number Original line Diff line number Diff line
@@ -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.
         * This may be null if the trigger audio isn't available.
         * If non-null, the format of the audio can be obtained by calling
         * If non-null, the format of the audio can be obtained by calling
         * {@link #getCaptureAudioFormat()}.
         * {@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.
         * Gets the session ID to start a capture from the DSP.
         * This may be null if streaming capture isn't possible.
         * This may be null if streaming capture isn't possible.
+14 −2
Original line number Original line Diff line number Diff line
@@ -689,8 +689,20 @@ public class SoundTriggerTestService extends Service {
        AudioFormat format =  event.getCaptureAudioFormat();
        AudioFormat format =  event.getCaptureAudioFormat();
        result = result + "AudioFormat: " + ((format == null) ? "null" : format.toString());
        result = result + "AudioFormat: " + ((format == null) ? "null" : format.toString());
        byte[] triggerAudio = event.getTriggerAudio();
        byte[] triggerAudio = event.getTriggerAudio();
        result = result + "TriggerAudio: " + (triggerAudio == null ? "null" : triggerAudio.length);
        result = result + ", TriggerAudio: " + (triggerAudio == null ? "null" : triggerAudio.length);
        result = result + "CaptureSession: " + event.getCaptureSession();
        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 += " )";
        result += " )";
        return result;
        return result;
    }
    }