Skip to content

Commit a13104f

Browse files
Sandeep SiddharthaAndroid (Google) Code Review
authored andcommitted
Merge "Read audio format from the recognition event" into lmp-dev
2 parents 9413b24 + 2178e2e commit a13104f

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

api/current.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27533,13 +27533,14 @@ package android.service.voice {
2753327533

2753427534
public static abstract interface AlwaysOnHotwordDetector.Callback {
2753527535
method public abstract void onAvailabilityChanged(int);
27536-
method public abstract void onDetected(android.service.voice.AlwaysOnHotwordDetector.TriggerAudio);
27536+
method public abstract void onDetected(android.service.voice.AlwaysOnHotwordDetector.EventPayload);
2753727537
method public abstract void onError();
2753827538
}
2753927539

27540-
public static class AlwaysOnHotwordDetector.TriggerAudio {
27540+
public static class AlwaysOnHotwordDetector.EventPayload {
2754127541
field public final android.media.AudioFormat audioFormat;
2754227542
field public final byte[] data;
27543+
field public final boolean isTriggerAudio;
2754327544
}
2754427545

2754527546
public class VoiceInteractionService extends android.app.Service {

core/java/android/service/voice/AlwaysOnHotwordDetector.java

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -180,21 +180,27 @@ public class AlwaysOnHotwordDetector {
180180
private int mAvailability = STATE_NOT_READY;
181181

182182
/**
183-
* Details of the audio that triggered the keyphrase.
183+
* Additional payload for {@link Callback#onDetected}.
184184
*/
185-
public static class TriggerAudio {
185+
public static class EventPayload {
186186
/**
187-
* Format of {@code data}.
187+
* Indicates if {@code data} is the audio that triggered the keyphrase.
188188
*/
189-
@NonNull
189+
public final boolean isTriggerAudio;
190+
/**
191+
* Format of {@code data}. May be null if {@code isTriggerAudio} is false.
192+
*/
193+
@Nullable
190194
public final AudioFormat audioFormat;
191195
/**
192-
* Raw audio data that triggered they keyphrase.
196+
* Raw data associated with the event.
197+
* This is the audio that triggered the keyphrase if {@code isTriggerAudio} is true.
193198
*/
194-
@NonNull
199+
@Nullable
195200
public final byte[] data;
196201

197-
private TriggerAudio(AudioFormat _audioFormat, byte[] _data) {
202+
private EventPayload(boolean _isTriggerAudio, AudioFormat _audioFormat, byte[] _data) {
203+
isTriggerAudio = _isTriggerAudio;
198204
audioFormat = _audioFormat;
199205
data = _data;
200206
}
@@ -224,10 +230,11 @@ public interface Callback {
224230
* Clients should start a recognition again once they are done handling this
225231
* detection.
226232
*
227-
* @param triggerAudio Optional trigger audio data, if it was requested during
233+
* @param eventPayload Payload data for the detection event.
234+
* This may contain the trigger audio, if requested when calling
228235
* {@link AlwaysOnHotwordDetector#startRecognition(int)}.
229236
*/
230-
void onDetected(@Nullable TriggerAudio triggerAudio);
237+
void onDetected(@NonNull EventPayload eventPayload);
231238
/**
232239
* Called when the detection fails due to an error.
233240
*/
@@ -487,22 +494,13 @@ public SoundTriggerListener(Handler handler) {
487494
@Override
488495
public void onDetected(KeyphraseRecognitionEvent event) {
489496
if (DBG) {
490-
Slog.d(TAG, "OnDetected(" + event + ")");
497+
Slog.d(TAG, "onDetected(" + event + ")");
491498
} else {
492499
Slog.i(TAG, "onDetected");
493500
}
494-
Message message = Message.obtain(mHandler, MSG_HOTWORD_DETECTED);
495-
// FIXME: Check whether the event contains trigger data or not.
496-
// FIXME: Read the audio format from the event.
497-
if (event.data != null) {
498-
AudioFormat audioFormat = new AudioFormat.Builder()
499-
.setChannelMask(AudioFormat.CHANNEL_IN_MONO)
500-
.setEncoding(AudioFormat.ENCODING_PCM_16BIT)
501-
.setSampleRate(16000)
502-
.build();
503-
message.obj = new TriggerAudio(audioFormat, event.data);
504-
}
505-
message.sendToTarget();
501+
Message.obtain(mHandler, MSG_HOTWORD_DETECTED,
502+
new EventPayload(event.triggerInData, event.captureFormat, event.data))
503+
.sendToTarget();
506504
}
507505

508506
@Override
@@ -527,7 +525,7 @@ public void handleMessage(Message msg) {
527525
mExternalCallback.onAvailabilityChanged(msg.arg1);
528526
break;
529527
case MSG_HOTWORD_DETECTED:
530-
mExternalCallback.onDetected((TriggerAudio) msg.obj);
528+
mExternalCallback.onDetected((EventPayload) msg.obj);
531529
break;
532530
case MSG_DETECTION_ERROR:
533531
mExternalCallback.onError();

0 commit comments

Comments
 (0)