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 | |
| 25 | import android.annotation.Nullable; |
| 26 | import android.annotation.SystemApi; |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 27 | import android.annotation.UnsupportedAppUsage; |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 28 | import android.media.AudioFormat; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 29 | import android.os.Handler; |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 30 | import android.os.Parcel; |
| 31 | import android.os.Parcelable; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 32 | |
| 33 | import java.util.ArrayList; |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 34 | import java.util.Arrays; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 35 | import java.util.UUID; |
| 36 | |
| 37 | /** |
| 38 | * The SoundTrigger class provides access via JNI to the native service managing |
| 39 | * the sound trigger HAL. |
| 40 | * |
| 41 | * @hide |
| 42 | */ |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 43 | @SystemApi |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 44 | public class SoundTrigger { |
| 45 | |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 46 | private SoundTrigger() { |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Status code used when the operation succeeded |
| 51 | */ |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 52 | public static final int STATUS_OK = 0; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 53 | /** @hide */ |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 54 | public static final int STATUS_ERROR = Integer.MIN_VALUE; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 55 | /** @hide */ |
Lazar Trsic | 8ea56f6 | 2015-07-07 17:31:20 +0200 | [diff] [blame] | 56 | public static final int STATUS_PERMISSION_DENIED = -EPERM; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 57 | /** @hide */ |
Lazar Trsic | 8ea56f6 | 2015-07-07 17:31:20 +0200 | [diff] [blame] | 58 | public static final int STATUS_NO_INIT = -ENODEV; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 59 | /** @hide */ |
Lazar Trsic | 8ea56f6 | 2015-07-07 17:31:20 +0200 | [diff] [blame] | 60 | public static final int STATUS_BAD_VALUE = -EINVAL; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 61 | /** @hide */ |
Lazar Trsic | 8ea56f6 | 2015-07-07 17:31:20 +0200 | [diff] [blame] | 62 | public static final int STATUS_DEAD_OBJECT = -EPIPE; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 63 | /** @hide */ |
Lazar Trsic | 8ea56f6 | 2015-07-07 17:31:20 +0200 | [diff] [blame] | 64 | public static final int STATUS_INVALID_OPERATION = -ENOSYS; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 65 | |
| 66 | /***************************************************************************** |
| 67 | * A ModuleProperties describes a given sound trigger hardware module |
| 68 | * managed by the native sound trigger service. Each module has a unique |
| 69 | * ID used to target any API call to this paricular module. Module |
| 70 | * properties are returned by listModules() method. |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 71 | * |
| 72 | * @hide |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 73 | ****************************************************************************/ |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 74 | public static class ModuleProperties implements Parcelable { |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 75 | /** Unique module ID provided by the native service */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 76 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 77 | public final int id; |
| 78 | |
| 79 | /** human readable voice detection engine implementor */ |
| 80 | public final String implementor; |
| 81 | |
| 82 | /** human readable voice detection engine description */ |
| 83 | public final String description; |
| 84 | |
| 85 | /** Unique voice engine Id (changes with each version) */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 86 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 87 | public final UUID uuid; |
| 88 | |
| 89 | /** Voice detection engine version */ |
| 90 | public final int version; |
| 91 | |
| 92 | /** Maximum number of active sound models */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 93 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 94 | public final int maxSoundModels; |
| 95 | |
| 96 | /** Maximum number of key phrases */ |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 97 | public final int maxKeyphrases; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 98 | |
| 99 | /** Maximum number of users per key phrase */ |
| 100 | public final int maxUsers; |
| 101 | |
| 102 | /** Supported recognition modes (bit field, RECOGNITION_MODE_VOICE_TRIGGER ...) */ |
| 103 | public final int recognitionModes; |
| 104 | |
| 105 | /** Supports seamless transition to capture mode after recognition */ |
| 106 | public final boolean supportsCaptureTransition; |
| 107 | |
| 108 | /** Maximum buffering capacity in ms if supportsCaptureTransition() is true */ |
| 109 | public final int maxBufferMs; |
| 110 | |
| 111 | /** Supports capture by other use cases while detection is active */ |
| 112 | public final boolean supportsConcurrentCapture; |
| 113 | |
| 114 | /** Rated power consumption when detection is active with TDB silence/sound/speech ratio */ |
| 115 | public final int powerConsumptionMw; |
| 116 | |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 117 | /** Returns the trigger (key phrase) capture in the binary data of the |
| 118 | * recognition callback event */ |
| 119 | public final boolean returnsTriggerInEvent; |
| 120 | |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 121 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 122 | ModuleProperties(int id, String implementor, String description, |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 123 | String uuid, int version, int maxSoundModels, int maxKeyphrases, |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 124 | int maxUsers, int recognitionModes, boolean supportsCaptureTransition, |
| 125 | int maxBufferMs, boolean supportsConcurrentCapture, |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 126 | int powerConsumptionMw, boolean returnsTriggerInEvent) { |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 127 | this.id = id; |
| 128 | this.implementor = implementor; |
| 129 | this.description = description; |
| 130 | this.uuid = UUID.fromString(uuid); |
| 131 | this.version = version; |
| 132 | this.maxSoundModels = maxSoundModels; |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 133 | this.maxKeyphrases = maxKeyphrases; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 134 | this.maxUsers = maxUsers; |
| 135 | this.recognitionModes = recognitionModes; |
| 136 | this.supportsCaptureTransition = supportsCaptureTransition; |
| 137 | this.maxBufferMs = maxBufferMs; |
| 138 | this.supportsConcurrentCapture = supportsConcurrentCapture; |
| 139 | this.powerConsumptionMw = powerConsumptionMw; |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 140 | this.returnsTriggerInEvent = returnsTriggerInEvent; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 141 | } |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 142 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 143 | public static final @android.annotation.NonNull Parcelable.Creator<ModuleProperties> CREATOR |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 144 | = new Parcelable.Creator<ModuleProperties>() { |
| 145 | public ModuleProperties createFromParcel(Parcel in) { |
| 146 | return ModuleProperties.fromParcel(in); |
| 147 | } |
| 148 | |
| 149 | public ModuleProperties[] newArray(int size) { |
| 150 | return new ModuleProperties[size]; |
| 151 | } |
| 152 | }; |
| 153 | |
| 154 | private static ModuleProperties fromParcel(Parcel in) { |
| 155 | int id = in.readInt(); |
| 156 | String implementor = in.readString(); |
| 157 | String description = in.readString(); |
| 158 | String uuid = in.readString(); |
| 159 | int version = in.readInt(); |
| 160 | int maxSoundModels = in.readInt(); |
| 161 | int maxKeyphrases = in.readInt(); |
| 162 | int maxUsers = in.readInt(); |
| 163 | int recognitionModes = in.readInt(); |
| 164 | boolean supportsCaptureTransition = in.readByte() == 1; |
| 165 | int maxBufferMs = in.readInt(); |
| 166 | boolean supportsConcurrentCapture = in.readByte() == 1; |
| 167 | int powerConsumptionMw = in.readInt(); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 168 | boolean returnsTriggerInEvent = in.readByte() == 1; |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 169 | return new ModuleProperties(id, implementor, description, uuid, version, |
| 170 | maxSoundModels, maxKeyphrases, maxUsers, recognitionModes, |
| 171 | supportsCaptureTransition, maxBufferMs, supportsConcurrentCapture, |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 172 | powerConsumptionMw, returnsTriggerInEvent); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | @Override |
| 176 | public void writeToParcel(Parcel dest, int flags) { |
| 177 | dest.writeInt(id); |
| 178 | dest.writeString(implementor); |
| 179 | dest.writeString(description); |
| 180 | dest.writeString(uuid.toString()); |
| 181 | dest.writeInt(version); |
| 182 | dest.writeInt(maxSoundModels); |
| 183 | dest.writeInt(maxKeyphrases); |
| 184 | dest.writeInt(maxUsers); |
| 185 | dest.writeInt(recognitionModes); |
| 186 | dest.writeByte((byte) (supportsCaptureTransition ? 1 : 0)); |
| 187 | dest.writeInt(maxBufferMs); |
| 188 | dest.writeByte((byte) (supportsConcurrentCapture ? 1 : 0)); |
| 189 | dest.writeInt(powerConsumptionMw); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 190 | dest.writeByte((byte) (returnsTriggerInEvent ? 1 : 0)); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | @Override |
| 194 | public int describeContents() { |
| 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | @Override |
| 199 | public String toString() { |
| 200 | return "ModuleProperties [id=" + id + ", implementor=" + implementor + ", description=" |
| 201 | + description + ", uuid=" + uuid + ", version=" + version + ", maxSoundModels=" |
| 202 | + maxSoundModels + ", maxKeyphrases=" + maxKeyphrases + ", maxUsers=" |
| 203 | + maxUsers + ", recognitionModes=" + recognitionModes |
| 204 | + ", supportsCaptureTransition=" + supportsCaptureTransition + ", maxBufferMs=" |
| 205 | + maxBufferMs + ", supportsConcurrentCapture=" + supportsConcurrentCapture |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 206 | + ", powerConsumptionMw=" + powerConsumptionMw |
| 207 | + ", returnsTriggerInEvent=" + returnsTriggerInEvent + "]"; |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 208 | } |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | /***************************************************************************** |
| 212 | * A SoundModel describes the attributes and contains the binary data used by the hardware |
| 213 | * implementation to detect a particular sound pattern. |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 214 | * A specialized version {@link KeyphraseSoundModel} is defined for key phrase |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 215 | * sound models. |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 216 | * |
| 217 | * @hide |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 218 | ****************************************************************************/ |
| 219 | public static class SoundModel { |
| 220 | /** Undefined sound model type */ |
| 221 | public static final int TYPE_UNKNOWN = -1; |
| 222 | |
| 223 | /** Keyphrase sound model */ |
| 224 | public static final int TYPE_KEYPHRASE = 0; |
| 225 | |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 226 | /** |
| 227 | * A generic sound model. Use this type only for non-keyphrase sound models such as |
| 228 | * ones that match a particular sound pattern. |
| 229 | */ |
| 230 | public static final int TYPE_GENERIC_SOUND = 1; |
| 231 | |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 232 | /** Unique sound model identifier */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 233 | @UnsupportedAppUsage |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 234 | public final UUID uuid; |
| 235 | |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 236 | /** Sound model type (e.g. TYPE_KEYPHRASE); */ |
| 237 | public final int type; |
| 238 | |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 239 | /** Unique sound model vendor identifier */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 240 | @UnsupportedAppUsage |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 241 | public final UUID vendorUuid; |
| 242 | |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 243 | /** Opaque data. For use by vendor implementation and enrollment application */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 244 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 245 | public final byte[] data; |
| 246 | |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 247 | public SoundModel(UUID uuid, UUID vendorUuid, int type, byte[] data) { |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 248 | this.uuid = uuid; |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 249 | this.vendorUuid = vendorUuid; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 250 | this.type = type; |
| 251 | this.data = data; |
| 252 | } |
Sandeep Siddhartha | 45c00b5 | 2014-10-16 16:17:11 -0700 | [diff] [blame] | 253 | |
| 254 | @Override |
| 255 | public int hashCode() { |
| 256 | final int prime = 31; |
| 257 | int result = 1; |
| 258 | result = prime * result + Arrays.hashCode(data); |
| 259 | result = prime * result + type; |
| 260 | result = prime * result + ((uuid == null) ? 0 : uuid.hashCode()); |
| 261 | result = prime * result + ((vendorUuid == null) ? 0 : vendorUuid.hashCode()); |
| 262 | return result; |
| 263 | } |
| 264 | |
| 265 | @Override |
| 266 | public boolean equals(Object obj) { |
| 267 | if (this == obj) |
| 268 | return true; |
| 269 | if (obj == null) |
| 270 | return false; |
| 271 | if (!(obj instanceof SoundModel)) |
| 272 | return false; |
| 273 | SoundModel other = (SoundModel) obj; |
| 274 | if (!Arrays.equals(data, other.data)) |
| 275 | return false; |
| 276 | if (type != other.type) |
| 277 | return false; |
| 278 | if (uuid == null) { |
| 279 | if (other.uuid != null) |
| 280 | return false; |
| 281 | } else if (!uuid.equals(other.uuid)) |
| 282 | return false; |
| 283 | if (vendorUuid == null) { |
| 284 | if (other.vendorUuid != null) |
| 285 | return false; |
| 286 | } else if (!vendorUuid.equals(other.vendorUuid)) |
| 287 | return false; |
| 288 | return true; |
| 289 | } |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | /***************************************************************************** |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 293 | * A Keyphrase describes a key phrase that can be detected by a |
| 294 | * {@link KeyphraseSoundModel} |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 295 | * |
| 296 | * @hide |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 297 | ****************************************************************************/ |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 298 | public static class Keyphrase implements Parcelable { |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 299 | /** Unique identifier for this keyphrase */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 300 | @UnsupportedAppUsage |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 301 | public final int id; |
| 302 | |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 303 | /** Recognition modes supported for this key phrase in the model */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 304 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 305 | public final int recognitionModes; |
| 306 | |
| 307 | /** Locale of the keyphrase. JAVA Locale string e.g en_US */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 308 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 309 | public final String locale; |
| 310 | |
| 311 | /** Key phrase text */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 312 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 313 | public final String text; |
| 314 | |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 315 | /** Users this key phrase has been trained for. countains sound trigger specific user IDs |
| 316 | * derived from system user IDs {@link android.os.UserHandle#getIdentifier()}. */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 317 | @UnsupportedAppUsage |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 318 | public final int[] users; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 319 | |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 320 | @UnsupportedAppUsage |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 321 | public Keyphrase(int id, int recognitionModes, String locale, String text, int[] users) { |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 322 | this.id = id; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 323 | this.recognitionModes = recognitionModes; |
| 324 | this.locale = locale; |
| 325 | this.text = text; |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 326 | this.users = users; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 327 | } |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 328 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 329 | public static final @android.annotation.NonNull Parcelable.Creator<Keyphrase> CREATOR |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 330 | = new Parcelable.Creator<Keyphrase>() { |
| 331 | public Keyphrase createFromParcel(Parcel in) { |
| 332 | return Keyphrase.fromParcel(in); |
| 333 | } |
| 334 | |
| 335 | public Keyphrase[] newArray(int size) { |
| 336 | return new Keyphrase[size]; |
| 337 | } |
| 338 | }; |
| 339 | |
| 340 | private static Keyphrase fromParcel(Parcel in) { |
| 341 | int id = in.readInt(); |
| 342 | int recognitionModes = in.readInt(); |
| 343 | String locale = in.readString(); |
| 344 | String text = in.readString(); |
| 345 | int[] users = null; |
| 346 | int numUsers = in.readInt(); |
Sandeep Siddhartha | 110f569 | 2014-07-20 12:22:56 -0700 | [diff] [blame] | 347 | if (numUsers >= 0) { |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 348 | users = new int[numUsers]; |
| 349 | in.readIntArray(users); |
| 350 | } |
| 351 | return new Keyphrase(id, recognitionModes, locale, text, users); |
| 352 | } |
| 353 | |
| 354 | @Override |
| 355 | public void writeToParcel(Parcel dest, int flags) { |
| 356 | dest.writeInt(id); |
| 357 | dest.writeInt(recognitionModes); |
| 358 | dest.writeString(locale); |
| 359 | dest.writeString(text); |
| 360 | if (users != null) { |
| 361 | dest.writeInt(users.length); |
| 362 | dest.writeIntArray(users); |
| 363 | } else { |
Sandeep Siddhartha | 110f569 | 2014-07-20 12:22:56 -0700 | [diff] [blame] | 364 | dest.writeInt(-1); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | |
| 368 | @Override |
| 369 | public int describeContents() { |
| 370 | return 0; |
| 371 | } |
| 372 | |
| 373 | @Override |
| 374 | public int hashCode() { |
| 375 | final int prime = 31; |
| 376 | int result = 1; |
| 377 | result = prime * result + ((text == null) ? 0 : text.hashCode()); |
| 378 | result = prime * result + id; |
| 379 | result = prime * result + ((locale == null) ? 0 : locale.hashCode()); |
| 380 | result = prime * result + recognitionModes; |
| 381 | result = prime * result + Arrays.hashCode(users); |
| 382 | return result; |
| 383 | } |
| 384 | |
| 385 | @Override |
| 386 | public boolean equals(Object obj) { |
| 387 | if (this == obj) |
| 388 | return true; |
| 389 | if (obj == null) |
| 390 | return false; |
| 391 | if (getClass() != obj.getClass()) |
| 392 | return false; |
| 393 | Keyphrase other = (Keyphrase) obj; |
| 394 | if (text == null) { |
| 395 | if (other.text != null) |
| 396 | return false; |
| 397 | } else if (!text.equals(other.text)) |
| 398 | return false; |
| 399 | if (id != other.id) |
| 400 | return false; |
| 401 | if (locale == null) { |
| 402 | if (other.locale != null) |
| 403 | return false; |
| 404 | } else if (!locale.equals(other.locale)) |
| 405 | return false; |
| 406 | if (recognitionModes != other.recognitionModes) |
| 407 | return false; |
| 408 | if (!Arrays.equals(users, other.users)) |
| 409 | return false; |
| 410 | return true; |
| 411 | } |
| 412 | |
| 413 | @Override |
| 414 | public String toString() { |
| 415 | return "Keyphrase [id=" + id + ", recognitionModes=" + recognitionModes + ", locale=" |
| 416 | + locale + ", text=" + text + ", users=" + Arrays.toString(users) + "]"; |
| 417 | } |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | /***************************************************************************** |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 421 | * A KeyphraseSoundModel is a specialized {@link SoundModel} for key phrases. |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 422 | * 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] | 423 | * and the list of corresponding {@link Keyphrase} descriptors. |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 424 | * |
| 425 | * @hide |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 426 | ****************************************************************************/ |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 427 | public static class KeyphraseSoundModel extends SoundModel implements Parcelable { |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 428 | /** Key phrases in this sound model */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 429 | @UnsupportedAppUsage |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 430 | public final Keyphrase[] keyphrases; // keyword phrases in model |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 431 | |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 432 | @UnsupportedAppUsage |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 433 | public KeyphraseSoundModel( |
| 434 | UUID uuid, UUID vendorUuid, byte[] data, Keyphrase[] keyphrases) { |
| 435 | super(uuid, vendorUuid, TYPE_KEYPHRASE, data); |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 436 | this.keyphrases = keyphrases; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 437 | } |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 438 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 439 | public static final @android.annotation.NonNull Parcelable.Creator<KeyphraseSoundModel> CREATOR |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 440 | = new Parcelable.Creator<KeyphraseSoundModel>() { |
| 441 | public KeyphraseSoundModel createFromParcel(Parcel in) { |
| 442 | return KeyphraseSoundModel.fromParcel(in); |
| 443 | } |
| 444 | |
| 445 | public KeyphraseSoundModel[] newArray(int size) { |
| 446 | return new KeyphraseSoundModel[size]; |
| 447 | } |
| 448 | }; |
| 449 | |
| 450 | private static KeyphraseSoundModel fromParcel(Parcel in) { |
| 451 | UUID uuid = UUID.fromString(in.readString()); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 452 | UUID vendorUuid = null; |
| 453 | int length = in.readInt(); |
| 454 | if (length >= 0) { |
| 455 | vendorUuid = UUID.fromString(in.readString()); |
| 456 | } |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 457 | byte[] data = in.readBlob(); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 458 | Keyphrase[] keyphrases = in.createTypedArray(Keyphrase.CREATOR); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 459 | return new KeyphraseSoundModel(uuid, vendorUuid, data, keyphrases); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | @Override |
| 463 | public int describeContents() { |
| 464 | return 0; |
| 465 | } |
| 466 | |
| 467 | @Override |
| 468 | public void writeToParcel(Parcel dest, int flags) { |
| 469 | dest.writeString(uuid.toString()); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 470 | if (vendorUuid == null) { |
| 471 | dest.writeInt(-1); |
| 472 | } else { |
| 473 | dest.writeInt(vendorUuid.toString().length()); |
| 474 | dest.writeString(vendorUuid.toString()); |
| 475 | } |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 476 | dest.writeBlob(data); |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 477 | dest.writeTypedArray(keyphrases, flags); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 478 | } |
Sandeep Siddhartha | 110f569 | 2014-07-20 12:22:56 -0700 | [diff] [blame] | 479 | |
| 480 | @Override |
| 481 | public String toString() { |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 482 | return "KeyphraseSoundModel [keyphrases=" + Arrays.toString(keyphrases) |
| 483 | + ", uuid=" + uuid + ", vendorUuid=" + vendorUuid |
| 484 | + ", type=" + type + ", data=" + (data == null ? 0 : data.length) + "]"; |
Sandeep Siddhartha | 110f569 | 2014-07-20 12:22:56 -0700 | [diff] [blame] | 485 | } |
Sandeep Siddhartha | 45c00b5 | 2014-10-16 16:17:11 -0700 | [diff] [blame] | 486 | |
| 487 | @Override |
| 488 | public int hashCode() { |
| 489 | final int prime = 31; |
| 490 | int result = super.hashCode(); |
| 491 | result = prime * result + Arrays.hashCode(keyphrases); |
| 492 | return result; |
| 493 | } |
| 494 | |
| 495 | @Override |
| 496 | public boolean equals(Object obj) { |
| 497 | if (this == obj) |
| 498 | return true; |
| 499 | if (!super.equals(obj)) |
| 500 | return false; |
| 501 | if (!(obj instanceof KeyphraseSoundModel)) |
| 502 | return false; |
| 503 | KeyphraseSoundModel other = (KeyphraseSoundModel) obj; |
| 504 | if (!Arrays.equals(keyphrases, other.keyphrases)) |
| 505 | return false; |
| 506 | return true; |
| 507 | } |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 510 | |
| 511 | /***************************************************************************** |
| 512 | * A GenericSoundModel is a specialized {@link SoundModel} for non-voice sound |
| 513 | * patterns. |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 514 | * |
| 515 | * @hide |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 516 | ****************************************************************************/ |
| 517 | public static class GenericSoundModel extends SoundModel implements Parcelable { |
| 518 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 519 | public static final @android.annotation.NonNull Parcelable.Creator<GenericSoundModel> CREATOR |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 520 | = new Parcelable.Creator<GenericSoundModel>() { |
| 521 | public GenericSoundModel createFromParcel(Parcel in) { |
| 522 | return GenericSoundModel.fromParcel(in); |
| 523 | } |
| 524 | |
| 525 | public GenericSoundModel[] newArray(int size) { |
| 526 | return new GenericSoundModel[size]; |
| 527 | } |
| 528 | }; |
| 529 | |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 530 | @UnsupportedAppUsage |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 531 | public GenericSoundModel(UUID uuid, UUID vendorUuid, byte[] data) { |
| 532 | super(uuid, vendorUuid, TYPE_GENERIC_SOUND, data); |
| 533 | } |
| 534 | |
| 535 | @Override |
| 536 | public int describeContents() { |
| 537 | return 0; |
| 538 | } |
| 539 | |
| 540 | private static GenericSoundModel fromParcel(Parcel in) { |
| 541 | UUID uuid = UUID.fromString(in.readString()); |
| 542 | UUID vendorUuid = null; |
| 543 | int length = in.readInt(); |
| 544 | if (length >= 0) { |
| 545 | vendorUuid = UUID.fromString(in.readString()); |
| 546 | } |
| 547 | byte[] data = in.readBlob(); |
| 548 | return new GenericSoundModel(uuid, vendorUuid, data); |
| 549 | } |
| 550 | |
| 551 | @Override |
| 552 | public void writeToParcel(Parcel dest, int flags) { |
| 553 | dest.writeString(uuid.toString()); |
| 554 | if (vendorUuid == null) { |
| 555 | dest.writeInt(-1); |
| 556 | } else { |
| 557 | dest.writeInt(vendorUuid.toString().length()); |
| 558 | dest.writeString(vendorUuid.toString()); |
| 559 | } |
| 560 | dest.writeBlob(data); |
| 561 | } |
| 562 | |
| 563 | @Override |
| 564 | public String toString() { |
| 565 | return "GenericSoundModel [uuid=" + uuid + ", vendorUuid=" + vendorUuid |
| 566 | + ", type=" + type + ", data=" + (data == null ? 0 : data.length) + "]"; |
| 567 | } |
| 568 | } |
| 569 | |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 570 | /** |
| 571 | * Modes for key phrase recognition |
| 572 | */ |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 573 | |
| 574 | /** |
| 575 | * Simple recognition of the key phrase |
| 576 | * |
| 577 | * @hide |
| 578 | */ |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 579 | public static final int RECOGNITION_MODE_VOICE_TRIGGER = 0x1; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 580 | /** |
| 581 | * Trigger only if one user is identified |
| 582 | * |
| 583 | * @hide |
| 584 | */ |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 585 | public static final int RECOGNITION_MODE_USER_IDENTIFICATION = 0x2; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 586 | /** |
| 587 | * Trigger only if one user is authenticated |
| 588 | * |
| 589 | * @hide |
| 590 | */ |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 591 | public static final int RECOGNITION_MODE_USER_AUTHENTICATION = 0x4; |
| 592 | |
| 593 | /** |
| 594 | * Status codes for {@link RecognitionEvent} |
| 595 | */ |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 596 | /** |
| 597 | * Recognition success |
| 598 | * |
| 599 | * @hide |
| 600 | */ |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 601 | public static final int RECOGNITION_STATUS_SUCCESS = 0; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 602 | /** |
| 603 | * Recognition aborted (e.g. capture preempted by anotehr use case |
| 604 | * |
| 605 | * @hide |
| 606 | */ |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 607 | public static final int RECOGNITION_STATUS_ABORT = 1; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 608 | /** |
| 609 | * Recognition failure |
| 610 | * |
| 611 | * @hide |
| 612 | */ |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 613 | public static final int RECOGNITION_STATUS_FAILURE = 2; |
mike dooley | b2ab04a | 2018-11-07 15:48:54 +0100 | [diff] [blame] | 614 | /** |
| 615 | * Recognition event was triggered by a getModelState request, not by the |
| 616 | * DSP. |
| 617 | * |
| 618 | * @hide |
| 619 | */ |
| 620 | public static final int RECOGNITION_STATUS_GET_STATE_RESPONSE = 3; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 621 | |
| 622 | /** |
| 623 | * A RecognitionEvent is provided by the |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 624 | * {@code StatusListener#onRecognition(RecognitionEvent)} |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 625 | * callback upon recognition success or failure. |
| 626 | */ |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 627 | public static class RecognitionEvent { |
| 628 | /** |
| 629 | * Recognition status e.g RECOGNITION_STATUS_SUCCESS |
| 630 | * |
| 631 | * @hide |
| 632 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 633 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 634 | public final int status; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 635 | /** |
| 636 | * |
| 637 | * Sound Model corresponding to this event callback |
| 638 | * |
| 639 | * @hide |
| 640 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 641 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 642 | public final int soundModelHandle; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 643 | /** |
| 644 | * True if it is possible to capture audio from this utterance buffered by the hardware |
| 645 | * |
| 646 | * @hide |
| 647 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 648 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 649 | public final boolean captureAvailable; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 650 | /** |
| 651 | * Audio session ID to be used when capturing the utterance with an AudioRecord |
| 652 | * if captureAvailable() is true. |
| 653 | * |
| 654 | * @hide |
| 655 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 656 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 657 | public final int captureSession; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 658 | /** |
| 659 | * Delay in ms between end of model detection and start of audio available for capture. |
| 660 | * A negative value is possible (e.g. if keyphrase is also available for capture) |
| 661 | * |
| 662 | * @hide |
| 663 | */ |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 664 | public final int captureDelayMs; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 665 | /** |
| 666 | * Duration in ms of audio captured before the start of the trigger. 0 if none. |
| 667 | * |
| 668 | * @hide |
| 669 | */ |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 670 | public final int capturePreambleMs; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 671 | /** |
| 672 | * True if the trigger (key phrase capture is present in binary data |
| 673 | * |
| 674 | * @hide |
| 675 | */ |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 676 | public final boolean triggerInData; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 677 | /** |
| 678 | * Audio format of either the trigger in event data or to use for capture of the |
| 679 | * rest of the utterance |
| 680 | * |
| 681 | * @hide |
| 682 | */ |
| 683 | public final AudioFormat captureFormat; |
| 684 | /** |
| 685 | * Opaque data for use by system applications who know about voice engine internals, |
| 686 | * typically during enrollment. |
| 687 | * |
| 688 | * @hide |
| 689 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 690 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 691 | public final byte[] data; |
| 692 | |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 693 | /** @hide */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 694 | @UnsupportedAppUsage |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 695 | public RecognitionEvent(int status, int soundModelHandle, boolean captureAvailable, |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 696 | int captureSession, int captureDelayMs, int capturePreambleMs, |
| 697 | boolean triggerInData, AudioFormat captureFormat, byte[] data) { |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 698 | this.status = status; |
| 699 | this.soundModelHandle = soundModelHandle; |
| 700 | this.captureAvailable = captureAvailable; |
| 701 | this.captureSession = captureSession; |
| 702 | this.captureDelayMs = captureDelayMs; |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 703 | this.capturePreambleMs = capturePreambleMs; |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 704 | this.triggerInData = triggerInData; |
| 705 | this.captureFormat = captureFormat; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 706 | this.data = data; |
| 707 | } |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 708 | |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 709 | /** |
| 710 | * Check if is possible to capture audio from this utterance buffered by the hardware. |
| 711 | * |
| 712 | * @return {@code true} iff a capturing is possible |
| 713 | */ |
| 714 | public boolean isCaptureAvailable() { |
| 715 | return captureAvailable; |
| 716 | } |
| 717 | |
| 718 | /** |
| 719 | * Get the audio format of either the trigger in event data or to use for capture of the |
| 720 | * rest of the utterance |
| 721 | * |
| 722 | * @return the audio format |
| 723 | */ |
| 724 | @Nullable public AudioFormat getCaptureFormat() { |
| 725 | return captureFormat; |
| 726 | } |
| 727 | |
| 728 | /** |
| 729 | * Get Audio session ID to be used when capturing the utterance with an {@link AudioRecord} |
| 730 | * if {@link #isCaptureAvailable()} is true. |
| 731 | * |
| 732 | * @return The id of the capture session |
| 733 | */ |
| 734 | public int getCaptureSession() { |
| 735 | return captureSession; |
| 736 | } |
| 737 | |
| 738 | /** |
| 739 | * Get the opaque data for use by system applications who know about voice engine |
| 740 | * internals, typically during enrollment. |
| 741 | * |
| 742 | * @return The data of the event |
| 743 | */ |
| 744 | public byte[] getData() { |
| 745 | return data; |
| 746 | } |
| 747 | |
| 748 | /** @hide */ |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 749 | public static final @android.annotation.NonNull Parcelable.Creator<RecognitionEvent> CREATOR |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 750 | = new Parcelable.Creator<RecognitionEvent>() { |
| 751 | public RecognitionEvent createFromParcel(Parcel in) { |
| 752 | return RecognitionEvent.fromParcel(in); |
| 753 | } |
| 754 | |
| 755 | public RecognitionEvent[] newArray(int size) { |
| 756 | return new RecognitionEvent[size]; |
| 757 | } |
| 758 | }; |
| 759 | |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 760 | /** @hide */ |
Arunesh Mishra | f47f173 | 2016-02-18 16:16:12 -0800 | [diff] [blame] | 761 | protected static RecognitionEvent fromParcel(Parcel in) { |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 762 | int status = in.readInt(); |
| 763 | int soundModelHandle = in.readInt(); |
| 764 | boolean captureAvailable = in.readByte() == 1; |
| 765 | int captureSession = in.readInt(); |
| 766 | int captureDelayMs = in.readInt(); |
| 767 | int capturePreambleMs = in.readInt(); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 768 | boolean triggerInData = in.readByte() == 1; |
| 769 | AudioFormat captureFormat = null; |
Eric Laurent | 39fcca0 | 2014-09-05 16:44:19 -0700 | [diff] [blame] | 770 | if (in.readByte() == 1) { |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 771 | int sampleRate = in.readInt(); |
| 772 | int encoding = in.readInt(); |
| 773 | int channelMask = in.readInt(); |
| 774 | captureFormat = (new AudioFormat.Builder()) |
| 775 | .setChannelMask(channelMask) |
| 776 | .setEncoding(encoding) |
| 777 | .setSampleRate(sampleRate) |
| 778 | .build(); |
| 779 | } |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 780 | byte[] data = in.readBlob(); |
| 781 | return new RecognitionEvent(status, soundModelHandle, captureAvailable, captureSession, |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 782 | captureDelayMs, capturePreambleMs, triggerInData, captureFormat, data); |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 783 | } |
| 784 | |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 785 | /** @hide */ |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 786 | public int describeContents() { |
| 787 | return 0; |
| 788 | } |
| 789 | |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 790 | /** @hide */ |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 791 | public void writeToParcel(Parcel dest, int flags) { |
| 792 | dest.writeInt(status); |
| 793 | dest.writeInt(soundModelHandle); |
| 794 | dest.writeByte((byte) (captureAvailable ? 1 : 0)); |
| 795 | dest.writeInt(captureSession); |
| 796 | dest.writeInt(captureDelayMs); |
| 797 | dest.writeInt(capturePreambleMs); |
Eric Laurent | 39fcca0 | 2014-09-05 16:44:19 -0700 | [diff] [blame] | 798 | dest.writeByte((byte) (triggerInData ? 1 : 0)); |
| 799 | if (captureFormat != null) { |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 800 | dest.writeByte((byte)1); |
| 801 | dest.writeInt(captureFormat.getSampleRate()); |
| 802 | dest.writeInt(captureFormat.getEncoding()); |
| 803 | dest.writeInt(captureFormat.getChannelMask()); |
| 804 | } else { |
| 805 | dest.writeByte((byte)0); |
| 806 | } |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 807 | dest.writeBlob(data); |
| 808 | } |
| 809 | |
| 810 | @Override |
| 811 | public int hashCode() { |
| 812 | final int prime = 31; |
| 813 | int result = 1; |
| 814 | result = prime * result + (captureAvailable ? 1231 : 1237); |
| 815 | result = prime * result + captureDelayMs; |
| 816 | result = prime * result + capturePreambleMs; |
| 817 | result = prime * result + captureSession; |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 818 | result = prime * result + (triggerInData ? 1231 : 1237); |
| 819 | if (captureFormat != null) { |
| 820 | result = prime * result + captureFormat.getSampleRate(); |
| 821 | result = prime * result + captureFormat.getEncoding(); |
| 822 | result = prime * result + captureFormat.getChannelMask(); |
| 823 | } |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 824 | result = prime * result + Arrays.hashCode(data); |
| 825 | result = prime * result + soundModelHandle; |
| 826 | result = prime * result + status; |
| 827 | return result; |
| 828 | } |
| 829 | |
| 830 | @Override |
| 831 | public boolean equals(Object obj) { |
| 832 | if (this == obj) |
| 833 | return true; |
| 834 | if (obj == null) |
| 835 | return false; |
| 836 | if (getClass() != obj.getClass()) |
| 837 | return false; |
| 838 | RecognitionEvent other = (RecognitionEvent) obj; |
| 839 | if (captureAvailable != other.captureAvailable) |
| 840 | return false; |
| 841 | if (captureDelayMs != other.captureDelayMs) |
| 842 | return false; |
| 843 | if (capturePreambleMs != other.capturePreambleMs) |
| 844 | return false; |
| 845 | if (captureSession != other.captureSession) |
| 846 | return false; |
| 847 | if (!Arrays.equals(data, other.data)) |
| 848 | return false; |
| 849 | if (soundModelHandle != other.soundModelHandle) |
| 850 | return false; |
| 851 | if (status != other.status) |
| 852 | return false; |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 853 | if (triggerInData != other.triggerInData) |
| 854 | return false; |
Ryan Bavetta | ea04e8f | 2016-03-02 18:34:50 -0800 | [diff] [blame] | 855 | if (captureFormat == null) { |
| 856 | if (other.captureFormat != null) |
| 857 | return false; |
| 858 | } else { |
| 859 | if (other.captureFormat == null) |
| 860 | return false; |
| 861 | if (captureFormat.getSampleRate() != other.captureFormat.getSampleRate()) |
| 862 | return false; |
| 863 | if (captureFormat.getEncoding() != other.captureFormat.getEncoding()) |
| 864 | return false; |
| 865 | if (captureFormat.getChannelMask() != other.captureFormat.getChannelMask()) |
| 866 | return false; |
| 867 | } |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 868 | return true; |
| 869 | } |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 870 | |
| 871 | @Override |
| 872 | public String toString() { |
| 873 | return "RecognitionEvent [status=" + status + ", soundModelHandle=" + soundModelHandle |
| 874 | + ", captureAvailable=" + captureAvailable + ", captureSession=" |
| 875 | + captureSession + ", captureDelayMs=" + captureDelayMs |
| 876 | + ", capturePreambleMs=" + capturePreambleMs |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 877 | + ", triggerInData=" + triggerInData |
| 878 | + ((captureFormat == null) ? "" : |
| 879 | (", sampleRate=" + captureFormat.getSampleRate())) |
| 880 | + ((captureFormat == null) ? "" : |
| 881 | (", encoding=" + captureFormat.getEncoding())) |
| 882 | + ((captureFormat == null) ? "" : |
| 883 | (", channelMask=" + captureFormat.getChannelMask())) |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 884 | + ", data=" + (data == null ? 0 : data.length) + "]"; |
| 885 | } |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | /** |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 889 | * A RecognitionConfig is provided to |
| 890 | * {@link SoundTriggerModule#startRecognition(int, RecognitionConfig)} to configure the |
| 891 | * recognition request. |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 892 | * |
| 893 | * @hide |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 894 | */ |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 895 | public static class RecognitionConfig implements Parcelable { |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 896 | /** True if the DSP should capture the trigger sound and make it available for further |
| 897 | * capture. */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 898 | @UnsupportedAppUsage |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 899 | public final boolean captureRequested; |
Sandeep Siddhartha | 2c0273e | 2014-08-01 11:32:03 -0700 | [diff] [blame] | 900 | /** |
| 901 | * True if the service should restart listening after the DSP triggers. |
| 902 | * Note: This config flag is currently used at the service layer rather than by the DSP. |
| 903 | */ |
| 904 | public final boolean allowMultipleTriggers; |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 905 | /** List of all keyphrases in the sound model for which recognition should be performed with |
| 906 | * options for each keyphrase. */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 907 | @UnsupportedAppUsage |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 908 | public final KeyphraseRecognitionExtra keyphrases[]; |
| 909 | /** Opaque data for use by system applications who know about voice engine internals, |
| 910 | * typically during enrollment. */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 911 | @UnsupportedAppUsage |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 912 | public final byte[] data; |
| 913 | |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 914 | @UnsupportedAppUsage |
Sandeep Siddhartha | 2c0273e | 2014-08-01 11:32:03 -0700 | [diff] [blame] | 915 | public RecognitionConfig(boolean captureRequested, boolean allowMultipleTriggers, |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 916 | KeyphraseRecognitionExtra[] keyphrases, byte[] data) { |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 917 | this.captureRequested = captureRequested; |
Sandeep Siddhartha | 2c0273e | 2014-08-01 11:32:03 -0700 | [diff] [blame] | 918 | this.allowMultipleTriggers = allowMultipleTriggers; |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 919 | this.keyphrases = keyphrases; |
| 920 | this.data = data; |
| 921 | } |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 922 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 923 | public static final @android.annotation.NonNull Parcelable.Creator<RecognitionConfig> CREATOR |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 924 | = new Parcelable.Creator<RecognitionConfig>() { |
| 925 | public RecognitionConfig createFromParcel(Parcel in) { |
| 926 | return RecognitionConfig.fromParcel(in); |
| 927 | } |
| 928 | |
| 929 | public RecognitionConfig[] newArray(int size) { |
| 930 | return new RecognitionConfig[size]; |
| 931 | } |
| 932 | }; |
| 933 | |
| 934 | private static RecognitionConfig fromParcel(Parcel in) { |
| 935 | boolean captureRequested = in.readByte() == 1; |
Sandeep Siddhartha | 2c0273e | 2014-08-01 11:32:03 -0700 | [diff] [blame] | 936 | boolean allowMultipleTriggers = in.readByte() == 1; |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 937 | KeyphraseRecognitionExtra[] keyphrases = |
| 938 | in.createTypedArray(KeyphraseRecognitionExtra.CREATOR); |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 939 | byte[] data = in.readBlob(); |
Sandeep Siddhartha | 2c0273e | 2014-08-01 11:32:03 -0700 | [diff] [blame] | 940 | return new RecognitionConfig(captureRequested, allowMultipleTriggers, keyphrases, data); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | @Override |
| 944 | public void writeToParcel(Parcel dest, int flags) { |
| 945 | dest.writeByte((byte) (captureRequested ? 1 : 0)); |
Sandeep Siddhartha | 2c0273e | 2014-08-01 11:32:03 -0700 | [diff] [blame] | 946 | dest.writeByte((byte) (allowMultipleTriggers ? 1 : 0)); |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 947 | dest.writeTypedArray(keyphrases, flags); |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 948 | dest.writeBlob(data); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | @Override |
| 952 | public int describeContents() { |
| 953 | return 0; |
| 954 | } |
Sandeep Siddhartha | 110f569 | 2014-07-20 12:22:56 -0700 | [diff] [blame] | 955 | |
| 956 | @Override |
| 957 | public String toString() { |
Sandeep Siddhartha | 2c0273e | 2014-08-01 11:32:03 -0700 | [diff] [blame] | 958 | return "RecognitionConfig [captureRequested=" + captureRequested |
| 959 | + ", allowMultipleTriggers=" + allowMultipleTriggers + ", keyphrases=" |
| 960 | + Arrays.toString(keyphrases) + ", data=" + Arrays.toString(data) + "]"; |
Sandeep Siddhartha | 110f569 | 2014-07-20 12:22:56 -0700 | [diff] [blame] | 961 | } |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | /** |
| 965 | * Confidence level for users defined in a keyphrase. |
| 966 | * - The confidence level is expressed in percent (0% -100%). |
| 967 | * When used in a {@link KeyphraseRecognitionEvent} it indicates the detected confidence level |
| 968 | * When used in a {@link RecognitionConfig} it indicates the minimum confidence level that |
| 969 | * should trigger a recognition. |
| 970 | * - 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] | 971 | * |
| 972 | * @hide |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 973 | */ |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 974 | public static class ConfidenceLevel implements Parcelable { |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 975 | @UnsupportedAppUsage |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 976 | public final int userId; |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 977 | @UnsupportedAppUsage |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 978 | public final int confidenceLevel; |
| 979 | |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 980 | @UnsupportedAppUsage |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 981 | public ConfidenceLevel(int userId, int confidenceLevel) { |
| 982 | this.userId = userId; |
| 983 | this.confidenceLevel = confidenceLevel; |
| 984 | } |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 985 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 986 | public static final @android.annotation.NonNull Parcelable.Creator<ConfidenceLevel> CREATOR |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 987 | = new Parcelable.Creator<ConfidenceLevel>() { |
| 988 | public ConfidenceLevel createFromParcel(Parcel in) { |
| 989 | return ConfidenceLevel.fromParcel(in); |
| 990 | } |
| 991 | |
| 992 | public ConfidenceLevel[] newArray(int size) { |
| 993 | return new ConfidenceLevel[size]; |
| 994 | } |
| 995 | }; |
| 996 | |
| 997 | private static ConfidenceLevel fromParcel(Parcel in) { |
| 998 | int userId = in.readInt(); |
| 999 | int confidenceLevel = in.readInt(); |
| 1000 | return new ConfidenceLevel(userId, confidenceLevel); |
| 1001 | } |
| 1002 | |
| 1003 | @Override |
| 1004 | public void writeToParcel(Parcel dest, int flags) { |
| 1005 | dest.writeInt(userId); |
| 1006 | dest.writeInt(confidenceLevel); |
| 1007 | } |
| 1008 | |
| 1009 | @Override |
| 1010 | public int describeContents() { |
| 1011 | return 0; |
| 1012 | } |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1013 | |
| 1014 | @Override |
| 1015 | public int hashCode() { |
| 1016 | final int prime = 31; |
| 1017 | int result = 1; |
| 1018 | result = prime * result + confidenceLevel; |
| 1019 | result = prime * result + userId; |
| 1020 | return result; |
| 1021 | } |
| 1022 | |
| 1023 | @Override |
| 1024 | public boolean equals(Object obj) { |
| 1025 | if (this == obj) |
| 1026 | return true; |
| 1027 | if (obj == null) |
| 1028 | return false; |
| 1029 | if (getClass() != obj.getClass()) |
| 1030 | return false; |
| 1031 | ConfidenceLevel other = (ConfidenceLevel) obj; |
| 1032 | if (confidenceLevel != other.confidenceLevel) |
| 1033 | return false; |
| 1034 | if (userId != other.userId) |
| 1035 | return false; |
| 1036 | return true; |
| 1037 | } |
| 1038 | |
| 1039 | @Override |
| 1040 | public String toString() { |
| 1041 | return "ConfidenceLevel [userId=" + userId |
| 1042 | + ", confidenceLevel=" + confidenceLevel + "]"; |
| 1043 | } |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | /** |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 1047 | * Additional data conveyed by a {@link KeyphraseRecognitionEvent} |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1048 | * for a key phrase detection. |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1049 | * |
| 1050 | * @hide |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1051 | */ |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1052 | public static class KeyphraseRecognitionExtra implements Parcelable { |
| 1053 | /** The keyphrase ID */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1054 | @UnsupportedAppUsage |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1055 | public final int id; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1056 | |
| 1057 | /** Recognition modes matched for this event */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1058 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1059 | public final int recognitionModes; |
| 1060 | |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1061 | /** Confidence level for mode RECOGNITION_MODE_VOICE_TRIGGER when user identification |
| 1062 | * is not performed */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1063 | @UnsupportedAppUsage |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1064 | public final int coarseConfidenceLevel; |
| 1065 | |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1066 | /** Confidence levels for all users recognized (KeyphraseRecognitionEvent) or to |
| 1067 | * be recognized (RecognitionConfig) */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1068 | @UnsupportedAppUsage |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1069 | public final ConfidenceLevel[] confidenceLevels; |
| 1070 | |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1071 | @UnsupportedAppUsage |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1072 | public KeyphraseRecognitionExtra(int id, int recognitionModes, int coarseConfidenceLevel, |
| 1073 | ConfidenceLevel[] confidenceLevels) { |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1074 | this.id = id; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1075 | this.recognitionModes = recognitionModes; |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1076 | this.coarseConfidenceLevel = coarseConfidenceLevel; |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1077 | this.confidenceLevels = confidenceLevels; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1078 | } |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1079 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 1080 | public static final @android.annotation.NonNull Parcelable.Creator<KeyphraseRecognitionExtra> CREATOR |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1081 | = new Parcelable.Creator<KeyphraseRecognitionExtra>() { |
| 1082 | public KeyphraseRecognitionExtra createFromParcel(Parcel in) { |
| 1083 | return KeyphraseRecognitionExtra.fromParcel(in); |
| 1084 | } |
| 1085 | |
| 1086 | public KeyphraseRecognitionExtra[] newArray(int size) { |
| 1087 | return new KeyphraseRecognitionExtra[size]; |
| 1088 | } |
| 1089 | }; |
| 1090 | |
| 1091 | private static KeyphraseRecognitionExtra fromParcel(Parcel in) { |
| 1092 | int id = in.readInt(); |
| 1093 | int recognitionModes = in.readInt(); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1094 | int coarseConfidenceLevel = in.readInt(); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1095 | ConfidenceLevel[] confidenceLevels = in.createTypedArray(ConfidenceLevel.CREATOR); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1096 | return new KeyphraseRecognitionExtra(id, recognitionModes, coarseConfidenceLevel, |
| 1097 | confidenceLevels); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | @Override |
| 1101 | public void writeToParcel(Parcel dest, int flags) { |
| 1102 | dest.writeInt(id); |
| 1103 | dest.writeInt(recognitionModes); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1104 | dest.writeInt(coarseConfidenceLevel); |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1105 | dest.writeTypedArray(confidenceLevels, flags); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | @Override |
| 1109 | public int describeContents() { |
| 1110 | return 0; |
| 1111 | } |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1112 | |
| 1113 | @Override |
| 1114 | public int hashCode() { |
| 1115 | final int prime = 31; |
| 1116 | int result = 1; |
| 1117 | result = prime * result + Arrays.hashCode(confidenceLevels); |
| 1118 | result = prime * result + id; |
| 1119 | result = prime * result + recognitionModes; |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1120 | result = prime * result + coarseConfidenceLevel; |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1121 | return result; |
| 1122 | } |
| 1123 | |
| 1124 | @Override |
| 1125 | public boolean equals(Object obj) { |
| 1126 | if (this == obj) |
| 1127 | return true; |
| 1128 | if (obj == null) |
| 1129 | return false; |
| 1130 | if (getClass() != obj.getClass()) |
| 1131 | return false; |
| 1132 | KeyphraseRecognitionExtra other = (KeyphraseRecognitionExtra) obj; |
| 1133 | if (!Arrays.equals(confidenceLevels, other.confidenceLevels)) |
| 1134 | return false; |
| 1135 | if (id != other.id) |
| 1136 | return false; |
| 1137 | if (recognitionModes != other.recognitionModes) |
| 1138 | return false; |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1139 | if (coarseConfidenceLevel != other.coarseConfidenceLevel) |
| 1140 | return false; |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1141 | return true; |
| 1142 | } |
| 1143 | |
| 1144 | @Override |
| 1145 | public String toString() { |
| 1146 | return "KeyphraseRecognitionExtra [id=" + id + ", recognitionModes=" + recognitionModes |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1147 | + ", coarseConfidenceLevel=" + coarseConfidenceLevel |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1148 | + ", confidenceLevels=" + Arrays.toString(confidenceLevels) + "]"; |
| 1149 | } |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | /** |
| 1153 | * Specialized {@link RecognitionEvent} for a key phrase detection. |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1154 | * |
| 1155 | * @hide |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1156 | */ |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1157 | public static class KeyphraseRecognitionEvent extends RecognitionEvent implements Parcelable { |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1158 | /** 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] | 1159 | @UnsupportedAppUsage |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 1160 | public final KeyphraseRecognitionExtra[] keyphraseExtras; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1161 | |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1162 | @UnsupportedAppUsage |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1163 | public KeyphraseRecognitionEvent(int status, int soundModelHandle, boolean captureAvailable, |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1164 | int captureSession, int captureDelayMs, int capturePreambleMs, |
| 1165 | boolean triggerInData, AudioFormat captureFormat, byte[] data, |
| 1166 | KeyphraseRecognitionExtra[] keyphraseExtras) { |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1167 | super(status, soundModelHandle, captureAvailable, captureSession, captureDelayMs, |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1168 | capturePreambleMs, triggerInData, captureFormat, data); |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 1169 | this.keyphraseExtras = keyphraseExtras; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1170 | } |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1171 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 1172 | public static final @android.annotation.NonNull Parcelable.Creator<KeyphraseRecognitionEvent> CREATOR |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1173 | = new Parcelable.Creator<KeyphraseRecognitionEvent>() { |
| 1174 | public KeyphraseRecognitionEvent createFromParcel(Parcel in) { |
Arunesh Mishra | f47f173 | 2016-02-18 16:16:12 -0800 | [diff] [blame] | 1175 | return KeyphraseRecognitionEvent.fromParcelForKeyphrase(in); |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | public KeyphraseRecognitionEvent[] newArray(int size) { |
| 1179 | return new KeyphraseRecognitionEvent[size]; |
| 1180 | } |
| 1181 | }; |
| 1182 | |
Arunesh Mishra | f47f173 | 2016-02-18 16:16:12 -0800 | [diff] [blame] | 1183 | private static KeyphraseRecognitionEvent fromParcelForKeyphrase(Parcel in) { |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1184 | int status = in.readInt(); |
| 1185 | int soundModelHandle = in.readInt(); |
| 1186 | boolean captureAvailable = in.readByte() == 1; |
| 1187 | int captureSession = in.readInt(); |
| 1188 | int captureDelayMs = in.readInt(); |
| 1189 | int capturePreambleMs = in.readInt(); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1190 | boolean triggerInData = in.readByte() == 1; |
| 1191 | AudioFormat captureFormat = null; |
Eric Laurent | 75b433f | 2014-09-12 15:45:47 -0700 | [diff] [blame] | 1192 | if (in.readByte() == 1) { |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1193 | int sampleRate = in.readInt(); |
| 1194 | int encoding = in.readInt(); |
| 1195 | int channelMask = in.readInt(); |
| 1196 | captureFormat = (new AudioFormat.Builder()) |
Ryan Bavetta | ea04e8f | 2016-03-02 18:34:50 -0800 | [diff] [blame] | 1197 | .setChannelMask(channelMask) |
| 1198 | .setEncoding(encoding) |
| 1199 | .setSampleRate(sampleRate) |
| 1200 | .build(); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1201 | } |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1202 | byte[] data = in.readBlob(); |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1203 | KeyphraseRecognitionExtra[] keyphraseExtras = |
| 1204 | in.createTypedArray(KeyphraseRecognitionExtra.CREATOR); |
| 1205 | return new KeyphraseRecognitionEvent(status, soundModelHandle, captureAvailable, |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1206 | captureSession, captureDelayMs, capturePreambleMs, triggerInData, |
| 1207 | captureFormat, data, keyphraseExtras); |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | @Override |
| 1211 | public void writeToParcel(Parcel dest, int flags) { |
| 1212 | dest.writeInt(status); |
| 1213 | dest.writeInt(soundModelHandle); |
| 1214 | dest.writeByte((byte) (captureAvailable ? 1 : 0)); |
| 1215 | dest.writeInt(captureSession); |
| 1216 | dest.writeInt(captureDelayMs); |
| 1217 | dest.writeInt(capturePreambleMs); |
Eric Laurent | 75b433f | 2014-09-12 15:45:47 -0700 | [diff] [blame] | 1218 | dest.writeByte((byte) (triggerInData ? 1 : 0)); |
| 1219 | if (captureFormat != null) { |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1220 | dest.writeByte((byte)1); |
| 1221 | dest.writeInt(captureFormat.getSampleRate()); |
| 1222 | dest.writeInt(captureFormat.getEncoding()); |
| 1223 | dest.writeInt(captureFormat.getChannelMask()); |
| 1224 | } else { |
| 1225 | dest.writeByte((byte)0); |
| 1226 | } |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1227 | dest.writeBlob(data); |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1228 | dest.writeTypedArray(keyphraseExtras, flags); |
| 1229 | } |
| 1230 | |
| 1231 | @Override |
| 1232 | public int describeContents() { |
| 1233 | return 0; |
| 1234 | } |
| 1235 | |
| 1236 | @Override |
| 1237 | public int hashCode() { |
| 1238 | final int prime = 31; |
| 1239 | int result = super.hashCode(); |
| 1240 | result = prime * result + Arrays.hashCode(keyphraseExtras); |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1241 | return result; |
| 1242 | } |
| 1243 | |
| 1244 | @Override |
| 1245 | public boolean equals(Object obj) { |
| 1246 | if (this == obj) |
| 1247 | return true; |
| 1248 | if (!super.equals(obj)) |
| 1249 | return false; |
| 1250 | if (getClass() != obj.getClass()) |
| 1251 | return false; |
| 1252 | KeyphraseRecognitionEvent other = (KeyphraseRecognitionEvent) obj; |
| 1253 | if (!Arrays.equals(keyphraseExtras, other.keyphraseExtras)) |
| 1254 | return false; |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1255 | return true; |
| 1256 | } |
| 1257 | |
| 1258 | @Override |
| 1259 | public String toString() { |
| 1260 | return "KeyphraseRecognitionEvent [keyphraseExtras=" + Arrays.toString(keyphraseExtras) |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1261 | + ", status=" + status |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1262 | + ", soundModelHandle=" + soundModelHandle + ", captureAvailable=" |
| 1263 | + captureAvailable + ", captureSession=" + captureSession + ", captureDelayMs=" |
| 1264 | + captureDelayMs + ", capturePreambleMs=" + capturePreambleMs |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1265 | + ", triggerInData=" + triggerInData |
| 1266 | + ((captureFormat == null) ? "" : |
| 1267 | (", sampleRate=" + captureFormat.getSampleRate())) |
| 1268 | + ((captureFormat == null) ? "" : |
| 1269 | (", encoding=" + captureFormat.getEncoding())) |
| 1270 | + ((captureFormat == null) ? "" : |
| 1271 | (", channelMask=" + captureFormat.getChannelMask())) |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1272 | + ", data=" + (data == null ? 0 : data.length) + "]"; |
| 1273 | } |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | /** |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 1277 | * Sub-class of RecognitionEvent specifically for sound-trigger based sound |
| 1278 | * models(non-keyphrase). Currently does not contain any additional fields. |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1279 | * |
| 1280 | * @hide |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 1281 | */ |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1282 | public static class GenericRecognitionEvent extends RecognitionEvent implements Parcelable { |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1283 | @UnsupportedAppUsage |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 1284 | public GenericRecognitionEvent(int status, int soundModelHandle, |
| 1285 | boolean captureAvailable, int captureSession, int captureDelayMs, |
| 1286 | int capturePreambleMs, boolean triggerInData, AudioFormat captureFormat, |
| 1287 | byte[] data) { |
| 1288 | super(status, soundModelHandle, captureAvailable, captureSession, |
| 1289 | captureDelayMs, capturePreambleMs, triggerInData, captureFormat, |
| 1290 | data); |
| 1291 | } |
Arunesh Mishra | f47f173 | 2016-02-18 16:16:12 -0800 | [diff] [blame] | 1292 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 1293 | public static final @android.annotation.NonNull Parcelable.Creator<GenericRecognitionEvent> CREATOR |
Arunesh Mishra | f47f173 | 2016-02-18 16:16:12 -0800 | [diff] [blame] | 1294 | = new Parcelable.Creator<GenericRecognitionEvent>() { |
| 1295 | public GenericRecognitionEvent createFromParcel(Parcel in) { |
| 1296 | return GenericRecognitionEvent.fromParcelForGeneric(in); |
| 1297 | } |
| 1298 | |
| 1299 | public GenericRecognitionEvent[] newArray(int size) { |
| 1300 | return new GenericRecognitionEvent[size]; |
| 1301 | } |
| 1302 | }; |
| 1303 | |
| 1304 | private static GenericRecognitionEvent fromParcelForGeneric(Parcel in) { |
| 1305 | RecognitionEvent event = RecognitionEvent.fromParcel(in); |
| 1306 | return new GenericRecognitionEvent(event.status, event.soundModelHandle, |
| 1307 | event.captureAvailable, event.captureSession, event.captureDelayMs, |
| 1308 | event.capturePreambleMs, event.triggerInData, event.captureFormat, event.data); |
| 1309 | } |
| 1310 | |
| 1311 | @Override |
| 1312 | public boolean equals(Object obj) { |
| 1313 | if (this == obj) |
| 1314 | return true; |
| 1315 | if (obj == null) |
| 1316 | return false; |
| 1317 | if (getClass() != obj.getClass()) return false; |
| 1318 | RecognitionEvent other = (RecognitionEvent) obj; |
| 1319 | return super.equals(obj); |
| 1320 | } |
| 1321 | |
| 1322 | @Override |
| 1323 | public String toString() { |
| 1324 | return "GenericRecognitionEvent ::" + super.toString(); |
| 1325 | } |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | /** |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1329 | * Status codes for {@link SoundModelEvent} |
| 1330 | */ |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1331 | /** |
| 1332 | * Sound Model was updated |
| 1333 | * |
| 1334 | * @hide |
| 1335 | */ |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1336 | public static final int SOUNDMODEL_STATUS_UPDATED = 0; |
| 1337 | |
| 1338 | /** |
| 1339 | * A SoundModelEvent is provided by the |
| 1340 | * {@link StatusListener#onSoundModelUpdate(SoundModelEvent)} |
| 1341 | * callback when a sound model has been updated by the implementation |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1342 | * |
| 1343 | * @hide |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1344 | */ |
| 1345 | public static class SoundModelEvent implements Parcelable { |
| 1346 | /** Status e.g {@link #SOUNDMODEL_STATUS_UPDATED} */ |
| 1347 | public final int status; |
| 1348 | /** The updated sound model handle */ |
| 1349 | public final int soundModelHandle; |
| 1350 | /** New sound model data */ |
| 1351 | public final byte[] data; |
| 1352 | |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1353 | @UnsupportedAppUsage |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1354 | SoundModelEvent(int status, int soundModelHandle, byte[] data) { |
| 1355 | this.status = status; |
| 1356 | this.soundModelHandle = soundModelHandle; |
| 1357 | this.data = data; |
| 1358 | } |
| 1359 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 1360 | public static final @android.annotation.NonNull Parcelable.Creator<SoundModelEvent> CREATOR |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1361 | = new Parcelable.Creator<SoundModelEvent>() { |
| 1362 | public SoundModelEvent createFromParcel(Parcel in) { |
| 1363 | return SoundModelEvent.fromParcel(in); |
| 1364 | } |
| 1365 | |
| 1366 | public SoundModelEvent[] newArray(int size) { |
| 1367 | return new SoundModelEvent[size]; |
| 1368 | } |
| 1369 | }; |
| 1370 | |
| 1371 | private static SoundModelEvent fromParcel(Parcel in) { |
| 1372 | int status = in.readInt(); |
| 1373 | int soundModelHandle = in.readInt(); |
| 1374 | byte[] data = in.readBlob(); |
| 1375 | return new SoundModelEvent(status, soundModelHandle, data); |
| 1376 | } |
| 1377 | |
| 1378 | @Override |
| 1379 | public int describeContents() { |
| 1380 | return 0; |
| 1381 | } |
| 1382 | |
| 1383 | @Override |
| 1384 | public void writeToParcel(Parcel dest, int flags) { |
| 1385 | dest.writeInt(status); |
| 1386 | dest.writeInt(soundModelHandle); |
| 1387 | dest.writeBlob(data); |
| 1388 | } |
| 1389 | |
| 1390 | @Override |
| 1391 | public int hashCode() { |
| 1392 | final int prime = 31; |
| 1393 | int result = 1; |
| 1394 | result = prime * result + Arrays.hashCode(data); |
| 1395 | result = prime * result + soundModelHandle; |
| 1396 | result = prime * result + status; |
| 1397 | return result; |
| 1398 | } |
| 1399 | |
| 1400 | @Override |
| 1401 | public boolean equals(Object obj) { |
| 1402 | if (this == obj) |
| 1403 | return true; |
| 1404 | if (obj == null) |
| 1405 | return false; |
| 1406 | if (getClass() != obj.getClass()) |
| 1407 | return false; |
| 1408 | SoundModelEvent other = (SoundModelEvent) obj; |
| 1409 | if (!Arrays.equals(data, other.data)) |
| 1410 | return false; |
| 1411 | if (soundModelHandle != other.soundModelHandle) |
| 1412 | return false; |
| 1413 | if (status != other.status) |
| 1414 | return false; |
| 1415 | return true; |
| 1416 | } |
| 1417 | |
| 1418 | @Override |
| 1419 | public String toString() { |
| 1420 | return "SoundModelEvent [status=" + status + ", soundModelHandle=" + soundModelHandle |
| 1421 | + ", data=" + (data == null ? 0 : data.length) + "]"; |
| 1422 | } |
| 1423 | } |
| 1424 | |
| 1425 | /** |
| 1426 | * Native service state. {@link StatusListener#onServiceStateChange(int)} |
| 1427 | */ |
| 1428 | // Keep in sync with system/core/include/system/sound_trigger.h |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1429 | /** |
| 1430 | * Sound trigger service is enabled |
| 1431 | * |
| 1432 | * @hide |
| 1433 | */ |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1434 | public static final int SERVICE_STATE_ENABLED = 0; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1435 | /** |
| 1436 | * Sound trigger service is disabled |
| 1437 | * |
| 1438 | * @hide |
| 1439 | */ |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1440 | public static final int SERVICE_STATE_DISABLED = 1; |
| 1441 | |
| 1442 | /** |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 1443 | * Returns a list of descriptors for all hardware modules loaded. |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1444 | * @param modules A ModuleProperties array where the list will be returned. |
| 1445 | * @return - {@link #STATUS_OK} in case of success |
| 1446 | * - {@link #STATUS_ERROR} in case of unspecified error |
| 1447 | * - {@link #STATUS_PERMISSION_DENIED} if the caller does not have system permission |
| 1448 | * - {@link #STATUS_NO_INIT} if the native service cannot be reached |
| 1449 | * - {@link #STATUS_BAD_VALUE} if modules is null |
| 1450 | * - {@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] | 1451 | * |
| 1452 | * @hide |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1453 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1454 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1455 | public static native int listModules(ArrayList <ModuleProperties> modules); |
| 1456 | |
| 1457 | /** |
| 1458 | * Get an interface on a hardware module to control sound models and recognition on |
| 1459 | * this module. |
| 1460 | * @param moduleId Sound module system identifier {@link ModuleProperties#id}. mandatory. |
| 1461 | * @param listener {@link StatusListener} interface. Mandatory. |
| 1462 | * @param handler the Handler that will receive the callabcks. Can be null if default handler |
| 1463 | * is OK. |
| 1464 | * @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] | 1465 | * |
| 1466 | * @hide |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1467 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 1468 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1469 | public static SoundTriggerModule attachModule(int moduleId, |
| 1470 | StatusListener listener, |
| 1471 | Handler handler) { |
| 1472 | if (listener == null) { |
| 1473 | return null; |
| 1474 | } |
| 1475 | SoundTriggerModule module = new SoundTriggerModule(moduleId, listener, handler); |
| 1476 | return module; |
| 1477 | } |
| 1478 | |
| 1479 | /** |
| 1480 | * Interface provided by the client application when attaching to a {@link SoundTriggerModule} |
| 1481 | * to received recognition and error notifications. |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1482 | * |
| 1483 | * @hide |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1484 | */ |
| 1485 | public static interface StatusListener { |
| 1486 | /** |
| 1487 | * Called when recognition succeeds of fails |
| 1488 | */ |
| 1489 | public abstract void onRecognition(RecognitionEvent event); |
| 1490 | |
| 1491 | /** |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1492 | * Called when a sound model has been updated |
| 1493 | */ |
| 1494 | public abstract void onSoundModelUpdate(SoundModelEvent event); |
| 1495 | |
| 1496 | /** |
| 1497 | * Called when the sound trigger native service state changes. |
| 1498 | * @param state Native service state. One of {@link SoundTrigger#SERVICE_STATE_ENABLED}, |
| 1499 | * {@link SoundTrigger#SERVICE_STATE_DISABLED} |
| 1500 | */ |
| 1501 | public abstract void onServiceStateChange(int state); |
| 1502 | |
| 1503 | /** |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1504 | * Called when the sound trigger native service dies |
| 1505 | */ |
| 1506 | public abstract void onServiceDied(); |
| 1507 | } |
| 1508 | } |