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

Commit 46edacff authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add getData() member to SoundTriggerDetector.EventPayload."

parents 7f64c692 7554ff0e
Loading
Loading
Loading
Loading
+19 −1
Original line number 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.
         * 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.
+14 −2
Original line number Diff line number Diff line
@@ -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;
    }