Sandeep | d701820 | 2014-07-10 15:15:39 -0700 | [diff] [blame] | 1 | /** |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.hardware.soundtrigger; |
| 18 | |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 19 | import static android.system.OsConstants.EINVAL; |
| 20 | import static android.system.OsConstants.ENODEV; |
| 21 | import static android.system.OsConstants.ENOSYS; |
| 22 | import static android.system.OsConstants.EPERM; |
| 23 | import static android.system.OsConstants.EPIPE; |
| 24 | |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 25 | import static java.util.Objects.requireNonNull; |
| 26 | |
Nicholas Ambur | 7092a56 | 2019-12-16 11:18:55 -0800 | [diff] [blame] | 27 | import android.annotation.IntDef; |
Aurimas Liutikas | 4d1699d | 2019-08-28 13:01:05 -0700 | [diff] [blame] | 28 | import android.annotation.NonNull; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 29 | import android.annotation.Nullable; |
| 30 | import android.annotation.SystemApi; |
jiabin | 1f4b4dd | 2019-03-18 18:07:03 -0700 | [diff] [blame] | 31 | import android.app.ActivityThread; |
Artur Satayev | 2695800 | 2019-12-10 17:47:52 +0000 | [diff] [blame] | 32 | import android.compat.annotation.UnsupportedAppUsage; |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 33 | import android.content.Context; |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 34 | import android.media.AudioFormat; |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 35 | import android.media.soundtrigger_middleware.ISoundTriggerMiddlewareService; |
| 36 | import android.media.soundtrigger_middleware.SoundTriggerModuleDescriptor; |
Ytai Ben-Tsvi | 2e8f78b | 2020-01-15 11:57:34 -0800 | [diff] [blame] | 37 | import android.media.soundtrigger_middleware.Status; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 38 | import android.os.Handler; |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 39 | import android.os.IBinder; |
| 40 | import android.os.Looper; |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 41 | import android.os.Parcel; |
| 42 | import android.os.Parcelable; |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 43 | import android.os.RemoteException; |
| 44 | import android.os.ServiceManager; |
Ytai Ben-Tsvi | 2e8f78b | 2020-01-15 11:57:34 -0800 | [diff] [blame] | 45 | import android.os.ServiceSpecificException; |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 46 | import android.util.Log; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 47 | |
Nicholas Ambur | 7092a56 | 2019-12-16 11:18:55 -0800 | [diff] [blame] | 48 | import java.lang.annotation.Retention; |
| 49 | import java.lang.annotation.RetentionPolicy; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 50 | import java.util.ArrayList; |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 51 | import java.util.Arrays; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 52 | import java.util.Locale; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 53 | import java.util.UUID; |
| 54 | |
| 55 | /** |
Ytai Ben-Tsvi | c59b280 | 2020-01-07 14:08:16 -0800 | [diff] [blame] | 56 | * The SoundTrigger class provides access to the service managing the sound trigger HAL. |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 57 | * |
| 58 | * @hide |
| 59 | */ |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 60 | @SystemApi |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 61 | public class SoundTrigger { |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 62 | private static final String TAG = "SoundTrigger"; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 63 | |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 64 | private SoundTrigger() { |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Status code used when the operation succeeded |
| 69 | */ |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 70 | public static final int STATUS_OK = 0; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 71 | /** @hide */ |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 72 | public static final int STATUS_ERROR = Integer.MIN_VALUE; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 73 | /** @hide */ |
Lazar Trsic | 8ea56f6 | 2015-07-07 17:31:20 +0200 | [diff] [blame] | 74 | public static final int STATUS_PERMISSION_DENIED = -EPERM; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 75 | /** @hide */ |
Lazar Trsic | 8ea56f6 | 2015-07-07 17:31:20 +0200 | [diff] [blame] | 76 | public static final int STATUS_NO_INIT = -ENODEV; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 77 | /** @hide */ |
Lazar Trsic | 8ea56f6 | 2015-07-07 17:31:20 +0200 | [diff] [blame] | 78 | public static final int STATUS_BAD_VALUE = -EINVAL; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 79 | /** @hide */ |
Lazar Trsic | 8ea56f6 | 2015-07-07 17:31:20 +0200 | [diff] [blame] | 80 | public static final int STATUS_DEAD_OBJECT = -EPIPE; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 81 | /** @hide */ |
Lazar Trsic | 8ea56f6 | 2015-07-07 17:31:20 +0200 | [diff] [blame] | 82 | public static final int STATUS_INVALID_OPERATION = -ENOSYS; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 83 | |
| 84 | /***************************************************************************** |
| 85 | * A ModuleProperties describes a given sound trigger hardware module |
| 86 | * managed by the native sound trigger service. Each module has a unique |
| 87 | * ID used to target any API call to this paricular module. Module |
| 88 | * properties are returned by listModules() method. |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 89 | * |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 90 | ****************************************************************************/ |
Nicholas Ambur | 1aa4b4b | 2019-08-22 12:13:29 -0700 | [diff] [blame] | 91 | public static final class ModuleProperties implements Parcelable { |
Nicholas Ambur | 7092a56 | 2019-12-16 11:18:55 -0800 | [diff] [blame] | 92 | |
| 93 | /** |
| 94 | * Bit field values of AudioCapabilities supported by the implemented HAL |
| 95 | * driver. |
| 96 | * @hide |
| 97 | */ |
| 98 | @Retention(RetentionPolicy.SOURCE) |
| 99 | @IntDef(flag = true, prefix = { "AUDIO_CAPABILITY_" }, value = { |
| 100 | CAPABILITY_ECHO_CANCELLATION, |
| 101 | CAPABILITY_NOISE_SUPPRESSION |
| 102 | }) |
| 103 | public @interface AudioCapabilities {} |
| 104 | |
| 105 | /** |
| 106 | * If set the underlying module supports AEC. |
| 107 | * Describes bit field {@link ModuleProperties#audioCapabilities} |
| 108 | */ |
| 109 | public static final int CAPABILITY_ECHO_CANCELLATION = 0x1; |
| 110 | /** |
| 111 | * If set, the underlying module supports noise suppression. |
| 112 | * Describes bit field {@link ModuleProperties#audioCapabilities} |
| 113 | */ |
| 114 | public static final int CAPABILITY_NOISE_SUPPRESSION = 0x2; |
| 115 | |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 116 | /** Unique module ID provided by the native service */ |
| 117 | public final int id; |
| 118 | |
| 119 | /** human readable voice detection engine implementor */ |
Nicholas Ambur | 1aa4b4b | 2019-08-22 12:13:29 -0700 | [diff] [blame] | 120 | @NonNull |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 121 | public final String implementor; |
| 122 | |
| 123 | /** human readable voice detection engine description */ |
Nicholas Ambur | 1aa4b4b | 2019-08-22 12:13:29 -0700 | [diff] [blame] | 124 | @NonNull |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 125 | public final String description; |
| 126 | |
| 127 | /** Unique voice engine Id (changes with each version) */ |
Nicholas Ambur | 1aa4b4b | 2019-08-22 12:13:29 -0700 | [diff] [blame] | 128 | @NonNull |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 129 | public final UUID uuid; |
| 130 | |
| 131 | /** Voice detection engine version */ |
| 132 | public final int version; |
| 133 | |
Nicholas Ambur | 38027cd | 2019-12-16 00:06:19 -0800 | [diff] [blame] | 134 | /** |
| 135 | * String naming the architecture used for running the supported models. |
| 136 | * (eg. a platform running models on a DSP could implement this string to convey the DSP |
| 137 | * architecture used) |
| 138 | */ |
| 139 | @NonNull |
| 140 | public final String supportedModelArch; |
| 141 | |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 142 | /** Maximum number of active sound models */ |
| 143 | public final int maxSoundModels; |
| 144 | |
| 145 | /** Maximum number of key phrases */ |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 146 | public final int maxKeyphrases; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 147 | |
| 148 | /** Maximum number of users per key phrase */ |
| 149 | public final int maxUsers; |
| 150 | |
| 151 | /** Supported recognition modes (bit field, RECOGNITION_MODE_VOICE_TRIGGER ...) */ |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 152 | @RecognitionModes |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 153 | public final int recognitionModes; |
| 154 | |
| 155 | /** Supports seamless transition to capture mode after recognition */ |
| 156 | public final boolean supportsCaptureTransition; |
| 157 | |
| 158 | /** Maximum buffering capacity in ms if supportsCaptureTransition() is true */ |
| 159 | public final int maxBufferMs; |
| 160 | |
| 161 | /** Supports capture by other use cases while detection is active */ |
| 162 | public final boolean supportsConcurrentCapture; |
| 163 | |
| 164 | /** Rated power consumption when detection is active with TDB silence/sound/speech ratio */ |
| 165 | public final int powerConsumptionMw; |
| 166 | |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 167 | /** Returns the trigger (key phrase) capture in the binary data of the |
| 168 | * recognition callback event */ |
| 169 | public final boolean returnsTriggerInEvent; |
| 170 | |
Nicholas Ambur | 7092a56 | 2019-12-16 11:18:55 -0800 | [diff] [blame] | 171 | /** |
| 172 | * Bit field encoding of the AudioCapabilities |
| 173 | * supported by the firmware. |
| 174 | */ |
| 175 | @AudioCapabilities |
| 176 | public final int audioCapabilities; |
| 177 | |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 178 | ModuleProperties(int id, @NonNull String implementor, @NonNull String description, |
Nicholas Ambur | 38027cd | 2019-12-16 00:06:19 -0800 | [diff] [blame] | 179 | @NonNull String uuid, int version, @NonNull String supportedModelArch, |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 180 | int maxSoundModels, int maxKeyphrases, int maxUsers, |
| 181 | @RecognitionModes int recognitionModes, boolean supportsCaptureTransition, |
| 182 | int maxBufferMs, boolean supportsConcurrentCapture, int powerConsumptionMw, |
Nicholas Ambur | 7092a56 | 2019-12-16 11:18:55 -0800 | [diff] [blame] | 183 | boolean returnsTriggerInEvent, int audioCapabilities) { |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 184 | this.id = id; |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 185 | this.implementor = requireNonNull(implementor); |
| 186 | this.description = requireNonNull(description); |
| 187 | this.uuid = UUID.fromString(requireNonNull(uuid)); |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 188 | this.version = version; |
Nicholas Ambur | 38027cd | 2019-12-16 00:06:19 -0800 | [diff] [blame] | 189 | this.supportedModelArch = requireNonNull(supportedModelArch); |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 190 | this.maxSoundModels = maxSoundModels; |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 191 | this.maxKeyphrases = maxKeyphrases; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 192 | this.maxUsers = maxUsers; |
| 193 | this.recognitionModes = recognitionModes; |
| 194 | this.supportsCaptureTransition = supportsCaptureTransition; |
| 195 | this.maxBufferMs = maxBufferMs; |
| 196 | this.supportsConcurrentCapture = supportsConcurrentCapture; |
| 197 | this.powerConsumptionMw = powerConsumptionMw; |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 198 | this.returnsTriggerInEvent = returnsTriggerInEvent; |
Nicholas Ambur | 7092a56 | 2019-12-16 11:18:55 -0800 | [diff] [blame] | 199 | this.audioCapabilities = audioCapabilities; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 200 | } |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 201 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 202 | public static final @android.annotation.NonNull Parcelable.Creator<ModuleProperties> CREATOR |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 203 | = new Parcelable.Creator<ModuleProperties>() { |
| 204 | public ModuleProperties createFromParcel(Parcel in) { |
| 205 | return ModuleProperties.fromParcel(in); |
| 206 | } |
| 207 | |
| 208 | public ModuleProperties[] newArray(int size) { |
| 209 | return new ModuleProperties[size]; |
| 210 | } |
| 211 | }; |
| 212 | |
| 213 | private static ModuleProperties fromParcel(Parcel in) { |
| 214 | int id = in.readInt(); |
| 215 | String implementor = in.readString(); |
| 216 | String description = in.readString(); |
| 217 | String uuid = in.readString(); |
| 218 | int version = in.readInt(); |
Nicholas Ambur | 38027cd | 2019-12-16 00:06:19 -0800 | [diff] [blame] | 219 | String supportedModelArch = in.readString(); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 220 | int maxSoundModels = in.readInt(); |
| 221 | int maxKeyphrases = in.readInt(); |
| 222 | int maxUsers = in.readInt(); |
| 223 | int recognitionModes = in.readInt(); |
| 224 | boolean supportsCaptureTransition = in.readByte() == 1; |
| 225 | int maxBufferMs = in.readInt(); |
| 226 | boolean supportsConcurrentCapture = in.readByte() == 1; |
| 227 | int powerConsumptionMw = in.readInt(); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 228 | boolean returnsTriggerInEvent = in.readByte() == 1; |
Nicholas Ambur | 7092a56 | 2019-12-16 11:18:55 -0800 | [diff] [blame] | 229 | int audioCapabilities = in.readInt(); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 230 | return new ModuleProperties(id, implementor, description, uuid, version, |
Nicholas Ambur | 38027cd | 2019-12-16 00:06:19 -0800 | [diff] [blame] | 231 | supportedModelArch, maxSoundModels, maxKeyphrases, maxUsers, recognitionModes, |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 232 | supportsCaptureTransition, maxBufferMs, supportsConcurrentCapture, |
Nicholas Ambur | 7092a56 | 2019-12-16 11:18:55 -0800 | [diff] [blame] | 233 | powerConsumptionMw, returnsTriggerInEvent, audioCapabilities); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | @Override |
| 237 | public void writeToParcel(Parcel dest, int flags) { |
| 238 | dest.writeInt(id); |
| 239 | dest.writeString(implementor); |
| 240 | dest.writeString(description); |
| 241 | dest.writeString(uuid.toString()); |
| 242 | dest.writeInt(version); |
Nicholas Ambur | 38027cd | 2019-12-16 00:06:19 -0800 | [diff] [blame] | 243 | dest.writeString(supportedModelArch); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 244 | dest.writeInt(maxSoundModels); |
| 245 | dest.writeInt(maxKeyphrases); |
| 246 | dest.writeInt(maxUsers); |
| 247 | dest.writeInt(recognitionModes); |
| 248 | dest.writeByte((byte) (supportsCaptureTransition ? 1 : 0)); |
| 249 | dest.writeInt(maxBufferMs); |
| 250 | dest.writeByte((byte) (supportsConcurrentCapture ? 1 : 0)); |
| 251 | dest.writeInt(powerConsumptionMw); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 252 | dest.writeByte((byte) (returnsTriggerInEvent ? 1 : 0)); |
Nicholas Ambur | 7092a56 | 2019-12-16 11:18:55 -0800 | [diff] [blame] | 253 | dest.writeInt(audioCapabilities); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | @Override |
| 257 | public int describeContents() { |
| 258 | return 0; |
| 259 | } |
| 260 | |
| 261 | @Override |
| 262 | public String toString() { |
| 263 | return "ModuleProperties [id=" + id + ", implementor=" + implementor + ", description=" |
Nicholas Ambur | 38027cd | 2019-12-16 00:06:19 -0800 | [diff] [blame] | 264 | + description + ", uuid=" + uuid + ", version=" + version |
| 265 | + " , supportedModelArch=" + supportedModelArch + ", maxSoundModels=" |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 266 | + maxSoundModels + ", maxKeyphrases=" + maxKeyphrases + ", maxUsers=" |
| 267 | + maxUsers + ", recognitionModes=" + recognitionModes |
| 268 | + ", supportsCaptureTransition=" + supportsCaptureTransition + ", maxBufferMs=" |
| 269 | + maxBufferMs + ", supportsConcurrentCapture=" + supportsConcurrentCapture |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 270 | + ", powerConsumptionMw=" + powerConsumptionMw |
Nicholas Ambur | 7092a56 | 2019-12-16 11:18:55 -0800 | [diff] [blame] | 271 | + ", returnsTriggerInEvent=" + returnsTriggerInEvent |
| 272 | + ", audioCapabilities=" + audioCapabilities + "]"; |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 273 | } |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 276 | /** |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 277 | * A SoundModel describes the attributes and contains the binary data used by the hardware |
| 278 | * implementation to detect a particular sound pattern. |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 279 | * A specialized version {@link KeyphraseSoundModel} is defined for key phrase |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 280 | * sound models. |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 281 | */ |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 282 | public static class SoundModel { |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 283 | |
| 284 | /** @hide */ |
| 285 | @Retention(RetentionPolicy.SOURCE) |
| 286 | @IntDef({ |
| 287 | TYPE_GENERIC_SOUND, |
| 288 | TYPE_KEYPHRASE, |
| 289 | TYPE_UNKNOWN, |
| 290 | }) |
| 291 | public @interface SoundModelType {} |
| 292 | |
| 293 | /** |
| 294 | * Undefined sound model type |
| 295 | * @hide |
| 296 | */ |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 297 | public static final int TYPE_UNKNOWN = -1; |
| 298 | |
| 299 | /** Keyphrase sound model */ |
| 300 | public static final int TYPE_KEYPHRASE = 0; |
| 301 | |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 302 | /** |
| 303 | * A generic sound model. Use this type only for non-keyphrase sound models such as |
| 304 | * ones that match a particular sound pattern. |
| 305 | */ |
| 306 | public static final int TYPE_GENERIC_SOUND = 1; |
| 307 | |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 308 | /** Unique sound model identifier */ |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 309 | @NonNull |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 310 | public final UUID uuid; |
| 311 | |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 312 | /** Sound model type (e.g. TYPE_KEYPHRASE); */ |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 313 | @SoundModelType |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 314 | public final int type; |
| 315 | |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 316 | /** Unique sound model vendor identifier */ |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 317 | @NonNull |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 318 | public final UUID vendorUuid; |
| 319 | |
Nicholas Ambur | d3ec82f | 2020-01-03 17:44:19 -0800 | [diff] [blame] | 320 | /** vendor specific version number of the model */ |
| 321 | public final int version; |
| 322 | |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 323 | /** Opaque data. For use by vendor implementation and enrollment application */ |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 324 | @NonNull |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 325 | public final byte[] data; |
| 326 | |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 327 | /** @hide */ |
| 328 | public SoundModel(@NonNull UUID uuid, @Nullable UUID vendorUuid, @SoundModelType int type, |
Nicholas Ambur | d3ec82f | 2020-01-03 17:44:19 -0800 | [diff] [blame] | 329 | @Nullable byte[] data, int version) { |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 330 | this.uuid = requireNonNull(uuid); |
| 331 | this.vendorUuid = vendorUuid != null ? vendorUuid : new UUID(0, 0); |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 332 | this.type = type; |
Nicholas Ambur | d3ec82f | 2020-01-03 17:44:19 -0800 | [diff] [blame] | 333 | this.version = version; |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 334 | this.data = data != null ? data : new byte[0]; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 335 | } |
Sandeep Siddhartha | 45c00b5 | 2014-10-16 16:17:11 -0700 | [diff] [blame] | 336 | |
| 337 | @Override |
| 338 | public int hashCode() { |
| 339 | final int prime = 31; |
| 340 | int result = 1; |
Nicholas Ambur | d3ec82f | 2020-01-03 17:44:19 -0800 | [diff] [blame] | 341 | result = prime * result + version; |
Sandeep Siddhartha | 45c00b5 | 2014-10-16 16:17:11 -0700 | [diff] [blame] | 342 | result = prime * result + Arrays.hashCode(data); |
| 343 | result = prime * result + type; |
| 344 | result = prime * result + ((uuid == null) ? 0 : uuid.hashCode()); |
| 345 | result = prime * result + ((vendorUuid == null) ? 0 : vendorUuid.hashCode()); |
| 346 | return result; |
| 347 | } |
| 348 | |
| 349 | @Override |
| 350 | public boolean equals(Object obj) { |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 351 | if (this == obj) { |
Sandeep Siddhartha | 45c00b5 | 2014-10-16 16:17:11 -0700 | [diff] [blame] | 352 | return true; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 353 | } |
| 354 | if (obj == null) { |
Sandeep Siddhartha | 45c00b5 | 2014-10-16 16:17:11 -0700 | [diff] [blame] | 355 | return false; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 356 | } |
| 357 | if (!(obj instanceof SoundModel)) { |
Sandeep Siddhartha | 45c00b5 | 2014-10-16 16:17:11 -0700 | [diff] [blame] | 358 | return false; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 359 | } |
Sandeep Siddhartha | 45c00b5 | 2014-10-16 16:17:11 -0700 | [diff] [blame] | 360 | SoundModel other = (SoundModel) obj; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 361 | if (type != other.type) { |
Sandeep Siddhartha | 45c00b5 | 2014-10-16 16:17:11 -0700 | [diff] [blame] | 362 | return false; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 363 | } |
Sandeep Siddhartha | 45c00b5 | 2014-10-16 16:17:11 -0700 | [diff] [blame] | 364 | if (uuid == null) { |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 365 | if (other.uuid != null) { |
Sandeep Siddhartha | 45c00b5 | 2014-10-16 16:17:11 -0700 | [diff] [blame] | 366 | return false; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 367 | } |
| 368 | } else if (!uuid.equals(other.uuid)) { |
Sandeep Siddhartha | 45c00b5 | 2014-10-16 16:17:11 -0700 | [diff] [blame] | 369 | return false; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 370 | } |
Sandeep Siddhartha | 45c00b5 | 2014-10-16 16:17:11 -0700 | [diff] [blame] | 371 | if (vendorUuid == null) { |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 372 | if (other.vendorUuid != null) { |
Sandeep Siddhartha | 45c00b5 | 2014-10-16 16:17:11 -0700 | [diff] [blame] | 373 | return false; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 374 | } |
| 375 | } else if (!vendorUuid.equals(other.vendorUuid)) { |
Sandeep Siddhartha | 45c00b5 | 2014-10-16 16:17:11 -0700 | [diff] [blame] | 376 | return false; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 377 | } |
| 378 | if (!Arrays.equals(data, other.data)) { |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 379 | return false; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 380 | } |
| 381 | if (version != other.version) { |
Nicholas Ambur | d3ec82f | 2020-01-03 17:44:19 -0800 | [diff] [blame] | 382 | return false; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 383 | } |
Sandeep Siddhartha | 45c00b5 | 2014-10-16 16:17:11 -0700 | [diff] [blame] | 384 | return true; |
| 385 | } |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 388 | /** |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 389 | * A Keyphrase describes a key phrase that can be detected by a |
| 390 | * {@link KeyphraseSoundModel} |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 391 | */ |
| 392 | public static final class Keyphrase implements Parcelable { |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 393 | /** Unique identifier for this keyphrase */ |
| 394 | public final int id; |
| 395 | |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 396 | /** |
| 397 | * Recognition modes supported for this key phrase in the model |
| 398 | * |
| 399 | * @see #RECOGNITION_MODE_VOICE_TRIGGER |
| 400 | * @see #RECOGNITION_MODE_USER_IDENTIFICATION |
| 401 | * @see #RECOGNITION_MODE_USER_AUTHENTICATION |
| 402 | * @see #RECOGNITION_MODE_GENERIC |
| 403 | */ |
| 404 | @RecognitionModes |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 405 | public final int recognitionModes; |
| 406 | |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 407 | /** Locale of the keyphrase. */ |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 408 | @NonNull |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 409 | public final Locale locale; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 410 | |
| 411 | /** Key phrase text */ |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 412 | @NonNull |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 413 | public final String text; |
| 414 | |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 415 | /** |
| 416 | * Users this key phrase has been trained for. countains sound trigger specific user IDs |
| 417 | * derived from system user IDs {@link android.os.UserHandle#getIdentifier()}. |
| 418 | */ |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 419 | @NonNull |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 420 | public final int[] users; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 421 | |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 422 | /** |
| 423 | * Constructor for Keyphrase describes a key phrase that can be detected by a |
| 424 | * {@link KeyphraseSoundModel} |
| 425 | * |
| 426 | * @param id Unique keyphrase identifier for this keyphrase |
| 427 | * @param recognitionModes Bit field representation of recognition modes this keyphrase |
| 428 | * supports |
| 429 | * @param locale Locale of the keyphrase |
| 430 | * @param text Key phrase text |
| 431 | * @param users Users this key phrase has been trained for. |
| 432 | */ |
| 433 | public Keyphrase(int id, @RecognitionModes int recognitionModes, @NonNull Locale locale, |
| 434 | @NonNull String text, @Nullable int[] users) { |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 435 | this.id = id; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 436 | this.recognitionModes = recognitionModes; |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 437 | this.locale = requireNonNull(locale); |
| 438 | this.text = requireNonNull(text); |
| 439 | this.users = users != null ? users : new int[0]; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 440 | } |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 441 | |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 442 | public static final @NonNull Parcelable.Creator<Keyphrase> CREATOR = |
| 443 | new Parcelable.Creator<Keyphrase>() { |
| 444 | @NonNull |
| 445 | public Keyphrase createFromParcel(@NonNull Parcel in) { |
| 446 | return Keyphrase.readFromParcel(in); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 449 | @NonNull |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 450 | public Keyphrase[] newArray(int size) { |
| 451 | return new Keyphrase[size]; |
| 452 | } |
| 453 | }; |
| 454 | |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 455 | /** |
| 456 | * Read from Parcel to generate keyphrase |
| 457 | */ |
| 458 | @NonNull |
| 459 | public static Keyphrase readFromParcel(@NonNull Parcel in) { |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 460 | int id = in.readInt(); |
| 461 | int recognitionModes = in.readInt(); |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 462 | Locale locale = Locale.forLanguageTag(in.readString()); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 463 | String text = in.readString(); |
| 464 | int[] users = null; |
| 465 | int numUsers = in.readInt(); |
Sandeep Siddhartha | 110f569 | 2014-07-20 12:22:56 -0700 | [diff] [blame] | 466 | if (numUsers >= 0) { |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 467 | users = new int[numUsers]; |
| 468 | in.readIntArray(users); |
| 469 | } |
| 470 | return new Keyphrase(id, recognitionModes, locale, text, users); |
| 471 | } |
| 472 | |
| 473 | @Override |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 474 | public void writeToParcel(@NonNull Parcel dest, int flags) { |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 475 | dest.writeInt(id); |
| 476 | dest.writeInt(recognitionModes); |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 477 | dest.writeString(locale.toLanguageTag()); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 478 | dest.writeString(text); |
| 479 | if (users != null) { |
| 480 | dest.writeInt(users.length); |
| 481 | dest.writeIntArray(users); |
| 482 | } else { |
Sandeep Siddhartha | 110f569 | 2014-07-20 12:22:56 -0700 | [diff] [blame] | 483 | dest.writeInt(-1); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 484 | } |
| 485 | } |
| 486 | |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 487 | /** @hide */ |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 488 | @Override |
| 489 | public int describeContents() { |
| 490 | return 0; |
| 491 | } |
| 492 | |
| 493 | @Override |
| 494 | public int hashCode() { |
| 495 | final int prime = 31; |
| 496 | int result = 1; |
| 497 | result = prime * result + ((text == null) ? 0 : text.hashCode()); |
| 498 | result = prime * result + id; |
| 499 | result = prime * result + ((locale == null) ? 0 : locale.hashCode()); |
| 500 | result = prime * result + recognitionModes; |
| 501 | result = prime * result + Arrays.hashCode(users); |
| 502 | return result; |
| 503 | } |
| 504 | |
| 505 | @Override |
| 506 | public boolean equals(Object obj) { |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 507 | if (this == obj) { |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 508 | return true; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 509 | } |
| 510 | if (obj == null) { |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 511 | return false; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 512 | } |
| 513 | if (getClass() != obj.getClass()) { |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 514 | return false; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 515 | } |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 516 | Keyphrase other = (Keyphrase) obj; |
| 517 | if (text == null) { |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 518 | if (other.text != null) { |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 519 | return false; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 520 | } |
| 521 | } else if (!text.equals(other.text)) { |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 522 | return false; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 523 | } |
| 524 | if (id != other.id) { |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 525 | return false; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 526 | } |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 527 | if (locale == null) { |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 528 | if (other.locale != null) { |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 529 | return false; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 530 | } |
| 531 | } else if (!locale.equals(other.locale)) { |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 532 | return false; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 533 | } |
| 534 | if (recognitionModes != other.recognitionModes) { |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 535 | return false; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 536 | } |
| 537 | if (!Arrays.equals(users, other.users)) { |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 538 | return false; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 539 | } |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 540 | return true; |
| 541 | } |
| 542 | |
| 543 | @Override |
| 544 | public String toString() { |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 545 | return "Keyphrase [id=" + id + ", recognitionModes=" + recognitionModes |
| 546 | + ", locale=" + locale.toLanguageTag() + ", text=" + text |
| 547 | + ", users=" + Arrays.toString(users) + "]"; |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 548 | } |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 549 | } |
| 550 | |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 551 | /** |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 552 | * A KeyphraseSoundModel is a specialized {@link SoundModel} for key phrases. |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 553 | * It contains data needed by the hardware to detect a certain number of key phrases |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 554 | * and the list of corresponding {@link Keyphrase} descriptors. |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 555 | */ |
| 556 | public static final class KeyphraseSoundModel extends SoundModel implements Parcelable { |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 557 | /** Key phrases in this sound model */ |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 558 | @NonNull |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 559 | public final Keyphrase[] keyphrases; // keyword phrases in model |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 560 | |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 561 | public KeyphraseSoundModel( |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 562 | @NonNull UUID uuid, @NonNull UUID vendorUuid, @Nullable byte[] data, |
Nicholas Ambur | d3ec82f | 2020-01-03 17:44:19 -0800 | [diff] [blame] | 563 | @Nullable Keyphrase[] keyphrases, int version) { |
| 564 | super(uuid, vendorUuid, TYPE_KEYPHRASE, data, version); |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 565 | this.keyphrases = keyphrases != null ? keyphrases : new Keyphrase[0]; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 566 | } |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 567 | |
Nicholas Ambur | d3ec82f | 2020-01-03 17:44:19 -0800 | [diff] [blame] | 568 | public KeyphraseSoundModel(@NonNull UUID uuid, @NonNull UUID vendorUuid, |
| 569 | @Nullable byte[] data, @Nullable Keyphrase[] keyphrases) { |
| 570 | this(uuid, vendorUuid, data, keyphrases, -1); |
| 571 | } |
| 572 | |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 573 | public static final @NonNull Parcelable.Creator<KeyphraseSoundModel> CREATOR = |
| 574 | new Parcelable.Creator<KeyphraseSoundModel>() { |
| 575 | @NonNull |
| 576 | public KeyphraseSoundModel createFromParcel(@NonNull Parcel in) { |
| 577 | return KeyphraseSoundModel.readFromParcel(in); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 580 | @NonNull |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 581 | public KeyphraseSoundModel[] newArray(int size) { |
| 582 | return new KeyphraseSoundModel[size]; |
| 583 | } |
| 584 | }; |
| 585 | |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 586 | /** |
| 587 | * Read from Parcel to generate KeyphraseSoundModel |
| 588 | */ |
| 589 | @NonNull |
| 590 | public static KeyphraseSoundModel readFromParcel(@NonNull Parcel in) { |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 591 | UUID uuid = UUID.fromString(in.readString()); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 592 | UUID vendorUuid = null; |
| 593 | int length = in.readInt(); |
| 594 | if (length >= 0) { |
| 595 | vendorUuid = UUID.fromString(in.readString()); |
| 596 | } |
Nicholas Ambur | d3ec82f | 2020-01-03 17:44:19 -0800 | [diff] [blame] | 597 | int version = in.readInt(); |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 598 | byte[] data = in.readBlob(); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 599 | Keyphrase[] keyphrases = in.createTypedArray(Keyphrase.CREATOR); |
Nicholas Ambur | d3ec82f | 2020-01-03 17:44:19 -0800 | [diff] [blame] | 600 | return new KeyphraseSoundModel(uuid, vendorUuid, data, keyphrases, version); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 601 | } |
| 602 | |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 603 | /** @hide */ |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 604 | @Override |
| 605 | public int describeContents() { |
| 606 | return 0; |
| 607 | } |
| 608 | |
| 609 | @Override |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 610 | public void writeToParcel(@NonNull Parcel dest, int flags) { |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 611 | dest.writeString(uuid.toString()); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 612 | if (vendorUuid == null) { |
| 613 | dest.writeInt(-1); |
| 614 | } else { |
| 615 | dest.writeInt(vendorUuid.toString().length()); |
| 616 | dest.writeString(vendorUuid.toString()); |
| 617 | } |
Nicholas Ambur | 43970b5 | 2020-01-14 18:54:26 -0800 | [diff] [blame] | 618 | dest.writeInt(version); |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 619 | dest.writeBlob(data); |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 620 | dest.writeTypedArray(keyphrases, flags); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 621 | } |
Sandeep Siddhartha | 110f569 | 2014-07-20 12:22:56 -0700 | [diff] [blame] | 622 | |
| 623 | @Override |
| 624 | public String toString() { |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 625 | return "KeyphraseSoundModel [keyphrases=" + Arrays.toString(keyphrases) |
| 626 | + ", uuid=" + uuid + ", vendorUuid=" + vendorUuid |
Nicholas Ambur | d3ec82f | 2020-01-03 17:44:19 -0800 | [diff] [blame] | 627 | + ", type=" + type |
| 628 | + ", data=" + (data == null ? 0 : data.length) |
| 629 | + ", version=" + version + "]"; |
Sandeep Siddhartha | 110f569 | 2014-07-20 12:22:56 -0700 | [diff] [blame] | 630 | } |
Sandeep Siddhartha | 45c00b5 | 2014-10-16 16:17:11 -0700 | [diff] [blame] | 631 | |
| 632 | @Override |
| 633 | public int hashCode() { |
| 634 | final int prime = 31; |
| 635 | int result = super.hashCode(); |
| 636 | result = prime * result + Arrays.hashCode(keyphrases); |
| 637 | return result; |
| 638 | } |
| 639 | |
| 640 | @Override |
| 641 | public boolean equals(Object obj) { |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 642 | if (this == obj) { |
Sandeep Siddhartha | 45c00b5 | 2014-10-16 16:17:11 -0700 | [diff] [blame] | 643 | return true; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 644 | } |
| 645 | if (!super.equals(obj)) { |
Sandeep Siddhartha | 45c00b5 | 2014-10-16 16:17:11 -0700 | [diff] [blame] | 646 | return false; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 647 | } |
| 648 | if (!(obj instanceof KeyphraseSoundModel)) { |
Sandeep Siddhartha | 45c00b5 | 2014-10-16 16:17:11 -0700 | [diff] [blame] | 649 | return false; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 650 | } |
Sandeep Siddhartha | 45c00b5 | 2014-10-16 16:17:11 -0700 | [diff] [blame] | 651 | KeyphraseSoundModel other = (KeyphraseSoundModel) obj; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 652 | if (!Arrays.equals(keyphrases, other.keyphrases)) { |
Sandeep Siddhartha | 45c00b5 | 2014-10-16 16:17:11 -0700 | [diff] [blame] | 653 | return false; |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 654 | } |
Sandeep Siddhartha | 45c00b5 | 2014-10-16 16:17:11 -0700 | [diff] [blame] | 655 | return true; |
| 656 | } |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 657 | } |
| 658 | |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 659 | |
| 660 | /***************************************************************************** |
| 661 | * A GenericSoundModel is a specialized {@link SoundModel} for non-voice sound |
| 662 | * patterns. |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 663 | * |
| 664 | * @hide |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 665 | ****************************************************************************/ |
| 666 | public static class GenericSoundModel extends SoundModel implements Parcelable { |
| 667 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 668 | public static final @android.annotation.NonNull Parcelable.Creator<GenericSoundModel> CREATOR |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 669 | = new Parcelable.Creator<GenericSoundModel>() { |
| 670 | public GenericSoundModel createFromParcel(Parcel in) { |
| 671 | return GenericSoundModel.fromParcel(in); |
| 672 | } |
| 673 | |
| 674 | public GenericSoundModel[] newArray(int size) { |
| 675 | return new GenericSoundModel[size]; |
| 676 | } |
| 677 | }; |
| 678 | |
Nicholas Ambur | d3ec82f | 2020-01-03 17:44:19 -0800 | [diff] [blame] | 679 | public GenericSoundModel(@NonNull UUID uuid, @NonNull UUID vendorUuid, |
| 680 | @Nullable byte[] data, int version) { |
| 681 | super(uuid, vendorUuid, TYPE_GENERIC_SOUND, data, version); |
| 682 | } |
| 683 | |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 684 | @UnsupportedAppUsage |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 685 | public GenericSoundModel(@NonNull UUID uuid, @NonNull UUID vendorUuid, |
| 686 | @Nullable byte[] data) { |
Nicholas Ambur | d3ec82f | 2020-01-03 17:44:19 -0800 | [diff] [blame] | 687 | this(uuid, vendorUuid, data, -1); |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | @Override |
| 691 | public int describeContents() { |
| 692 | return 0; |
| 693 | } |
| 694 | |
| 695 | private static GenericSoundModel fromParcel(Parcel in) { |
| 696 | UUID uuid = UUID.fromString(in.readString()); |
| 697 | UUID vendorUuid = null; |
| 698 | int length = in.readInt(); |
| 699 | if (length >= 0) { |
| 700 | vendorUuid = UUID.fromString(in.readString()); |
| 701 | } |
| 702 | byte[] data = in.readBlob(); |
Nicholas Ambur | d3ec82f | 2020-01-03 17:44:19 -0800 | [diff] [blame] | 703 | int version = in.readInt(); |
| 704 | return new GenericSoundModel(uuid, vendorUuid, data, version); |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | @Override |
| 708 | public void writeToParcel(Parcel dest, int flags) { |
| 709 | dest.writeString(uuid.toString()); |
| 710 | if (vendorUuid == null) { |
| 711 | dest.writeInt(-1); |
| 712 | } else { |
| 713 | dest.writeInt(vendorUuid.toString().length()); |
| 714 | dest.writeString(vendorUuid.toString()); |
| 715 | } |
| 716 | dest.writeBlob(data); |
Nicholas Ambur | d3ec82f | 2020-01-03 17:44:19 -0800 | [diff] [blame] | 717 | dest.writeInt(version); |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | @Override |
| 721 | public String toString() { |
| 722 | return "GenericSoundModel [uuid=" + uuid + ", vendorUuid=" + vendorUuid |
Nicholas Ambur | d3ec82f | 2020-01-03 17:44:19 -0800 | [diff] [blame] | 723 | + ", type=" + type |
| 724 | + ", data=" + (data == null ? 0 : data.length) |
| 725 | + ", version=" + version + "]"; |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 726 | } |
| 727 | } |
| 728 | |
Nicholas Ambur | f94db1c | 2019-12-08 19:04:06 -0800 | [diff] [blame] | 729 | /** |
Nicholas Ambur | a0be6be | 2019-10-01 10:11:39 -0700 | [diff] [blame] | 730 | * A ModelParamRange is a representation of supported parameter range for a |
| 731 | * given loaded model. |
Nicholas Ambur | f94db1c | 2019-12-08 19:04:06 -0800 | [diff] [blame] | 732 | */ |
Nicholas Ambur | a0be6be | 2019-10-01 10:11:39 -0700 | [diff] [blame] | 733 | public static final class ModelParamRange implements Parcelable { |
| 734 | |
| 735 | /** |
Nicholas Ambur | f94db1c | 2019-12-08 19:04:06 -0800 | [diff] [blame] | 736 | * The inclusive start of supported range. |
Nicholas Ambur | a0be6be | 2019-10-01 10:11:39 -0700 | [diff] [blame] | 737 | */ |
| 738 | public final int start; |
| 739 | |
| 740 | /** |
Nicholas Ambur | f94db1c | 2019-12-08 19:04:06 -0800 | [diff] [blame] | 741 | * The inclusive end of supported range. |
Nicholas Ambur | a0be6be | 2019-10-01 10:11:39 -0700 | [diff] [blame] | 742 | */ |
| 743 | public final int end; |
| 744 | |
| 745 | ModelParamRange(int start, int end) { |
| 746 | this.start = start; |
| 747 | this.end = end; |
| 748 | } |
| 749 | |
Nicholas Ambur | f94db1c | 2019-12-08 19:04:06 -0800 | [diff] [blame] | 750 | /** @hide */ |
Nicholas Ambur | a0be6be | 2019-10-01 10:11:39 -0700 | [diff] [blame] | 751 | private ModelParamRange(@NonNull Parcel in) { |
| 752 | this.start = in.readInt(); |
| 753 | this.end = in.readInt(); |
| 754 | } |
| 755 | |
| 756 | @NonNull |
Nicholas Ambur | f94db1c | 2019-12-08 19:04:06 -0800 | [diff] [blame] | 757 | public static final Creator<ModelParamRange> CREATOR = |
| 758 | new Creator<ModelParamRange>() { |
| 759 | @Override |
| 760 | @NonNull |
| 761 | public ModelParamRange createFromParcel(@NonNull Parcel in) { |
| 762 | return new ModelParamRange(in); |
| 763 | } |
Nicholas Ambur | a0be6be | 2019-10-01 10:11:39 -0700 | [diff] [blame] | 764 | |
Nicholas Ambur | f94db1c | 2019-12-08 19:04:06 -0800 | [diff] [blame] | 765 | @Override |
| 766 | @NonNull |
| 767 | public ModelParamRange[] newArray(int size) { |
| 768 | return new ModelParamRange[size]; |
| 769 | } |
| 770 | }; |
Nicholas Ambur | a0be6be | 2019-10-01 10:11:39 -0700 | [diff] [blame] | 771 | |
Nicholas Ambur | f94db1c | 2019-12-08 19:04:06 -0800 | [diff] [blame] | 772 | /** @hide */ |
Nicholas Ambur | a0be6be | 2019-10-01 10:11:39 -0700 | [diff] [blame] | 773 | @Override |
| 774 | public int describeContents() { |
| 775 | return 0; |
| 776 | } |
| 777 | |
Nicholas Ambur | f94db1c | 2019-12-08 19:04:06 -0800 | [diff] [blame] | 778 | /** @hide */ |
| 779 | @Override |
| 780 | public int hashCode() { |
| 781 | final int prime = 31; |
| 782 | int result = 1; |
| 783 | result = prime * result + (start); |
| 784 | result = prime * result + (end); |
| 785 | return result; |
| 786 | } |
| 787 | |
| 788 | @Override |
| 789 | public boolean equals(@Nullable Object obj) { |
| 790 | if (this == obj) { |
| 791 | return true; |
| 792 | } |
| 793 | if (obj == null) { |
| 794 | return false; |
| 795 | } |
| 796 | if (getClass() != obj.getClass()) { |
| 797 | return false; |
| 798 | } |
| 799 | ModelParamRange other = (ModelParamRange) obj; |
| 800 | if (start != other.start) { |
| 801 | return false; |
| 802 | } |
| 803 | if (end != other.end) { |
| 804 | return false; |
| 805 | } |
| 806 | return true; |
| 807 | } |
| 808 | |
Nicholas Ambur | a0be6be | 2019-10-01 10:11:39 -0700 | [diff] [blame] | 809 | @Override |
| 810 | public void writeToParcel(@NonNull Parcel dest, int flags) { |
| 811 | dest.writeInt(start); |
| 812 | dest.writeInt(end); |
| 813 | } |
| 814 | |
| 815 | @Override |
| 816 | @NonNull |
| 817 | public String toString() { |
| 818 | return "ModelParamRange [start=" + start + ", end=" + end + "]"; |
| 819 | } |
| 820 | } |
| 821 | |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 822 | /** |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 823 | * Modes for key phrase recognition |
| 824 | * @hide |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 825 | */ |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 826 | @Retention(RetentionPolicy.SOURCE) |
| 827 | @IntDef(flag = true, prefix = { "RECOGNITION_MODE_" }, value = { |
| 828 | RECOGNITION_MODE_VOICE_TRIGGER, |
| 829 | RECOGNITION_MODE_USER_IDENTIFICATION, |
| 830 | RECOGNITION_MODE_USER_AUTHENTICATION, |
| 831 | RECOGNITION_MODE_GENERIC |
| 832 | }) |
| 833 | public @interface RecognitionModes {} |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 834 | |
| 835 | /** |
Nicholas Ambur | ef84fc4 | 2020-01-14 20:28:37 -0800 | [diff] [blame^] | 836 | * Trigger on recognition of a key phrase |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 837 | */ |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 838 | public static final int RECOGNITION_MODE_VOICE_TRIGGER = 0x1; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 839 | /** |
| 840 | * Trigger only if one user is identified |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 841 | */ |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 842 | public static final int RECOGNITION_MODE_USER_IDENTIFICATION = 0x2; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 843 | /** |
| 844 | * Trigger only if one user is authenticated |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 845 | */ |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 846 | public static final int RECOGNITION_MODE_USER_AUTHENTICATION = 0x4; |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 847 | /** |
| 848 | * Generic (non-speech) recognition. |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 849 | */ |
| 850 | public static final int RECOGNITION_MODE_GENERIC = 0x8; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 851 | |
| 852 | /** |
| 853 | * Status codes for {@link RecognitionEvent} |
| 854 | */ |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 855 | /** |
| 856 | * Recognition success |
| 857 | * |
| 858 | * @hide |
| 859 | */ |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 860 | public static final int RECOGNITION_STATUS_SUCCESS = 0; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 861 | /** |
| 862 | * Recognition aborted (e.g. capture preempted by anotehr use case |
| 863 | * |
| 864 | * @hide |
| 865 | */ |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 866 | public static final int RECOGNITION_STATUS_ABORT = 1; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 867 | /** |
| 868 | * Recognition failure |
| 869 | * |
| 870 | * @hide |
| 871 | */ |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 872 | public static final int RECOGNITION_STATUS_FAILURE = 2; |
mike dooley | b2ab04a | 2018-11-07 15:48:54 +0100 | [diff] [blame] | 873 | /** |
| 874 | * Recognition event was triggered by a getModelState request, not by the |
| 875 | * DSP. |
| 876 | * |
| 877 | * @hide |
| 878 | */ |
| 879 | public static final int RECOGNITION_STATUS_GET_STATE_RESPONSE = 3; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 880 | |
| 881 | /** |
| 882 | * A RecognitionEvent is provided by the |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 883 | * {@code StatusListener#onRecognition(RecognitionEvent)} |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 884 | * callback upon recognition success or failure. |
| 885 | */ |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 886 | public static class RecognitionEvent { |
| 887 | /** |
| 888 | * Recognition status e.g RECOGNITION_STATUS_SUCCESS |
| 889 | * |
| 890 | * @hide |
| 891 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 892 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 893 | public final int status; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 894 | /** |
| 895 | * |
| 896 | * Sound Model corresponding to this event callback |
| 897 | * |
| 898 | * @hide |
| 899 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 900 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 901 | public final int soundModelHandle; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 902 | /** |
| 903 | * True if it is possible to capture audio from this utterance buffered by the hardware |
| 904 | * |
| 905 | * @hide |
| 906 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 907 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 908 | public final boolean captureAvailable; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 909 | /** |
| 910 | * Audio session ID to be used when capturing the utterance with an AudioRecord |
| 911 | * if captureAvailable() is true. |
| 912 | * |
| 913 | * @hide |
| 914 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 915 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 916 | public final int captureSession; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 917 | /** |
| 918 | * Delay in ms between end of model detection and start of audio available for capture. |
| 919 | * A negative value is possible (e.g. if keyphrase is also available for capture) |
| 920 | * |
| 921 | * @hide |
| 922 | */ |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 923 | public final int captureDelayMs; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 924 | /** |
| 925 | * Duration in ms of audio captured before the start of the trigger. 0 if none. |
| 926 | * |
| 927 | * @hide |
| 928 | */ |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 929 | public final int capturePreambleMs; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 930 | /** |
| 931 | * True if the trigger (key phrase capture is present in binary data |
| 932 | * |
| 933 | * @hide |
| 934 | */ |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 935 | public final boolean triggerInData; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 936 | /** |
| 937 | * Audio format of either the trigger in event data or to use for capture of the |
| 938 | * rest of the utterance |
| 939 | * |
| 940 | * @hide |
| 941 | */ |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 942 | @NonNull |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 943 | public final AudioFormat captureFormat; |
| 944 | /** |
| 945 | * Opaque data for use by system applications who know about voice engine internals, |
| 946 | * typically during enrollment. |
| 947 | * |
| 948 | * @hide |
| 949 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 950 | @UnsupportedAppUsage |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 951 | @NonNull |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 952 | public final byte[] data; |
| 953 | |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 954 | /** @hide */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 955 | @UnsupportedAppUsage |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 956 | public RecognitionEvent(int status, int soundModelHandle, boolean captureAvailable, |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 957 | int captureSession, int captureDelayMs, int capturePreambleMs, |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 958 | boolean triggerInData, @NonNull AudioFormat captureFormat, @Nullable byte[] data) { |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 959 | this.status = status; |
| 960 | this.soundModelHandle = soundModelHandle; |
| 961 | this.captureAvailable = captureAvailable; |
| 962 | this.captureSession = captureSession; |
| 963 | this.captureDelayMs = captureDelayMs; |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 964 | this.capturePreambleMs = capturePreambleMs; |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 965 | this.triggerInData = triggerInData; |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 966 | this.captureFormat = requireNonNull(captureFormat); |
| 967 | this.data = data != null ? data : new byte[0]; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 968 | } |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 969 | |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 970 | /** |
| 971 | * Check if is possible to capture audio from this utterance buffered by the hardware. |
| 972 | * |
| 973 | * @return {@code true} iff a capturing is possible |
| 974 | */ |
| 975 | public boolean isCaptureAvailable() { |
| 976 | return captureAvailable; |
| 977 | } |
| 978 | |
| 979 | /** |
| 980 | * Get the audio format of either the trigger in event data or to use for capture of the |
| 981 | * rest of the utterance |
| 982 | * |
| 983 | * @return the audio format |
| 984 | */ |
| 985 | @Nullable public AudioFormat getCaptureFormat() { |
| 986 | return captureFormat; |
| 987 | } |
| 988 | |
| 989 | /** |
| 990 | * Get Audio session ID to be used when capturing the utterance with an {@link AudioRecord} |
| 991 | * if {@link #isCaptureAvailable()} is true. |
| 992 | * |
| 993 | * @return The id of the capture session |
| 994 | */ |
| 995 | public int getCaptureSession() { |
| 996 | return captureSession; |
| 997 | } |
| 998 | |
| 999 | /** |
| 1000 | * Get the opaque data for use by system applications who know about voice engine |
| 1001 | * internals, typically during enrollment. |
| 1002 | * |
| 1003 | * @return The data of the event |
| 1004 | */ |
| 1005 | public byte[] getData() { |
| 1006 | return data; |
| 1007 | } |
| 1008 | |
| 1009 | /** @hide */ |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 1010 | public static final @android.annotation.NonNull Parcelable.Creator<RecognitionEvent> CREATOR |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 1011 | = new Parcelable.Creator<RecognitionEvent>() { |
| 1012 | public RecognitionEvent createFromParcel(Parcel in) { |
| 1013 | return RecognitionEvent.fromParcel(in); |
| 1014 | } |
| 1015 | |
| 1016 | public RecognitionEvent[] newArray(int size) { |
| 1017 | return new RecognitionEvent[size]; |
| 1018 | } |
| 1019 | }; |
| 1020 | |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1021 | /** @hide */ |
Arunesh Mishra | f47f173 | 2016-02-18 16:16:12 -0800 | [diff] [blame] | 1022 | protected static RecognitionEvent fromParcel(Parcel in) { |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 1023 | int status = in.readInt(); |
| 1024 | int soundModelHandle = in.readInt(); |
| 1025 | boolean captureAvailable = in.readByte() == 1; |
| 1026 | int captureSession = in.readInt(); |
| 1027 | int captureDelayMs = in.readInt(); |
| 1028 | int capturePreambleMs = in.readInt(); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1029 | boolean triggerInData = in.readByte() == 1; |
| 1030 | AudioFormat captureFormat = null; |
Eric Laurent | 39fcca0 | 2014-09-05 16:44:19 -0700 | [diff] [blame] | 1031 | if (in.readByte() == 1) { |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1032 | int sampleRate = in.readInt(); |
| 1033 | int encoding = in.readInt(); |
| 1034 | int channelMask = in.readInt(); |
| 1035 | captureFormat = (new AudioFormat.Builder()) |
| 1036 | .setChannelMask(channelMask) |
| 1037 | .setEncoding(encoding) |
| 1038 | .setSampleRate(sampleRate) |
| 1039 | .build(); |
| 1040 | } |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 1041 | byte[] data = in.readBlob(); |
| 1042 | return new RecognitionEvent(status, soundModelHandle, captureAvailable, captureSession, |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1043 | captureDelayMs, capturePreambleMs, triggerInData, captureFormat, data); |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 1044 | } |
| 1045 | |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1046 | /** @hide */ |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 1047 | public int describeContents() { |
| 1048 | return 0; |
| 1049 | } |
| 1050 | |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1051 | /** @hide */ |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 1052 | public void writeToParcel(Parcel dest, int flags) { |
| 1053 | dest.writeInt(status); |
| 1054 | dest.writeInt(soundModelHandle); |
| 1055 | dest.writeByte((byte) (captureAvailable ? 1 : 0)); |
| 1056 | dest.writeInt(captureSession); |
| 1057 | dest.writeInt(captureDelayMs); |
| 1058 | dest.writeInt(capturePreambleMs); |
Eric Laurent | 39fcca0 | 2014-09-05 16:44:19 -0700 | [diff] [blame] | 1059 | dest.writeByte((byte) (triggerInData ? 1 : 0)); |
| 1060 | if (captureFormat != null) { |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1061 | dest.writeByte((byte)1); |
| 1062 | dest.writeInt(captureFormat.getSampleRate()); |
| 1063 | dest.writeInt(captureFormat.getEncoding()); |
| 1064 | dest.writeInt(captureFormat.getChannelMask()); |
| 1065 | } else { |
| 1066 | dest.writeByte((byte)0); |
| 1067 | } |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 1068 | dest.writeBlob(data); |
| 1069 | } |
| 1070 | |
| 1071 | @Override |
| 1072 | public int hashCode() { |
| 1073 | final int prime = 31; |
| 1074 | int result = 1; |
| 1075 | result = prime * result + (captureAvailable ? 1231 : 1237); |
| 1076 | result = prime * result + captureDelayMs; |
| 1077 | result = prime * result + capturePreambleMs; |
| 1078 | result = prime * result + captureSession; |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1079 | result = prime * result + (triggerInData ? 1231 : 1237); |
| 1080 | if (captureFormat != null) { |
| 1081 | result = prime * result + captureFormat.getSampleRate(); |
| 1082 | result = prime * result + captureFormat.getEncoding(); |
| 1083 | result = prime * result + captureFormat.getChannelMask(); |
| 1084 | } |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 1085 | result = prime * result + Arrays.hashCode(data); |
| 1086 | result = prime * result + soundModelHandle; |
| 1087 | result = prime * result + status; |
| 1088 | return result; |
| 1089 | } |
| 1090 | |
| 1091 | @Override |
Aurimas Liutikas | 4d1699d | 2019-08-28 13:01:05 -0700 | [diff] [blame] | 1092 | public boolean equals(@Nullable Object obj) { |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 1093 | if (this == obj) |
| 1094 | return true; |
| 1095 | if (obj == null) |
| 1096 | return false; |
| 1097 | if (getClass() != obj.getClass()) |
| 1098 | return false; |
| 1099 | RecognitionEvent other = (RecognitionEvent) obj; |
| 1100 | if (captureAvailable != other.captureAvailable) |
| 1101 | return false; |
| 1102 | if (captureDelayMs != other.captureDelayMs) |
| 1103 | return false; |
| 1104 | if (capturePreambleMs != other.capturePreambleMs) |
| 1105 | return false; |
| 1106 | if (captureSession != other.captureSession) |
| 1107 | return false; |
| 1108 | if (!Arrays.equals(data, other.data)) |
| 1109 | return false; |
| 1110 | if (soundModelHandle != other.soundModelHandle) |
| 1111 | return false; |
| 1112 | if (status != other.status) |
| 1113 | return false; |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1114 | if (triggerInData != other.triggerInData) |
| 1115 | return false; |
Ryan Bavetta | ea04e8f | 2016-03-02 18:34:50 -0800 | [diff] [blame] | 1116 | if (captureFormat == null) { |
| 1117 | if (other.captureFormat != null) |
| 1118 | return false; |
| 1119 | } else { |
| 1120 | if (other.captureFormat == null) |
| 1121 | return false; |
| 1122 | if (captureFormat.getSampleRate() != other.captureFormat.getSampleRate()) |
| 1123 | return false; |
| 1124 | if (captureFormat.getEncoding() != other.captureFormat.getEncoding()) |
| 1125 | return false; |
| 1126 | if (captureFormat.getChannelMask() != other.captureFormat.getChannelMask()) |
| 1127 | return false; |
| 1128 | } |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 1129 | return true; |
| 1130 | } |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1131 | |
Aurimas Liutikas | 4d1699d | 2019-08-28 13:01:05 -0700 | [diff] [blame] | 1132 | @NonNull |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1133 | @Override |
| 1134 | public String toString() { |
| 1135 | return "RecognitionEvent [status=" + status + ", soundModelHandle=" + soundModelHandle |
| 1136 | + ", captureAvailable=" + captureAvailable + ", captureSession=" |
| 1137 | + captureSession + ", captureDelayMs=" + captureDelayMs |
| 1138 | + ", capturePreambleMs=" + capturePreambleMs |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1139 | + ", triggerInData=" + triggerInData |
| 1140 | + ((captureFormat == null) ? "" : |
| 1141 | (", sampleRate=" + captureFormat.getSampleRate())) |
| 1142 | + ((captureFormat == null) ? "" : |
| 1143 | (", encoding=" + captureFormat.getEncoding())) |
| 1144 | + ((captureFormat == null) ? "" : |
| 1145 | (", channelMask=" + captureFormat.getChannelMask())) |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1146 | + ", data=" + (data == null ? 0 : data.length) + "]"; |
| 1147 | } |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | /** |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1151 | * A RecognitionConfig is provided to |
| 1152 | * {@link SoundTriggerModule#startRecognition(int, RecognitionConfig)} to configure the |
| 1153 | * recognition request. |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1154 | * |
| 1155 | * @hide |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1156 | */ |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1157 | public static class RecognitionConfig implements Parcelable { |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1158 | /** True if the DSP should capture the trigger sound and make it available for further |
| 1159 | * capture. */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1160 | @UnsupportedAppUsage |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1161 | public final boolean captureRequested; |
Sandeep Siddhartha | 2c0273e | 2014-08-01 11:32:03 -0700 | [diff] [blame] | 1162 | /** |
| 1163 | * True if the service should restart listening after the DSP triggers. |
| 1164 | * Note: This config flag is currently used at the service layer rather than by the DSP. |
| 1165 | */ |
| 1166 | public final boolean allowMultipleTriggers; |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1167 | /** List of all keyphrases in the sound model for which recognition should be performed with |
| 1168 | * options for each keyphrase. */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1169 | @UnsupportedAppUsage |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 1170 | @NonNull |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1171 | public final KeyphraseRecognitionExtra keyphrases[]; |
| 1172 | /** Opaque data for use by system applications who know about voice engine internals, |
| 1173 | * typically during enrollment. */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1174 | @UnsupportedAppUsage |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 1175 | @NonNull |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1176 | public final byte[] data; |
| 1177 | |
Nicholas Ambur | 7092a56 | 2019-12-16 11:18:55 -0800 | [diff] [blame] | 1178 | /** |
| 1179 | * Bit field encoding of the AudioCapabilities |
| 1180 | * supported by the firmware. |
| 1181 | */ |
| 1182 | @ModuleProperties.AudioCapabilities |
| 1183 | public final int audioCapabilities; |
| 1184 | |
Sandeep Siddhartha | 2c0273e | 2014-08-01 11:32:03 -0700 | [diff] [blame] | 1185 | public RecognitionConfig(boolean captureRequested, boolean allowMultipleTriggers, |
Nicholas Ambur | 7092a56 | 2019-12-16 11:18:55 -0800 | [diff] [blame] | 1186 | @Nullable KeyphraseRecognitionExtra[] keyphrases, @Nullable byte[] data, |
| 1187 | int audioCapabilities) { |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1188 | this.captureRequested = captureRequested; |
Sandeep Siddhartha | 2c0273e | 2014-08-01 11:32:03 -0700 | [diff] [blame] | 1189 | this.allowMultipleTriggers = allowMultipleTriggers; |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 1190 | this.keyphrases = keyphrases != null ? keyphrases : new KeyphraseRecognitionExtra[0]; |
| 1191 | this.data = data != null ? data : new byte[0]; |
Nicholas Ambur | 7092a56 | 2019-12-16 11:18:55 -0800 | [diff] [blame] | 1192 | this.audioCapabilities = audioCapabilities; |
| 1193 | } |
| 1194 | |
| 1195 | @UnsupportedAppUsage |
| 1196 | public RecognitionConfig(boolean captureRequested, boolean allowMultipleTriggers, |
| 1197 | @Nullable KeyphraseRecognitionExtra[] keyphrases, @Nullable byte[] data) { |
| 1198 | this(captureRequested, allowMultipleTriggers, keyphrases, data, 0); |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1199 | } |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1200 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 1201 | public static final @android.annotation.NonNull Parcelable.Creator<RecognitionConfig> CREATOR |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1202 | = new Parcelable.Creator<RecognitionConfig>() { |
| 1203 | public RecognitionConfig createFromParcel(Parcel in) { |
| 1204 | return RecognitionConfig.fromParcel(in); |
| 1205 | } |
| 1206 | |
| 1207 | public RecognitionConfig[] newArray(int size) { |
| 1208 | return new RecognitionConfig[size]; |
| 1209 | } |
| 1210 | }; |
| 1211 | |
| 1212 | private static RecognitionConfig fromParcel(Parcel in) { |
| 1213 | boolean captureRequested = in.readByte() == 1; |
Sandeep Siddhartha | 2c0273e | 2014-08-01 11:32:03 -0700 | [diff] [blame] | 1214 | boolean allowMultipleTriggers = in.readByte() == 1; |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1215 | KeyphraseRecognitionExtra[] keyphrases = |
| 1216 | in.createTypedArray(KeyphraseRecognitionExtra.CREATOR); |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 1217 | byte[] data = in.readBlob(); |
Nicholas Ambur | 7092a56 | 2019-12-16 11:18:55 -0800 | [diff] [blame] | 1218 | int audioCapabilities = in.readInt(); |
| 1219 | return new RecognitionConfig(captureRequested, allowMultipleTriggers, keyphrases, data, |
| 1220 | audioCapabilities); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | @Override |
| 1224 | public void writeToParcel(Parcel dest, int flags) { |
| 1225 | dest.writeByte((byte) (captureRequested ? 1 : 0)); |
Sandeep Siddhartha | 2c0273e | 2014-08-01 11:32:03 -0700 | [diff] [blame] | 1226 | dest.writeByte((byte) (allowMultipleTriggers ? 1 : 0)); |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1227 | dest.writeTypedArray(keyphrases, flags); |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 1228 | dest.writeBlob(data); |
Nicholas Ambur | 7092a56 | 2019-12-16 11:18:55 -0800 | [diff] [blame] | 1229 | dest.writeInt(audioCapabilities); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | @Override |
| 1233 | public int describeContents() { |
| 1234 | return 0; |
| 1235 | } |
Sandeep Siddhartha | 110f569 | 2014-07-20 12:22:56 -0700 | [diff] [blame] | 1236 | |
| 1237 | @Override |
| 1238 | public String toString() { |
Sandeep Siddhartha | 2c0273e | 2014-08-01 11:32:03 -0700 | [diff] [blame] | 1239 | return "RecognitionConfig [captureRequested=" + captureRequested |
| 1240 | + ", allowMultipleTriggers=" + allowMultipleTriggers + ", keyphrases=" |
Nicholas Ambur | 7092a56 | 2019-12-16 11:18:55 -0800 | [diff] [blame] | 1241 | + Arrays.toString(keyphrases) + ", data=" + Arrays.toString(data) |
| 1242 | + ", audioCapabilities=" + Integer.toHexString(audioCapabilities) + "]"; |
Sandeep Siddhartha | 110f569 | 2014-07-20 12:22:56 -0700 | [diff] [blame] | 1243 | } |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | /** |
| 1247 | * Confidence level for users defined in a keyphrase. |
| 1248 | * - The confidence level is expressed in percent (0% -100%). |
| 1249 | * When used in a {@link KeyphraseRecognitionEvent} it indicates the detected confidence level |
| 1250 | * When used in a {@link RecognitionConfig} it indicates the minimum confidence level that |
| 1251 | * should trigger a recognition. |
| 1252 | * - The user ID is derived from the system ID {@link android.os.UserHandle#getIdentifier()}. |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1253 | * |
| 1254 | * @hide |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1255 | */ |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1256 | public static class ConfidenceLevel implements Parcelable { |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1257 | @UnsupportedAppUsage |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1258 | public final int userId; |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1259 | @UnsupportedAppUsage |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1260 | public final int confidenceLevel; |
| 1261 | |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1262 | @UnsupportedAppUsage |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1263 | public ConfidenceLevel(int userId, int confidenceLevel) { |
| 1264 | this.userId = userId; |
| 1265 | this.confidenceLevel = confidenceLevel; |
| 1266 | } |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1267 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 1268 | public static final @android.annotation.NonNull Parcelable.Creator<ConfidenceLevel> CREATOR |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1269 | = new Parcelable.Creator<ConfidenceLevel>() { |
| 1270 | public ConfidenceLevel createFromParcel(Parcel in) { |
| 1271 | return ConfidenceLevel.fromParcel(in); |
| 1272 | } |
| 1273 | |
| 1274 | public ConfidenceLevel[] newArray(int size) { |
| 1275 | return new ConfidenceLevel[size]; |
| 1276 | } |
| 1277 | }; |
| 1278 | |
| 1279 | private static ConfidenceLevel fromParcel(Parcel in) { |
| 1280 | int userId = in.readInt(); |
| 1281 | int confidenceLevel = in.readInt(); |
| 1282 | return new ConfidenceLevel(userId, confidenceLevel); |
| 1283 | } |
| 1284 | |
| 1285 | @Override |
| 1286 | public void writeToParcel(Parcel dest, int flags) { |
| 1287 | dest.writeInt(userId); |
| 1288 | dest.writeInt(confidenceLevel); |
| 1289 | } |
| 1290 | |
| 1291 | @Override |
| 1292 | public int describeContents() { |
| 1293 | return 0; |
| 1294 | } |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1295 | |
| 1296 | @Override |
| 1297 | public int hashCode() { |
| 1298 | final int prime = 31; |
| 1299 | int result = 1; |
| 1300 | result = prime * result + confidenceLevel; |
| 1301 | result = prime * result + userId; |
| 1302 | return result; |
| 1303 | } |
| 1304 | |
| 1305 | @Override |
| 1306 | public boolean equals(Object obj) { |
| 1307 | if (this == obj) |
| 1308 | return true; |
| 1309 | if (obj == null) |
| 1310 | return false; |
| 1311 | if (getClass() != obj.getClass()) |
| 1312 | return false; |
| 1313 | ConfidenceLevel other = (ConfidenceLevel) obj; |
| 1314 | if (confidenceLevel != other.confidenceLevel) |
| 1315 | return false; |
| 1316 | if (userId != other.userId) |
| 1317 | return false; |
| 1318 | return true; |
| 1319 | } |
| 1320 | |
| 1321 | @Override |
| 1322 | public String toString() { |
| 1323 | return "ConfidenceLevel [userId=" + userId |
| 1324 | + ", confidenceLevel=" + confidenceLevel + "]"; |
| 1325 | } |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | /** |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 1329 | * Additional data conveyed by a {@link KeyphraseRecognitionEvent} |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1330 | * for a key phrase detection. |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1331 | * |
| 1332 | * @hide |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1333 | */ |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1334 | public static class KeyphraseRecognitionExtra implements Parcelable { |
| 1335 | /** The keyphrase ID */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1336 | @UnsupportedAppUsage |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1337 | public final int id; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1338 | |
| 1339 | /** Recognition modes matched for this event */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1340 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1341 | public final int recognitionModes; |
| 1342 | |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1343 | /** Confidence level for mode RECOGNITION_MODE_VOICE_TRIGGER when user identification |
| 1344 | * is not performed */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1345 | @UnsupportedAppUsage |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1346 | public final int coarseConfidenceLevel; |
| 1347 | |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1348 | /** Confidence levels for all users recognized (KeyphraseRecognitionEvent) or to |
| 1349 | * be recognized (RecognitionConfig) */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1350 | @UnsupportedAppUsage |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 1351 | @NonNull |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1352 | public final ConfidenceLevel[] confidenceLevels; |
| 1353 | |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1354 | @UnsupportedAppUsage |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1355 | public KeyphraseRecognitionExtra(int id, int recognitionModes, int coarseConfidenceLevel, |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 1356 | @Nullable ConfidenceLevel[] confidenceLevels) { |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1357 | this.id = id; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1358 | this.recognitionModes = recognitionModes; |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1359 | this.coarseConfidenceLevel = coarseConfidenceLevel; |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 1360 | this.confidenceLevels = |
| 1361 | confidenceLevels != null ? confidenceLevels : new ConfidenceLevel[0]; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1362 | } |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1363 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 1364 | public static final @android.annotation.NonNull Parcelable.Creator<KeyphraseRecognitionExtra> CREATOR |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1365 | = new Parcelable.Creator<KeyphraseRecognitionExtra>() { |
| 1366 | public KeyphraseRecognitionExtra createFromParcel(Parcel in) { |
| 1367 | return KeyphraseRecognitionExtra.fromParcel(in); |
| 1368 | } |
| 1369 | |
| 1370 | public KeyphraseRecognitionExtra[] newArray(int size) { |
| 1371 | return new KeyphraseRecognitionExtra[size]; |
| 1372 | } |
| 1373 | }; |
| 1374 | |
| 1375 | private static KeyphraseRecognitionExtra fromParcel(Parcel in) { |
| 1376 | int id = in.readInt(); |
| 1377 | int recognitionModes = in.readInt(); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1378 | int coarseConfidenceLevel = in.readInt(); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1379 | ConfidenceLevel[] confidenceLevels = in.createTypedArray(ConfidenceLevel.CREATOR); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1380 | return new KeyphraseRecognitionExtra(id, recognitionModes, coarseConfidenceLevel, |
| 1381 | confidenceLevels); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1382 | } |
| 1383 | |
| 1384 | @Override |
| 1385 | public void writeToParcel(Parcel dest, int flags) { |
| 1386 | dest.writeInt(id); |
| 1387 | dest.writeInt(recognitionModes); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1388 | dest.writeInt(coarseConfidenceLevel); |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1389 | dest.writeTypedArray(confidenceLevels, flags); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | @Override |
| 1393 | public int describeContents() { |
| 1394 | return 0; |
| 1395 | } |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1396 | |
| 1397 | @Override |
| 1398 | public int hashCode() { |
| 1399 | final int prime = 31; |
| 1400 | int result = 1; |
| 1401 | result = prime * result + Arrays.hashCode(confidenceLevels); |
| 1402 | result = prime * result + id; |
| 1403 | result = prime * result + recognitionModes; |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1404 | result = prime * result + coarseConfidenceLevel; |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1405 | return result; |
| 1406 | } |
| 1407 | |
| 1408 | @Override |
| 1409 | public boolean equals(Object obj) { |
| 1410 | if (this == obj) |
| 1411 | return true; |
| 1412 | if (obj == null) |
| 1413 | return false; |
| 1414 | if (getClass() != obj.getClass()) |
| 1415 | return false; |
| 1416 | KeyphraseRecognitionExtra other = (KeyphraseRecognitionExtra) obj; |
| 1417 | if (!Arrays.equals(confidenceLevels, other.confidenceLevels)) |
| 1418 | return false; |
| 1419 | if (id != other.id) |
| 1420 | return false; |
| 1421 | if (recognitionModes != other.recognitionModes) |
| 1422 | return false; |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1423 | if (coarseConfidenceLevel != other.coarseConfidenceLevel) |
| 1424 | return false; |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1425 | return true; |
| 1426 | } |
| 1427 | |
| 1428 | @Override |
| 1429 | public String toString() { |
| 1430 | return "KeyphraseRecognitionExtra [id=" + id + ", recognitionModes=" + recognitionModes |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1431 | + ", coarseConfidenceLevel=" + coarseConfidenceLevel |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1432 | + ", confidenceLevels=" + Arrays.toString(confidenceLevels) + "]"; |
| 1433 | } |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1434 | } |
| 1435 | |
| 1436 | /** |
| 1437 | * Specialized {@link RecognitionEvent} for a key phrase detection. |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1438 | * |
| 1439 | * @hide |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1440 | */ |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1441 | public static class KeyphraseRecognitionEvent extends RecognitionEvent implements Parcelable { |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1442 | /** Indicates if the key phrase is present in the buffered audio available for capture */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1443 | @UnsupportedAppUsage |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 1444 | @NonNull |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 1445 | public final KeyphraseRecognitionExtra[] keyphraseExtras; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1446 | |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1447 | @UnsupportedAppUsage |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1448 | public KeyphraseRecognitionEvent(int status, int soundModelHandle, boolean captureAvailable, |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1449 | int captureSession, int captureDelayMs, int capturePreambleMs, |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 1450 | boolean triggerInData, @NonNull AudioFormat captureFormat, @Nullable byte[] data, |
| 1451 | @Nullable KeyphraseRecognitionExtra[] keyphraseExtras) { |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1452 | super(status, soundModelHandle, captureAvailable, captureSession, captureDelayMs, |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1453 | capturePreambleMs, triggerInData, captureFormat, data); |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 1454 | this.keyphraseExtras = |
| 1455 | keyphraseExtras != null ? keyphraseExtras : new KeyphraseRecognitionExtra[0]; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1456 | } |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1457 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 1458 | public static final @android.annotation.NonNull Parcelable.Creator<KeyphraseRecognitionEvent> CREATOR |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1459 | = new Parcelable.Creator<KeyphraseRecognitionEvent>() { |
| 1460 | public KeyphraseRecognitionEvent createFromParcel(Parcel in) { |
Arunesh Mishra | f47f173 | 2016-02-18 16:16:12 -0800 | [diff] [blame] | 1461 | return KeyphraseRecognitionEvent.fromParcelForKeyphrase(in); |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1462 | } |
| 1463 | |
| 1464 | public KeyphraseRecognitionEvent[] newArray(int size) { |
| 1465 | return new KeyphraseRecognitionEvent[size]; |
| 1466 | } |
| 1467 | }; |
| 1468 | |
Arunesh Mishra | f47f173 | 2016-02-18 16:16:12 -0800 | [diff] [blame] | 1469 | private static KeyphraseRecognitionEvent fromParcelForKeyphrase(Parcel in) { |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1470 | int status = in.readInt(); |
| 1471 | int soundModelHandle = in.readInt(); |
| 1472 | boolean captureAvailable = in.readByte() == 1; |
| 1473 | int captureSession = in.readInt(); |
| 1474 | int captureDelayMs = in.readInt(); |
| 1475 | int capturePreambleMs = in.readInt(); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1476 | boolean triggerInData = in.readByte() == 1; |
| 1477 | AudioFormat captureFormat = null; |
Eric Laurent | 75b433f | 2014-09-12 15:45:47 -0700 | [diff] [blame] | 1478 | if (in.readByte() == 1) { |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1479 | int sampleRate = in.readInt(); |
| 1480 | int encoding = in.readInt(); |
| 1481 | int channelMask = in.readInt(); |
| 1482 | captureFormat = (new AudioFormat.Builder()) |
Ryan Bavetta | ea04e8f | 2016-03-02 18:34:50 -0800 | [diff] [blame] | 1483 | .setChannelMask(channelMask) |
| 1484 | .setEncoding(encoding) |
| 1485 | .setSampleRate(sampleRate) |
| 1486 | .build(); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1487 | } |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1488 | byte[] data = in.readBlob(); |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1489 | KeyphraseRecognitionExtra[] keyphraseExtras = |
| 1490 | in.createTypedArray(KeyphraseRecognitionExtra.CREATOR); |
| 1491 | return new KeyphraseRecognitionEvent(status, soundModelHandle, captureAvailable, |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1492 | captureSession, captureDelayMs, capturePreambleMs, triggerInData, |
| 1493 | captureFormat, data, keyphraseExtras); |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | @Override |
| 1497 | public void writeToParcel(Parcel dest, int flags) { |
| 1498 | dest.writeInt(status); |
| 1499 | dest.writeInt(soundModelHandle); |
| 1500 | dest.writeByte((byte) (captureAvailable ? 1 : 0)); |
| 1501 | dest.writeInt(captureSession); |
| 1502 | dest.writeInt(captureDelayMs); |
| 1503 | dest.writeInt(capturePreambleMs); |
Eric Laurent | 75b433f | 2014-09-12 15:45:47 -0700 | [diff] [blame] | 1504 | dest.writeByte((byte) (triggerInData ? 1 : 0)); |
| 1505 | if (captureFormat != null) { |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1506 | dest.writeByte((byte)1); |
| 1507 | dest.writeInt(captureFormat.getSampleRate()); |
| 1508 | dest.writeInt(captureFormat.getEncoding()); |
| 1509 | dest.writeInt(captureFormat.getChannelMask()); |
| 1510 | } else { |
| 1511 | dest.writeByte((byte)0); |
| 1512 | } |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1513 | dest.writeBlob(data); |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1514 | dest.writeTypedArray(keyphraseExtras, flags); |
| 1515 | } |
| 1516 | |
| 1517 | @Override |
| 1518 | public int describeContents() { |
| 1519 | return 0; |
| 1520 | } |
| 1521 | |
| 1522 | @Override |
| 1523 | public int hashCode() { |
| 1524 | final int prime = 31; |
| 1525 | int result = super.hashCode(); |
| 1526 | result = prime * result + Arrays.hashCode(keyphraseExtras); |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1527 | return result; |
| 1528 | } |
| 1529 | |
| 1530 | @Override |
| 1531 | public boolean equals(Object obj) { |
| 1532 | if (this == obj) |
| 1533 | return true; |
| 1534 | if (!super.equals(obj)) |
| 1535 | return false; |
| 1536 | if (getClass() != obj.getClass()) |
| 1537 | return false; |
| 1538 | KeyphraseRecognitionEvent other = (KeyphraseRecognitionEvent) obj; |
| 1539 | if (!Arrays.equals(keyphraseExtras, other.keyphraseExtras)) |
| 1540 | return false; |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1541 | return true; |
| 1542 | } |
| 1543 | |
| 1544 | @Override |
| 1545 | public String toString() { |
| 1546 | return "KeyphraseRecognitionEvent [keyphraseExtras=" + Arrays.toString(keyphraseExtras) |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1547 | + ", status=" + status |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1548 | + ", soundModelHandle=" + soundModelHandle + ", captureAvailable=" |
| 1549 | + captureAvailable + ", captureSession=" + captureSession + ", captureDelayMs=" |
| 1550 | + captureDelayMs + ", capturePreambleMs=" + capturePreambleMs |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1551 | + ", triggerInData=" + triggerInData |
| 1552 | + ((captureFormat == null) ? "" : |
| 1553 | (", sampleRate=" + captureFormat.getSampleRate())) |
| 1554 | + ((captureFormat == null) ? "" : |
| 1555 | (", encoding=" + captureFormat.getEncoding())) |
| 1556 | + ((captureFormat == null) ? "" : |
| 1557 | (", channelMask=" + captureFormat.getChannelMask())) |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1558 | + ", data=" + (data == null ? 0 : data.length) + "]"; |
| 1559 | } |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | /** |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 1563 | * Sub-class of RecognitionEvent specifically for sound-trigger based sound |
| 1564 | * models(non-keyphrase). Currently does not contain any additional fields. |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1565 | * |
| 1566 | * @hide |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 1567 | */ |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1568 | public static class GenericRecognitionEvent extends RecognitionEvent implements Parcelable { |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1569 | @UnsupportedAppUsage |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 1570 | public GenericRecognitionEvent(int status, int soundModelHandle, |
| 1571 | boolean captureAvailable, int captureSession, int captureDelayMs, |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 1572 | int capturePreambleMs, boolean triggerInData, @NonNull AudioFormat captureFormat, |
| 1573 | @Nullable byte[] data) { |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 1574 | super(status, soundModelHandle, captureAvailable, captureSession, |
| 1575 | captureDelayMs, capturePreambleMs, triggerInData, captureFormat, |
| 1576 | data); |
| 1577 | } |
Arunesh Mishra | f47f173 | 2016-02-18 16:16:12 -0800 | [diff] [blame] | 1578 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 1579 | public static final @android.annotation.NonNull Parcelable.Creator<GenericRecognitionEvent> CREATOR |
Arunesh Mishra | f47f173 | 2016-02-18 16:16:12 -0800 | [diff] [blame] | 1580 | = new Parcelable.Creator<GenericRecognitionEvent>() { |
| 1581 | public GenericRecognitionEvent createFromParcel(Parcel in) { |
| 1582 | return GenericRecognitionEvent.fromParcelForGeneric(in); |
| 1583 | } |
| 1584 | |
| 1585 | public GenericRecognitionEvent[] newArray(int size) { |
| 1586 | return new GenericRecognitionEvent[size]; |
| 1587 | } |
| 1588 | }; |
| 1589 | |
| 1590 | private static GenericRecognitionEvent fromParcelForGeneric(Parcel in) { |
| 1591 | RecognitionEvent event = RecognitionEvent.fromParcel(in); |
| 1592 | return new GenericRecognitionEvent(event.status, event.soundModelHandle, |
| 1593 | event.captureAvailable, event.captureSession, event.captureDelayMs, |
| 1594 | event.capturePreambleMs, event.triggerInData, event.captureFormat, event.data); |
| 1595 | } |
| 1596 | |
| 1597 | @Override |
| 1598 | public boolean equals(Object obj) { |
| 1599 | if (this == obj) |
| 1600 | return true; |
| 1601 | if (obj == null) |
| 1602 | return false; |
| 1603 | if (getClass() != obj.getClass()) return false; |
| 1604 | RecognitionEvent other = (RecognitionEvent) obj; |
| 1605 | return super.equals(obj); |
| 1606 | } |
| 1607 | |
| 1608 | @Override |
| 1609 | public String toString() { |
| 1610 | return "GenericRecognitionEvent ::" + super.toString(); |
| 1611 | } |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 1612 | } |
| 1613 | |
| 1614 | /** |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1615 | * Status codes for {@link SoundModelEvent} |
| 1616 | */ |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1617 | /** |
| 1618 | * Sound Model was updated |
| 1619 | * |
| 1620 | * @hide |
| 1621 | */ |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1622 | public static final int SOUNDMODEL_STATUS_UPDATED = 0; |
| 1623 | |
| 1624 | /** |
| 1625 | * A SoundModelEvent is provided by the |
| 1626 | * {@link StatusListener#onSoundModelUpdate(SoundModelEvent)} |
| 1627 | * callback when a sound model has been updated by the implementation |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1628 | * |
| 1629 | * @hide |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1630 | */ |
| 1631 | public static class SoundModelEvent implements Parcelable { |
| 1632 | /** Status e.g {@link #SOUNDMODEL_STATUS_UPDATED} */ |
| 1633 | public final int status; |
| 1634 | /** The updated sound model handle */ |
| 1635 | public final int soundModelHandle; |
| 1636 | /** New sound model data */ |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 1637 | @NonNull |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1638 | public final byte[] data; |
| 1639 | |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1640 | @UnsupportedAppUsage |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 1641 | SoundModelEvent(int status, int soundModelHandle, @Nullable byte[] data) { |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1642 | this.status = status; |
| 1643 | this.soundModelHandle = soundModelHandle; |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 1644 | this.data = data != null ? data : new byte[0]; |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1645 | } |
| 1646 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 1647 | public static final @android.annotation.NonNull Parcelable.Creator<SoundModelEvent> CREATOR |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1648 | = new Parcelable.Creator<SoundModelEvent>() { |
| 1649 | public SoundModelEvent createFromParcel(Parcel in) { |
| 1650 | return SoundModelEvent.fromParcel(in); |
| 1651 | } |
| 1652 | |
| 1653 | public SoundModelEvent[] newArray(int size) { |
| 1654 | return new SoundModelEvent[size]; |
| 1655 | } |
| 1656 | }; |
| 1657 | |
| 1658 | private static SoundModelEvent fromParcel(Parcel in) { |
| 1659 | int status = in.readInt(); |
| 1660 | int soundModelHandle = in.readInt(); |
| 1661 | byte[] data = in.readBlob(); |
| 1662 | return new SoundModelEvent(status, soundModelHandle, data); |
| 1663 | } |
| 1664 | |
| 1665 | @Override |
| 1666 | public int describeContents() { |
| 1667 | return 0; |
| 1668 | } |
| 1669 | |
| 1670 | @Override |
| 1671 | public void writeToParcel(Parcel dest, int flags) { |
| 1672 | dest.writeInt(status); |
| 1673 | dest.writeInt(soundModelHandle); |
| 1674 | dest.writeBlob(data); |
| 1675 | } |
| 1676 | |
| 1677 | @Override |
| 1678 | public int hashCode() { |
| 1679 | final int prime = 31; |
| 1680 | int result = 1; |
| 1681 | result = prime * result + Arrays.hashCode(data); |
| 1682 | result = prime * result + soundModelHandle; |
| 1683 | result = prime * result + status; |
| 1684 | return result; |
| 1685 | } |
| 1686 | |
| 1687 | @Override |
| 1688 | public boolean equals(Object obj) { |
| 1689 | if (this == obj) |
| 1690 | return true; |
| 1691 | if (obj == null) |
| 1692 | return false; |
| 1693 | if (getClass() != obj.getClass()) |
| 1694 | return false; |
| 1695 | SoundModelEvent other = (SoundModelEvent) obj; |
| 1696 | if (!Arrays.equals(data, other.data)) |
| 1697 | return false; |
| 1698 | if (soundModelHandle != other.soundModelHandle) |
| 1699 | return false; |
| 1700 | if (status != other.status) |
| 1701 | return false; |
| 1702 | return true; |
| 1703 | } |
| 1704 | |
| 1705 | @Override |
| 1706 | public String toString() { |
| 1707 | return "SoundModelEvent [status=" + status + ", soundModelHandle=" + soundModelHandle |
| 1708 | + ", data=" + (data == null ? 0 : data.length) + "]"; |
| 1709 | } |
| 1710 | } |
| 1711 | |
| 1712 | /** |
| 1713 | * Native service state. {@link StatusListener#onServiceStateChange(int)} |
| 1714 | */ |
| 1715 | // Keep in sync with system/core/include/system/sound_trigger.h |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1716 | /** |
| 1717 | * Sound trigger service is enabled |
| 1718 | * |
| 1719 | * @hide |
| 1720 | */ |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1721 | public static final int SERVICE_STATE_ENABLED = 0; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1722 | /** |
| 1723 | * Sound trigger service is disabled |
| 1724 | * |
| 1725 | * @hide |
| 1726 | */ |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1727 | public static final int SERVICE_STATE_DISABLED = 1; |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 1728 | private static Object mServiceLock = new Object(); |
| 1729 | private static ISoundTriggerMiddlewareService mService; |
| 1730 | /** |
jiabin | 1f4b4dd | 2019-03-18 18:07:03 -0700 | [diff] [blame] | 1731 | * @return returns current package name. |
| 1732 | */ |
| 1733 | static String getCurrentOpPackageName() { |
| 1734 | String packageName = ActivityThread.currentOpPackageName(); |
| 1735 | if (packageName == null) { |
| 1736 | return ""; |
| 1737 | } |
| 1738 | return packageName; |
| 1739 | } |
| 1740 | |
| 1741 | /** |
Ytai Ben-Tsvi | 2e8f78b | 2020-01-15 11:57:34 -0800 | [diff] [blame] | 1742 | * Translate an exception thrown from interaction with the underlying service to an error code. |
| 1743 | * Throws a runtime exception for unexpected conditions. |
| 1744 | * @param e The caught exception. |
| 1745 | * @return The error code. |
| 1746 | * |
| 1747 | * @hide |
| 1748 | */ |
| 1749 | static int handleException(Exception e) { |
| 1750 | Log.w(TAG, "Exception caught", e); |
| 1751 | if (e instanceof RemoteException) { |
| 1752 | return STATUS_DEAD_OBJECT; |
| 1753 | } |
| 1754 | if (e instanceof ServiceSpecificException) { |
| 1755 | switch (((ServiceSpecificException) e).errorCode) { |
| 1756 | case Status.OPERATION_NOT_SUPPORTED: |
| 1757 | return STATUS_INVALID_OPERATION; |
| 1758 | case Status.TEMPORARY_PERMISSION_DENIED: |
| 1759 | return STATUS_PERMISSION_DENIED; |
| 1760 | case Status.DEAD_OBJECT: |
| 1761 | return STATUS_DEAD_OBJECT; |
| 1762 | } |
| 1763 | return STATUS_ERROR; |
| 1764 | } |
| 1765 | if (e instanceof SecurityException) { |
| 1766 | return STATUS_PERMISSION_DENIED; |
| 1767 | } |
| 1768 | if (e instanceof IllegalStateException) { |
| 1769 | return STATUS_INVALID_OPERATION; |
| 1770 | } |
| 1771 | if (e instanceof IllegalArgumentException || e instanceof NullPointerException) { |
| 1772 | return STATUS_BAD_VALUE; |
| 1773 | } |
| 1774 | // This is not one of the conditions represented by our error code, escalate to a |
| 1775 | // RuntimeException. |
| 1776 | Log.e(TAG, "Escalating unexpected exception: ", e); |
| 1777 | throw new RuntimeException(e); |
| 1778 | } |
| 1779 | |
| 1780 | /** |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 1781 | * Returns a list of descriptors for all hardware modules loaded. |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1782 | * @param modules A ModuleProperties array where the list will be returned. |
| 1783 | * @return - {@link #STATUS_OK} in case of success |
| 1784 | * - {@link #STATUS_ERROR} in case of unspecified error |
| 1785 | * - {@link #STATUS_PERMISSION_DENIED} if the caller does not have system permission |
| 1786 | * - {@link #STATUS_NO_INIT} if the native service cannot be reached |
| 1787 | * - {@link #STATUS_BAD_VALUE} if modules is null |
| 1788 | * - {@link #STATUS_DEAD_OBJECT} if the binder transaction to the native service fails |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1789 | * |
| 1790 | * @hide |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1791 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1792 | @UnsupportedAppUsage |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 1793 | public static int listModules(@NonNull ArrayList<ModuleProperties> modules) { |
| 1794 | try { |
| 1795 | SoundTriggerModuleDescriptor[] descs = getService().listModules(); |
| 1796 | modules.clear(); |
| 1797 | modules.ensureCapacity(descs.length); |
| 1798 | for (SoundTriggerModuleDescriptor desc : descs) { |
| 1799 | modules.add(ConversionUtil.aidl2apiModuleDescriptor(desc)); |
| 1800 | } |
| 1801 | return STATUS_OK; |
Ytai Ben-Tsvi | 2e8f78b | 2020-01-15 11:57:34 -0800 | [diff] [blame] | 1802 | } catch (Exception e) { |
| 1803 | return handleException(e); |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 1804 | } |
jiabin | 1f4b4dd | 2019-03-18 18:07:03 -0700 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | /** |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1808 | * Get an interface on a hardware module to control sound models and recognition on |
| 1809 | * this module. |
| 1810 | * @param moduleId Sound module system identifier {@link ModuleProperties#id}. mandatory. |
| 1811 | * @param listener {@link StatusListener} interface. Mandatory. |
| 1812 | * @param handler the Handler that will receive the callabcks. Can be null if default handler |
| 1813 | * is OK. |
| 1814 | * @return a valid sound module in case of success or null in case of error. |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1815 | * |
| 1816 | * @hide |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1817 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1818 | @UnsupportedAppUsage |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 1819 | public static @NonNull SoundTriggerModule attachModule(int moduleId, |
| 1820 | @NonNull StatusListener listener, |
| 1821 | @Nullable Handler handler) { |
| 1822 | Looper looper = handler != null ? handler.getLooper() : Looper.getMainLooper(); |
| 1823 | try { |
| 1824 | return new SoundTriggerModule(getService(), moduleId, listener, looper); |
| 1825 | } catch (RemoteException e) { |
| 1826 | Log.e(TAG, "", e); |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1827 | return null; |
| 1828 | } |
Ytai Ben-Tsvi | 7d383d1 | 2019-11-25 12:47:40 -0800 | [diff] [blame] | 1829 | } |
| 1830 | |
| 1831 | private static ISoundTriggerMiddlewareService getService() { |
| 1832 | synchronized (mServiceLock) { |
| 1833 | while (true) { |
| 1834 | IBinder binder = null; |
| 1835 | try { |
| 1836 | binder = |
| 1837 | ServiceManager.getServiceOrThrow( |
| 1838 | Context.SOUND_TRIGGER_MIDDLEWARE_SERVICE); |
| 1839 | binder.linkToDeath(() -> { |
| 1840 | synchronized (mServiceLock) { |
| 1841 | mService = null; |
| 1842 | } |
| 1843 | }, 0); |
| 1844 | mService = ISoundTriggerMiddlewareService.Stub.asInterface(binder); |
| 1845 | break; |
| 1846 | } catch (Exception e) { |
| 1847 | Log.e(TAG, "Failed to bind to soundtrigger service", e); |
| 1848 | } |
| 1849 | } |
| 1850 | return mService; |
| 1851 | } |
| 1852 | |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | /** |
| 1856 | * Interface provided by the client application when attaching to a {@link SoundTriggerModule} |
| 1857 | * to received recognition and error notifications. |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1858 | * |
| 1859 | * @hide |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1860 | */ |
| 1861 | public static interface StatusListener { |
| 1862 | /** |
| 1863 | * Called when recognition succeeds of fails |
| 1864 | */ |
| 1865 | public abstract void onRecognition(RecognitionEvent event); |
| 1866 | |
| 1867 | /** |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1868 | * Called when a sound model has been updated |
| 1869 | */ |
| 1870 | public abstract void onSoundModelUpdate(SoundModelEvent event); |
| 1871 | |
| 1872 | /** |
| 1873 | * Called when the sound trigger native service state changes. |
| 1874 | * @param state Native service state. One of {@link SoundTrigger#SERVICE_STATE_ENABLED}, |
| 1875 | * {@link SoundTrigger#SERVICE_STATE_DISABLED} |
| 1876 | */ |
| 1877 | public abstract void onServiceStateChange(int state); |
| 1878 | |
| 1879 | /** |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1880 | * Called when the sound trigger native service dies |
| 1881 | */ |
| 1882 | public abstract void onServiceDied(); |
| 1883 | } |
| 1884 | } |