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 | |
| 143 | public static final Parcelable.Creator<ModuleProperties> CREATOR |
| 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 | |
| 329 | public static final Parcelable.Creator<Keyphrase> CREATOR |
| 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 | |
| 439 | public static final Parcelable.Creator<KeyphraseSoundModel> CREATOR |
| 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 | |
| 519 | public static final Parcelable.Creator<GenericSoundModel> CREATOR |
| 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; |
| 614 | |
| 615 | /** |
| 616 | * A RecognitionEvent is provided by the |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 617 | * {@code StatusListener#onRecognition(RecognitionEvent)} |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 618 | * callback upon recognition success or failure. |
| 619 | */ |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 620 | public static class RecognitionEvent { |
| 621 | /** |
| 622 | * Recognition status e.g RECOGNITION_STATUS_SUCCESS |
| 623 | * |
| 624 | * @hide |
| 625 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame^] | 626 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 627 | public final int status; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 628 | /** |
| 629 | * |
| 630 | * Sound Model corresponding to this event callback |
| 631 | * |
| 632 | * @hide |
| 633 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame^] | 634 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 635 | public final int soundModelHandle; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 636 | /** |
| 637 | * True if it is possible to capture audio from this utterance buffered by the hardware |
| 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 boolean captureAvailable; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 643 | /** |
| 644 | * Audio session ID to be used when capturing the utterance with an AudioRecord |
| 645 | * if captureAvailable() is true. |
| 646 | * |
| 647 | * @hide |
| 648 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame^] | 649 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 650 | public final int captureSession; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 651 | /** |
| 652 | * Delay in ms between end of model detection and start of audio available for capture. |
| 653 | * A negative value is possible (e.g. if keyphrase is also available for capture) |
| 654 | * |
| 655 | * @hide |
| 656 | */ |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 657 | public final int captureDelayMs; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 658 | /** |
| 659 | * Duration in ms of audio captured before the start of the trigger. 0 if none. |
| 660 | * |
| 661 | * @hide |
| 662 | */ |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 663 | public final int capturePreambleMs; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 664 | /** |
| 665 | * True if the trigger (key phrase capture is present in binary data |
| 666 | * |
| 667 | * @hide |
| 668 | */ |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 669 | public final boolean triggerInData; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 670 | /** |
| 671 | * Audio format of either the trigger in event data or to use for capture of the |
| 672 | * rest of the utterance |
| 673 | * |
| 674 | * @hide |
| 675 | */ |
| 676 | public final AudioFormat captureFormat; |
| 677 | /** |
| 678 | * Opaque data for use by system applications who know about voice engine internals, |
| 679 | * typically during enrollment. |
| 680 | * |
| 681 | * @hide |
| 682 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame^] | 683 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 684 | public final byte[] data; |
| 685 | |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 686 | /** @hide */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame^] | 687 | @UnsupportedAppUsage |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 688 | public RecognitionEvent(int status, int soundModelHandle, boolean captureAvailable, |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 689 | int captureSession, int captureDelayMs, int capturePreambleMs, |
| 690 | boolean triggerInData, AudioFormat captureFormat, byte[] data) { |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 691 | this.status = status; |
| 692 | this.soundModelHandle = soundModelHandle; |
| 693 | this.captureAvailable = captureAvailable; |
| 694 | this.captureSession = captureSession; |
| 695 | this.captureDelayMs = captureDelayMs; |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 696 | this.capturePreambleMs = capturePreambleMs; |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 697 | this.triggerInData = triggerInData; |
| 698 | this.captureFormat = captureFormat; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 699 | this.data = data; |
| 700 | } |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 701 | |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 702 | /** |
| 703 | * Check if is possible to capture audio from this utterance buffered by the hardware. |
| 704 | * |
| 705 | * @return {@code true} iff a capturing is possible |
| 706 | */ |
| 707 | public boolean isCaptureAvailable() { |
| 708 | return captureAvailable; |
| 709 | } |
| 710 | |
| 711 | /** |
| 712 | * Get the audio format of either the trigger in event data or to use for capture of the |
| 713 | * rest of the utterance |
| 714 | * |
| 715 | * @return the audio format |
| 716 | */ |
| 717 | @Nullable public AudioFormat getCaptureFormat() { |
| 718 | return captureFormat; |
| 719 | } |
| 720 | |
| 721 | /** |
| 722 | * Get Audio session ID to be used when capturing the utterance with an {@link AudioRecord} |
| 723 | * if {@link #isCaptureAvailable()} is true. |
| 724 | * |
| 725 | * @return The id of the capture session |
| 726 | */ |
| 727 | public int getCaptureSession() { |
| 728 | return captureSession; |
| 729 | } |
| 730 | |
| 731 | /** |
| 732 | * Get the opaque data for use by system applications who know about voice engine |
| 733 | * internals, typically during enrollment. |
| 734 | * |
| 735 | * @return The data of the event |
| 736 | */ |
| 737 | public byte[] getData() { |
| 738 | return data; |
| 739 | } |
| 740 | |
| 741 | /** @hide */ |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 742 | public static final Parcelable.Creator<RecognitionEvent> CREATOR |
| 743 | = new Parcelable.Creator<RecognitionEvent>() { |
| 744 | public RecognitionEvent createFromParcel(Parcel in) { |
| 745 | return RecognitionEvent.fromParcel(in); |
| 746 | } |
| 747 | |
| 748 | public RecognitionEvent[] newArray(int size) { |
| 749 | return new RecognitionEvent[size]; |
| 750 | } |
| 751 | }; |
| 752 | |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 753 | /** @hide */ |
Arunesh Mishra | f47f173 | 2016-02-18 16:16:12 -0800 | [diff] [blame] | 754 | protected static RecognitionEvent fromParcel(Parcel in) { |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 755 | int status = in.readInt(); |
| 756 | int soundModelHandle = in.readInt(); |
| 757 | boolean captureAvailable = in.readByte() == 1; |
| 758 | int captureSession = in.readInt(); |
| 759 | int captureDelayMs = in.readInt(); |
| 760 | int capturePreambleMs = in.readInt(); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 761 | boolean triggerInData = in.readByte() == 1; |
| 762 | AudioFormat captureFormat = null; |
Eric Laurent | 39fcca0 | 2014-09-05 16:44:19 -0700 | [diff] [blame] | 763 | if (in.readByte() == 1) { |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 764 | int sampleRate = in.readInt(); |
| 765 | int encoding = in.readInt(); |
| 766 | int channelMask = in.readInt(); |
| 767 | captureFormat = (new AudioFormat.Builder()) |
| 768 | .setChannelMask(channelMask) |
| 769 | .setEncoding(encoding) |
| 770 | .setSampleRate(sampleRate) |
| 771 | .build(); |
| 772 | } |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 773 | byte[] data = in.readBlob(); |
| 774 | return new RecognitionEvent(status, soundModelHandle, captureAvailable, captureSession, |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 775 | captureDelayMs, capturePreambleMs, triggerInData, captureFormat, data); |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 776 | } |
| 777 | |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 778 | /** @hide */ |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 779 | public int describeContents() { |
| 780 | return 0; |
| 781 | } |
| 782 | |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 783 | /** @hide */ |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 784 | public void writeToParcel(Parcel dest, int flags) { |
| 785 | dest.writeInt(status); |
| 786 | dest.writeInt(soundModelHandle); |
| 787 | dest.writeByte((byte) (captureAvailable ? 1 : 0)); |
| 788 | dest.writeInt(captureSession); |
| 789 | dest.writeInt(captureDelayMs); |
| 790 | dest.writeInt(capturePreambleMs); |
Eric Laurent | 39fcca0 | 2014-09-05 16:44:19 -0700 | [diff] [blame] | 791 | dest.writeByte((byte) (triggerInData ? 1 : 0)); |
| 792 | if (captureFormat != null) { |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 793 | dest.writeByte((byte)1); |
| 794 | dest.writeInt(captureFormat.getSampleRate()); |
| 795 | dest.writeInt(captureFormat.getEncoding()); |
| 796 | dest.writeInt(captureFormat.getChannelMask()); |
| 797 | } else { |
| 798 | dest.writeByte((byte)0); |
| 799 | } |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 800 | dest.writeBlob(data); |
| 801 | } |
| 802 | |
| 803 | @Override |
| 804 | public int hashCode() { |
| 805 | final int prime = 31; |
| 806 | int result = 1; |
| 807 | result = prime * result + (captureAvailable ? 1231 : 1237); |
| 808 | result = prime * result + captureDelayMs; |
| 809 | result = prime * result + capturePreambleMs; |
| 810 | result = prime * result + captureSession; |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 811 | result = prime * result + (triggerInData ? 1231 : 1237); |
| 812 | if (captureFormat != null) { |
| 813 | result = prime * result + captureFormat.getSampleRate(); |
| 814 | result = prime * result + captureFormat.getEncoding(); |
| 815 | result = prime * result + captureFormat.getChannelMask(); |
| 816 | } |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 817 | result = prime * result + Arrays.hashCode(data); |
| 818 | result = prime * result + soundModelHandle; |
| 819 | result = prime * result + status; |
| 820 | return result; |
| 821 | } |
| 822 | |
| 823 | @Override |
| 824 | public boolean equals(Object obj) { |
| 825 | if (this == obj) |
| 826 | return true; |
| 827 | if (obj == null) |
| 828 | return false; |
| 829 | if (getClass() != obj.getClass()) |
| 830 | return false; |
| 831 | RecognitionEvent other = (RecognitionEvent) obj; |
| 832 | if (captureAvailable != other.captureAvailable) |
| 833 | return false; |
| 834 | if (captureDelayMs != other.captureDelayMs) |
| 835 | return false; |
| 836 | if (capturePreambleMs != other.capturePreambleMs) |
| 837 | return false; |
| 838 | if (captureSession != other.captureSession) |
| 839 | return false; |
| 840 | if (!Arrays.equals(data, other.data)) |
| 841 | return false; |
| 842 | if (soundModelHandle != other.soundModelHandle) |
| 843 | return false; |
| 844 | if (status != other.status) |
| 845 | return false; |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 846 | if (triggerInData != other.triggerInData) |
| 847 | return false; |
Ryan Bavetta | ea04e8f | 2016-03-02 18:34:50 -0800 | [diff] [blame] | 848 | if (captureFormat == null) { |
| 849 | if (other.captureFormat != null) |
| 850 | return false; |
| 851 | } else { |
| 852 | if (other.captureFormat == null) |
| 853 | return false; |
| 854 | if (captureFormat.getSampleRate() != other.captureFormat.getSampleRate()) |
| 855 | return false; |
| 856 | if (captureFormat.getEncoding() != other.captureFormat.getEncoding()) |
| 857 | return false; |
| 858 | if (captureFormat.getChannelMask() != other.captureFormat.getChannelMask()) |
| 859 | return false; |
| 860 | } |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 861 | return true; |
| 862 | } |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 863 | |
| 864 | @Override |
| 865 | public String toString() { |
| 866 | return "RecognitionEvent [status=" + status + ", soundModelHandle=" + soundModelHandle |
| 867 | + ", captureAvailable=" + captureAvailable + ", captureSession=" |
| 868 | + captureSession + ", captureDelayMs=" + captureDelayMs |
| 869 | + ", capturePreambleMs=" + capturePreambleMs |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 870 | + ", triggerInData=" + triggerInData |
| 871 | + ((captureFormat == null) ? "" : |
| 872 | (", sampleRate=" + captureFormat.getSampleRate())) |
| 873 | + ((captureFormat == null) ? "" : |
| 874 | (", encoding=" + captureFormat.getEncoding())) |
| 875 | + ((captureFormat == null) ? "" : |
| 876 | (", channelMask=" + captureFormat.getChannelMask())) |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 877 | + ", data=" + (data == null ? 0 : data.length) + "]"; |
| 878 | } |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | /** |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 882 | * A RecognitionConfig is provided to |
| 883 | * {@link SoundTriggerModule#startRecognition(int, RecognitionConfig)} to configure the |
| 884 | * recognition request. |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 885 | * |
| 886 | * @hide |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 887 | */ |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 888 | public static class RecognitionConfig implements Parcelable { |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 889 | /** True if the DSP should capture the trigger sound and make it available for further |
| 890 | * capture. */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame^] | 891 | @UnsupportedAppUsage |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 892 | public final boolean captureRequested; |
Sandeep Siddhartha | 2c0273e | 2014-08-01 11:32:03 -0700 | [diff] [blame] | 893 | /** |
| 894 | * True if the service should restart listening after the DSP triggers. |
| 895 | * Note: This config flag is currently used at the service layer rather than by the DSP. |
| 896 | */ |
| 897 | public final boolean allowMultipleTriggers; |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 898 | /** List of all keyphrases in the sound model for which recognition should be performed with |
| 899 | * options for each keyphrase. */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame^] | 900 | @UnsupportedAppUsage |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 901 | public final KeyphraseRecognitionExtra keyphrases[]; |
| 902 | /** Opaque data for use by system applications who know about voice engine internals, |
| 903 | * typically during enrollment. */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame^] | 904 | @UnsupportedAppUsage |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 905 | public final byte[] data; |
| 906 | |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame^] | 907 | @UnsupportedAppUsage |
Sandeep Siddhartha | 2c0273e | 2014-08-01 11:32:03 -0700 | [diff] [blame] | 908 | public RecognitionConfig(boolean captureRequested, boolean allowMultipleTriggers, |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 909 | KeyphraseRecognitionExtra[] keyphrases, byte[] data) { |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 910 | this.captureRequested = captureRequested; |
Sandeep Siddhartha | 2c0273e | 2014-08-01 11:32:03 -0700 | [diff] [blame] | 911 | this.allowMultipleTriggers = allowMultipleTriggers; |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 912 | this.keyphrases = keyphrases; |
| 913 | this.data = data; |
| 914 | } |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 915 | |
| 916 | public static final Parcelable.Creator<RecognitionConfig> CREATOR |
| 917 | = new Parcelable.Creator<RecognitionConfig>() { |
| 918 | public RecognitionConfig createFromParcel(Parcel in) { |
| 919 | return RecognitionConfig.fromParcel(in); |
| 920 | } |
| 921 | |
| 922 | public RecognitionConfig[] newArray(int size) { |
| 923 | return new RecognitionConfig[size]; |
| 924 | } |
| 925 | }; |
| 926 | |
| 927 | private static RecognitionConfig fromParcel(Parcel in) { |
| 928 | boolean captureRequested = in.readByte() == 1; |
Sandeep Siddhartha | 2c0273e | 2014-08-01 11:32:03 -0700 | [diff] [blame] | 929 | boolean allowMultipleTriggers = in.readByte() == 1; |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 930 | KeyphraseRecognitionExtra[] keyphrases = |
| 931 | in.createTypedArray(KeyphraseRecognitionExtra.CREATOR); |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 932 | byte[] data = in.readBlob(); |
Sandeep Siddhartha | 2c0273e | 2014-08-01 11:32:03 -0700 | [diff] [blame] | 933 | return new RecognitionConfig(captureRequested, allowMultipleTriggers, keyphrases, data); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | @Override |
| 937 | public void writeToParcel(Parcel dest, int flags) { |
| 938 | dest.writeByte((byte) (captureRequested ? 1 : 0)); |
Sandeep Siddhartha | 2c0273e | 2014-08-01 11:32:03 -0700 | [diff] [blame] | 939 | dest.writeByte((byte) (allowMultipleTriggers ? 1 : 0)); |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 940 | dest.writeTypedArray(keyphrases, flags); |
Sandeep Siddhartha | 39c12fa | 2014-07-25 18:37:29 -0700 | [diff] [blame] | 941 | dest.writeBlob(data); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | @Override |
| 945 | public int describeContents() { |
| 946 | return 0; |
| 947 | } |
Sandeep Siddhartha | 110f569 | 2014-07-20 12:22:56 -0700 | [diff] [blame] | 948 | |
| 949 | @Override |
| 950 | public String toString() { |
Sandeep Siddhartha | 2c0273e | 2014-08-01 11:32:03 -0700 | [diff] [blame] | 951 | return "RecognitionConfig [captureRequested=" + captureRequested |
| 952 | + ", allowMultipleTriggers=" + allowMultipleTriggers + ", keyphrases=" |
| 953 | + Arrays.toString(keyphrases) + ", data=" + Arrays.toString(data) + "]"; |
Sandeep Siddhartha | 110f569 | 2014-07-20 12:22:56 -0700 | [diff] [blame] | 954 | } |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | /** |
| 958 | * Confidence level for users defined in a keyphrase. |
| 959 | * - The confidence level is expressed in percent (0% -100%). |
| 960 | * When used in a {@link KeyphraseRecognitionEvent} it indicates the detected confidence level |
| 961 | * When used in a {@link RecognitionConfig} it indicates the minimum confidence level that |
| 962 | * should trigger a recognition. |
| 963 | * - 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] | 964 | * |
| 965 | * @hide |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 966 | */ |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 967 | public static class ConfidenceLevel implements Parcelable { |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame^] | 968 | @UnsupportedAppUsage |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 969 | public final int userId; |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame^] | 970 | @UnsupportedAppUsage |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 971 | public final int confidenceLevel; |
| 972 | |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame^] | 973 | @UnsupportedAppUsage |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 974 | public ConfidenceLevel(int userId, int confidenceLevel) { |
| 975 | this.userId = userId; |
| 976 | this.confidenceLevel = confidenceLevel; |
| 977 | } |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 978 | |
| 979 | public static final Parcelable.Creator<ConfidenceLevel> CREATOR |
| 980 | = new Parcelable.Creator<ConfidenceLevel>() { |
| 981 | public ConfidenceLevel createFromParcel(Parcel in) { |
| 982 | return ConfidenceLevel.fromParcel(in); |
| 983 | } |
| 984 | |
| 985 | public ConfidenceLevel[] newArray(int size) { |
| 986 | return new ConfidenceLevel[size]; |
| 987 | } |
| 988 | }; |
| 989 | |
| 990 | private static ConfidenceLevel fromParcel(Parcel in) { |
| 991 | int userId = in.readInt(); |
| 992 | int confidenceLevel = in.readInt(); |
| 993 | return new ConfidenceLevel(userId, confidenceLevel); |
| 994 | } |
| 995 | |
| 996 | @Override |
| 997 | public void writeToParcel(Parcel dest, int flags) { |
| 998 | dest.writeInt(userId); |
| 999 | dest.writeInt(confidenceLevel); |
| 1000 | } |
| 1001 | |
| 1002 | @Override |
| 1003 | public int describeContents() { |
| 1004 | return 0; |
| 1005 | } |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1006 | |
| 1007 | @Override |
| 1008 | public int hashCode() { |
| 1009 | final int prime = 31; |
| 1010 | int result = 1; |
| 1011 | result = prime * result + confidenceLevel; |
| 1012 | result = prime * result + userId; |
| 1013 | return result; |
| 1014 | } |
| 1015 | |
| 1016 | @Override |
| 1017 | public boolean equals(Object obj) { |
| 1018 | if (this == obj) |
| 1019 | return true; |
| 1020 | if (obj == null) |
| 1021 | return false; |
| 1022 | if (getClass() != obj.getClass()) |
| 1023 | return false; |
| 1024 | ConfidenceLevel other = (ConfidenceLevel) obj; |
| 1025 | if (confidenceLevel != other.confidenceLevel) |
| 1026 | return false; |
| 1027 | if (userId != other.userId) |
| 1028 | return false; |
| 1029 | return true; |
| 1030 | } |
| 1031 | |
| 1032 | @Override |
| 1033 | public String toString() { |
| 1034 | return "ConfidenceLevel [userId=" + userId |
| 1035 | + ", confidenceLevel=" + confidenceLevel + "]"; |
| 1036 | } |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | /** |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 1040 | * Additional data conveyed by a {@link KeyphraseRecognitionEvent} |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1041 | * for a key phrase detection. |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1042 | * |
| 1043 | * @hide |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1044 | */ |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1045 | public static class KeyphraseRecognitionExtra implements Parcelable { |
| 1046 | /** The keyphrase ID */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame^] | 1047 | @UnsupportedAppUsage |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1048 | public final int id; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1049 | |
| 1050 | /** Recognition modes matched for this event */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame^] | 1051 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1052 | public final int recognitionModes; |
| 1053 | |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1054 | /** Confidence level for mode RECOGNITION_MODE_VOICE_TRIGGER when user identification |
| 1055 | * is not performed */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame^] | 1056 | @UnsupportedAppUsage |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1057 | public final int coarseConfidenceLevel; |
| 1058 | |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1059 | /** Confidence levels for all users recognized (KeyphraseRecognitionEvent) or to |
| 1060 | * be recognized (RecognitionConfig) */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame^] | 1061 | @UnsupportedAppUsage |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1062 | public final ConfidenceLevel[] confidenceLevels; |
| 1063 | |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame^] | 1064 | @UnsupportedAppUsage |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1065 | public KeyphraseRecognitionExtra(int id, int recognitionModes, int coarseConfidenceLevel, |
| 1066 | ConfidenceLevel[] confidenceLevels) { |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1067 | this.id = id; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1068 | this.recognitionModes = recognitionModes; |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1069 | this.coarseConfidenceLevel = coarseConfidenceLevel; |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1070 | this.confidenceLevels = confidenceLevels; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1071 | } |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1072 | |
| 1073 | public static final Parcelable.Creator<KeyphraseRecognitionExtra> CREATOR |
| 1074 | = new Parcelable.Creator<KeyphraseRecognitionExtra>() { |
| 1075 | public KeyphraseRecognitionExtra createFromParcel(Parcel in) { |
| 1076 | return KeyphraseRecognitionExtra.fromParcel(in); |
| 1077 | } |
| 1078 | |
| 1079 | public KeyphraseRecognitionExtra[] newArray(int size) { |
| 1080 | return new KeyphraseRecognitionExtra[size]; |
| 1081 | } |
| 1082 | }; |
| 1083 | |
| 1084 | private static KeyphraseRecognitionExtra fromParcel(Parcel in) { |
| 1085 | int id = in.readInt(); |
| 1086 | int recognitionModes = in.readInt(); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1087 | int coarseConfidenceLevel = in.readInt(); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1088 | ConfidenceLevel[] confidenceLevels = in.createTypedArray(ConfidenceLevel.CREATOR); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1089 | return new KeyphraseRecognitionExtra(id, recognitionModes, coarseConfidenceLevel, |
| 1090 | confidenceLevels); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | @Override |
| 1094 | public void writeToParcel(Parcel dest, int flags) { |
| 1095 | dest.writeInt(id); |
| 1096 | dest.writeInt(recognitionModes); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1097 | dest.writeInt(coarseConfidenceLevel); |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1098 | dest.writeTypedArray(confidenceLevels, flags); |
Sandeep Siddhartha | 0558972 | 2014-07-17 16:21:54 -0700 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | @Override |
| 1102 | public int describeContents() { |
| 1103 | return 0; |
| 1104 | } |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1105 | |
| 1106 | @Override |
| 1107 | public int hashCode() { |
| 1108 | final int prime = 31; |
| 1109 | int result = 1; |
| 1110 | result = prime * result + Arrays.hashCode(confidenceLevels); |
| 1111 | result = prime * result + id; |
| 1112 | result = prime * result + recognitionModes; |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1113 | result = prime * result + coarseConfidenceLevel; |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1114 | return result; |
| 1115 | } |
| 1116 | |
| 1117 | @Override |
| 1118 | public boolean equals(Object obj) { |
| 1119 | if (this == obj) |
| 1120 | return true; |
| 1121 | if (obj == null) |
| 1122 | return false; |
| 1123 | if (getClass() != obj.getClass()) |
| 1124 | return false; |
| 1125 | KeyphraseRecognitionExtra other = (KeyphraseRecognitionExtra) obj; |
| 1126 | if (!Arrays.equals(confidenceLevels, other.confidenceLevels)) |
| 1127 | return false; |
| 1128 | if (id != other.id) |
| 1129 | return false; |
| 1130 | if (recognitionModes != other.recognitionModes) |
| 1131 | return false; |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1132 | if (coarseConfidenceLevel != other.coarseConfidenceLevel) |
| 1133 | return false; |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1134 | return true; |
| 1135 | } |
| 1136 | |
| 1137 | @Override |
| 1138 | public String toString() { |
| 1139 | return "KeyphraseRecognitionExtra [id=" + id + ", recognitionModes=" + recognitionModes |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1140 | + ", coarseConfidenceLevel=" + coarseConfidenceLevel |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1141 | + ", confidenceLevels=" + Arrays.toString(confidenceLevels) + "]"; |
| 1142 | } |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | /** |
| 1146 | * Specialized {@link RecognitionEvent} for a key phrase detection. |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1147 | * |
| 1148 | * @hide |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1149 | */ |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1150 | public static class KeyphraseRecognitionEvent extends RecognitionEvent implements Parcelable { |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1151 | /** 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^] | 1152 | @UnsupportedAppUsage |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 1153 | public final KeyphraseRecognitionExtra[] keyphraseExtras; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1154 | |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame^] | 1155 | @UnsupportedAppUsage |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1156 | public KeyphraseRecognitionEvent(int status, int soundModelHandle, boolean captureAvailable, |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1157 | int captureSession, int captureDelayMs, int capturePreambleMs, |
| 1158 | boolean triggerInData, AudioFormat captureFormat, byte[] data, |
| 1159 | KeyphraseRecognitionExtra[] keyphraseExtras) { |
Eric Laurent | 013f66b | 2014-07-06 16:35:00 -0700 | [diff] [blame] | 1160 | super(status, soundModelHandle, captureAvailable, captureSession, captureDelayMs, |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1161 | capturePreambleMs, triggerInData, captureFormat, data); |
Sandeep Siddhartha | d4233c6 | 2014-06-12 18:31:19 -0700 | [diff] [blame] | 1162 | this.keyphraseExtras = keyphraseExtras; |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1163 | } |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1164 | |
| 1165 | public static final Parcelable.Creator<KeyphraseRecognitionEvent> CREATOR |
| 1166 | = new Parcelable.Creator<KeyphraseRecognitionEvent>() { |
| 1167 | public KeyphraseRecognitionEvent createFromParcel(Parcel in) { |
Arunesh Mishra | f47f173 | 2016-02-18 16:16:12 -0800 | [diff] [blame] | 1168 | return KeyphraseRecognitionEvent.fromParcelForKeyphrase(in); |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1169 | } |
| 1170 | |
| 1171 | public KeyphraseRecognitionEvent[] newArray(int size) { |
| 1172 | return new KeyphraseRecognitionEvent[size]; |
| 1173 | } |
| 1174 | }; |
| 1175 | |
Arunesh Mishra | f47f173 | 2016-02-18 16:16:12 -0800 | [diff] [blame] | 1176 | private static KeyphraseRecognitionEvent fromParcelForKeyphrase(Parcel in) { |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1177 | int status = in.readInt(); |
| 1178 | int soundModelHandle = in.readInt(); |
| 1179 | boolean captureAvailable = in.readByte() == 1; |
| 1180 | int captureSession = in.readInt(); |
| 1181 | int captureDelayMs = in.readInt(); |
| 1182 | int capturePreambleMs = in.readInt(); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1183 | boolean triggerInData = in.readByte() == 1; |
| 1184 | AudioFormat captureFormat = null; |
Eric Laurent | 75b433f | 2014-09-12 15:45:47 -0700 | [diff] [blame] | 1185 | if (in.readByte() == 1) { |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1186 | int sampleRate = in.readInt(); |
| 1187 | int encoding = in.readInt(); |
| 1188 | int channelMask = in.readInt(); |
| 1189 | captureFormat = (new AudioFormat.Builder()) |
Ryan Bavetta | ea04e8f | 2016-03-02 18:34:50 -0800 | [diff] [blame] | 1190 | .setChannelMask(channelMask) |
| 1191 | .setEncoding(encoding) |
| 1192 | .setSampleRate(sampleRate) |
| 1193 | .build(); |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1194 | } |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1195 | byte[] data = in.readBlob(); |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1196 | KeyphraseRecognitionExtra[] keyphraseExtras = |
| 1197 | in.createTypedArray(KeyphraseRecognitionExtra.CREATOR); |
| 1198 | return new KeyphraseRecognitionEvent(status, soundModelHandle, captureAvailable, |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1199 | captureSession, captureDelayMs, capturePreambleMs, triggerInData, |
| 1200 | captureFormat, data, keyphraseExtras); |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | @Override |
| 1204 | public void writeToParcel(Parcel dest, int flags) { |
| 1205 | dest.writeInt(status); |
| 1206 | dest.writeInt(soundModelHandle); |
| 1207 | dest.writeByte((byte) (captureAvailable ? 1 : 0)); |
| 1208 | dest.writeInt(captureSession); |
| 1209 | dest.writeInt(captureDelayMs); |
| 1210 | dest.writeInt(capturePreambleMs); |
Eric Laurent | 75b433f | 2014-09-12 15:45:47 -0700 | [diff] [blame] | 1211 | dest.writeByte((byte) (triggerInData ? 1 : 0)); |
| 1212 | if (captureFormat != null) { |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1213 | dest.writeByte((byte)1); |
| 1214 | dest.writeInt(captureFormat.getSampleRate()); |
| 1215 | dest.writeInt(captureFormat.getEncoding()); |
| 1216 | dest.writeInt(captureFormat.getChannelMask()); |
| 1217 | } else { |
| 1218 | dest.writeByte((byte)0); |
| 1219 | } |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1220 | dest.writeBlob(data); |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1221 | dest.writeTypedArray(keyphraseExtras, flags); |
| 1222 | } |
| 1223 | |
| 1224 | @Override |
| 1225 | public int describeContents() { |
| 1226 | return 0; |
| 1227 | } |
| 1228 | |
| 1229 | @Override |
| 1230 | public int hashCode() { |
| 1231 | final int prime = 31; |
| 1232 | int result = super.hashCode(); |
| 1233 | result = prime * result + Arrays.hashCode(keyphraseExtras); |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1234 | return result; |
| 1235 | } |
| 1236 | |
| 1237 | @Override |
| 1238 | public boolean equals(Object obj) { |
| 1239 | if (this == obj) |
| 1240 | return true; |
| 1241 | if (!super.equals(obj)) |
| 1242 | return false; |
| 1243 | if (getClass() != obj.getClass()) |
| 1244 | return false; |
| 1245 | KeyphraseRecognitionEvent other = (KeyphraseRecognitionEvent) obj; |
| 1246 | if (!Arrays.equals(keyphraseExtras, other.keyphraseExtras)) |
| 1247 | return false; |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1248 | return true; |
| 1249 | } |
| 1250 | |
| 1251 | @Override |
| 1252 | public String toString() { |
| 1253 | return "KeyphraseRecognitionEvent [keyphraseExtras=" + Arrays.toString(keyphraseExtras) |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1254 | + ", status=" + status |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1255 | + ", soundModelHandle=" + soundModelHandle + ", captureAvailable=" |
| 1256 | + captureAvailable + ", captureSession=" + captureSession + ", captureDelayMs=" |
| 1257 | + captureDelayMs + ", capturePreambleMs=" + capturePreambleMs |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1258 | + ", triggerInData=" + triggerInData |
| 1259 | + ((captureFormat == null) ? "" : |
| 1260 | (", sampleRate=" + captureFormat.getSampleRate())) |
| 1261 | + ((captureFormat == null) ? "" : |
| 1262 | (", encoding=" + captureFormat.getEncoding())) |
| 1263 | + ((captureFormat == null) ? "" : |
| 1264 | (", channelMask=" + captureFormat.getChannelMask())) |
Sandeep Siddhartha | 6817337 | 2014-07-28 13:25:30 -0700 | [diff] [blame] | 1265 | + ", data=" + (data == null ? 0 : data.length) + "]"; |
| 1266 | } |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | /** |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 1270 | * Sub-class of RecognitionEvent specifically for sound-trigger based sound |
| 1271 | * models(non-keyphrase). Currently does not contain any additional fields. |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1272 | * |
| 1273 | * @hide |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 1274 | */ |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1275 | public static class GenericRecognitionEvent extends RecognitionEvent implements Parcelable { |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame^] | 1276 | @UnsupportedAppUsage |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 1277 | public GenericRecognitionEvent(int status, int soundModelHandle, |
| 1278 | boolean captureAvailable, int captureSession, int captureDelayMs, |
| 1279 | int capturePreambleMs, boolean triggerInData, AudioFormat captureFormat, |
| 1280 | byte[] data) { |
| 1281 | super(status, soundModelHandle, captureAvailable, captureSession, |
| 1282 | captureDelayMs, capturePreambleMs, triggerInData, captureFormat, |
| 1283 | data); |
| 1284 | } |
Arunesh Mishra | f47f173 | 2016-02-18 16:16:12 -0800 | [diff] [blame] | 1285 | |
| 1286 | public static final Parcelable.Creator<GenericRecognitionEvent> CREATOR |
| 1287 | = new Parcelable.Creator<GenericRecognitionEvent>() { |
| 1288 | public GenericRecognitionEvent createFromParcel(Parcel in) { |
| 1289 | return GenericRecognitionEvent.fromParcelForGeneric(in); |
| 1290 | } |
| 1291 | |
| 1292 | public GenericRecognitionEvent[] newArray(int size) { |
| 1293 | return new GenericRecognitionEvent[size]; |
| 1294 | } |
| 1295 | }; |
| 1296 | |
| 1297 | private static GenericRecognitionEvent fromParcelForGeneric(Parcel in) { |
| 1298 | RecognitionEvent event = RecognitionEvent.fromParcel(in); |
| 1299 | return new GenericRecognitionEvent(event.status, event.soundModelHandle, |
| 1300 | event.captureAvailable, event.captureSession, event.captureDelayMs, |
| 1301 | event.capturePreambleMs, event.triggerInData, event.captureFormat, event.data); |
| 1302 | } |
| 1303 | |
| 1304 | @Override |
| 1305 | public boolean equals(Object obj) { |
| 1306 | if (this == obj) |
| 1307 | return true; |
| 1308 | if (obj == null) |
| 1309 | return false; |
| 1310 | if (getClass() != obj.getClass()) return false; |
| 1311 | RecognitionEvent other = (RecognitionEvent) obj; |
| 1312 | return super.equals(obj); |
| 1313 | } |
| 1314 | |
| 1315 | @Override |
| 1316 | public String toString() { |
| 1317 | return "GenericRecognitionEvent ::" + super.toString(); |
| 1318 | } |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | /** |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1322 | * Status codes for {@link SoundModelEvent} |
| 1323 | */ |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1324 | /** |
| 1325 | * Sound Model was updated |
| 1326 | * |
| 1327 | * @hide |
| 1328 | */ |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1329 | public static final int SOUNDMODEL_STATUS_UPDATED = 0; |
| 1330 | |
| 1331 | /** |
| 1332 | * A SoundModelEvent is provided by the |
| 1333 | * {@link StatusListener#onSoundModelUpdate(SoundModelEvent)} |
| 1334 | * callback when a sound model has been updated by the implementation |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1335 | * |
| 1336 | * @hide |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1337 | */ |
| 1338 | public static class SoundModelEvent implements Parcelable { |
| 1339 | /** Status e.g {@link #SOUNDMODEL_STATUS_UPDATED} */ |
| 1340 | public final int status; |
| 1341 | /** The updated sound model handle */ |
| 1342 | public final int soundModelHandle; |
| 1343 | /** New sound model data */ |
| 1344 | public final byte[] data; |
| 1345 | |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame^] | 1346 | @UnsupportedAppUsage |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1347 | SoundModelEvent(int status, int soundModelHandle, byte[] data) { |
| 1348 | this.status = status; |
| 1349 | this.soundModelHandle = soundModelHandle; |
| 1350 | this.data = data; |
| 1351 | } |
| 1352 | |
| 1353 | public static final Parcelable.Creator<SoundModelEvent> CREATOR |
| 1354 | = new Parcelable.Creator<SoundModelEvent>() { |
| 1355 | public SoundModelEvent createFromParcel(Parcel in) { |
| 1356 | return SoundModelEvent.fromParcel(in); |
| 1357 | } |
| 1358 | |
| 1359 | public SoundModelEvent[] newArray(int size) { |
| 1360 | return new SoundModelEvent[size]; |
| 1361 | } |
| 1362 | }; |
| 1363 | |
| 1364 | private static SoundModelEvent fromParcel(Parcel in) { |
| 1365 | int status = in.readInt(); |
| 1366 | int soundModelHandle = in.readInt(); |
| 1367 | byte[] data = in.readBlob(); |
| 1368 | return new SoundModelEvent(status, soundModelHandle, data); |
| 1369 | } |
| 1370 | |
| 1371 | @Override |
| 1372 | public int describeContents() { |
| 1373 | return 0; |
| 1374 | } |
| 1375 | |
| 1376 | @Override |
| 1377 | public void writeToParcel(Parcel dest, int flags) { |
| 1378 | dest.writeInt(status); |
| 1379 | dest.writeInt(soundModelHandle); |
| 1380 | dest.writeBlob(data); |
| 1381 | } |
| 1382 | |
| 1383 | @Override |
| 1384 | public int hashCode() { |
| 1385 | final int prime = 31; |
| 1386 | int result = 1; |
| 1387 | result = prime * result + Arrays.hashCode(data); |
| 1388 | result = prime * result + soundModelHandle; |
| 1389 | result = prime * result + status; |
| 1390 | return result; |
| 1391 | } |
| 1392 | |
| 1393 | @Override |
| 1394 | public boolean equals(Object obj) { |
| 1395 | if (this == obj) |
| 1396 | return true; |
| 1397 | if (obj == null) |
| 1398 | return false; |
| 1399 | if (getClass() != obj.getClass()) |
| 1400 | return false; |
| 1401 | SoundModelEvent other = (SoundModelEvent) obj; |
| 1402 | if (!Arrays.equals(data, other.data)) |
| 1403 | return false; |
| 1404 | if (soundModelHandle != other.soundModelHandle) |
| 1405 | return false; |
| 1406 | if (status != other.status) |
| 1407 | return false; |
| 1408 | return true; |
| 1409 | } |
| 1410 | |
| 1411 | @Override |
| 1412 | public String toString() { |
| 1413 | return "SoundModelEvent [status=" + status + ", soundModelHandle=" + soundModelHandle |
| 1414 | + ", data=" + (data == null ? 0 : data.length) + "]"; |
| 1415 | } |
| 1416 | } |
| 1417 | |
| 1418 | /** |
| 1419 | * Native service state. {@link StatusListener#onServiceStateChange(int)} |
| 1420 | */ |
| 1421 | // Keep in sync with system/core/include/system/sound_trigger.h |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1422 | /** |
| 1423 | * Sound trigger service is enabled |
| 1424 | * |
| 1425 | * @hide |
| 1426 | */ |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1427 | public static final int SERVICE_STATE_ENABLED = 0; |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1428 | /** |
| 1429 | * Sound trigger service is disabled |
| 1430 | * |
| 1431 | * @hide |
| 1432 | */ |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1433 | public static final int SERVICE_STATE_DISABLED = 1; |
| 1434 | |
| 1435 | /** |
Arunesh Mishra | a772e5f | 2016-01-25 10:33:11 -0800 | [diff] [blame] | 1436 | * Returns a list of descriptors for all hardware modules loaded. |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1437 | * @param modules A ModuleProperties array where the list will be returned. |
| 1438 | * @return - {@link #STATUS_OK} in case of success |
| 1439 | * - {@link #STATUS_ERROR} in case of unspecified error |
| 1440 | * - {@link #STATUS_PERMISSION_DENIED} if the caller does not have system permission |
| 1441 | * - {@link #STATUS_NO_INIT} if the native service cannot be reached |
| 1442 | * - {@link #STATUS_BAD_VALUE} if modules is null |
| 1443 | * - {@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] | 1444 | * |
| 1445 | * @hide |
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 |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1448 | public static native int listModules(ArrayList <ModuleProperties> modules); |
| 1449 | |
| 1450 | /** |
| 1451 | * Get an interface on a hardware module to control sound models and recognition on |
| 1452 | * this module. |
| 1453 | * @param moduleId Sound module system identifier {@link ModuleProperties#id}. mandatory. |
| 1454 | * @param listener {@link StatusListener} interface. Mandatory. |
| 1455 | * @param handler the Handler that will receive the callabcks. Can be null if default handler |
| 1456 | * is OK. |
| 1457 | * @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] | 1458 | * |
| 1459 | * @hide |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1460 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame^] | 1461 | @UnsupportedAppUsage |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1462 | public static SoundTriggerModule attachModule(int moduleId, |
| 1463 | StatusListener listener, |
| 1464 | Handler handler) { |
| 1465 | if (listener == null) { |
| 1466 | return null; |
| 1467 | } |
| 1468 | SoundTriggerModule module = new SoundTriggerModule(moduleId, listener, handler); |
| 1469 | return module; |
| 1470 | } |
| 1471 | |
| 1472 | /** |
| 1473 | * Interface provided by the client application when attaching to a {@link SoundTriggerModule} |
| 1474 | * to received recognition and error notifications. |
Philip P. Moltmann | a5fd029 | 2018-03-06 13:44:07 -0800 | [diff] [blame] | 1475 | * |
| 1476 | * @hide |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1477 | */ |
| 1478 | public static interface StatusListener { |
| 1479 | /** |
| 1480 | * Called when recognition succeeds of fails |
| 1481 | */ |
| 1482 | public abstract void onRecognition(RecognitionEvent event); |
| 1483 | |
| 1484 | /** |
Eric Laurent | d3b8223 | 2014-07-30 08:57:39 -0700 | [diff] [blame] | 1485 | * Called when a sound model has been updated |
| 1486 | */ |
| 1487 | public abstract void onSoundModelUpdate(SoundModelEvent event); |
| 1488 | |
| 1489 | /** |
| 1490 | * Called when the sound trigger native service state changes. |
| 1491 | * @param state Native service state. One of {@link SoundTrigger#SERVICE_STATE_ENABLED}, |
| 1492 | * {@link SoundTrigger#SERVICE_STATE_DISABLED} |
| 1493 | */ |
| 1494 | public abstract void onServiceStateChange(int state); |
| 1495 | |
| 1496 | /** |
Eric Laurent | e48188c | 2014-04-18 17:44:11 -0700 | [diff] [blame] | 1497 | * Called when the sound trigger native service dies |
| 1498 | */ |
| 1499 | public abstract void onServiceDied(); |
| 1500 | } |
| 1501 | } |