blob: cf35ef1cff6e61e1be5a2dbb11eb67c920ca4a2d [file] [log] [blame]
Eric Laurentfc496a22016-08-05 12:13:45 -07001/*
2 * Copyright 2016 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
17package android.hardware.soundtrigger@2.0;
18
19import android.hardware.audio.common@2.0;
20
21import ISoundTriggerHwCallback;
22
23interface ISoundTriggerHw {
24
25 /*
26 * Sound trigger implementation descriptor read by the framework via
27 * getProperties(). Used by SoundTrigger service to report to applications
28 * and manage concurrency and policy.
29 */
30 struct Properties {
31 /* Implementor name */
32 string implementor;
33 /* Implementation description */
34 string description;
35 /* Implementation version */
36 uint32_t version;
37 /* Unique implementation ID. The UUID must change with each version of
38 the engine implementation */
39 Uuid uuid;
40 /* Maximum number of concurrent sound models loaded */
41 uint32_t maxSoundModels;
42 /* Maximum number of key phrases */
43 uint32_t maxKeyPhrases;
44 /* Maximum number of concurrent users detected */
45 uint32_t maxUsers;
46 /* All supported modes. e.g RecognitionMode.VOICE_TRIGGER */
47 uint32_t recognitionModes;
48 /* Supports seamless transition from detection to capture */
49 bool captureTransition;
50 /* Maximum buffering capacity in ms if captureTransition is true */
51 uint32_t maxBufferMs;
52 /* Supports capture by other use cases while detection is active */
53 bool concurrentCapture;
54 /* Returns the trigger capture in event */
55 bool triggerInEvent;
56 /* Rated power consumption when detection is active with TDB
57 * silence/sound/speech ratio */
58 uint32_t powerConsumptionMw;
59 };
60
61
62 /*
63 * Base sound model descriptor. This struct is the header of a larger block
64 * passed to loadSoundModel() and contains the binary data of the
65 * sound model.
66 */
67 struct SoundModel {
68 /* Model type. e.g. SoundModelType.KEYPHRASE */
69 SoundModelType type;
70 /* Unique sound model ID. */
71 Uuid uuid;
72 /* Unique vendor ID. Identifies the engine the sound model
73 * was build for */
74 Uuid vendorUuid;
75 /* Opaque data transparent to Android framework */
76 vec<uint8_t> data;
77 };
78
79 /* Key phrase descriptor */
80 struct Phrase {
81 /* Unique keyphrase ID assigned at enrollment time */
82 uint32_t id;
83 /* Recognition modes supported by this key phrase */
84 uint32_t recognitionModes;
85 /* List of users IDs associated with this key phrase */
86 vec<uint32_t> users;
87 /* Locale - Java Locale style (e.g. en_US) */
88 string locale;
89 /* Phrase text in UTF-8 format. */
90 string text;
91 };
92
93 /*
94 * Specialized sound model for key phrase detection.
95 * Proprietary representation of key phrases in binary data must match
96 * information indicated by phrases field
97 */
98 struct PhraseSoundModel {
99 /* Common part of sound model descriptor */
100 SoundModel common;
101 /* List of descriptors for key phrases supported by this sound model */
102 vec<Phrase> phrases;
103 };
104
105 /*
106 * Configuration for sound trigger capture session passed to
107 * startRecognition() method
108 */
109 struct RecognitionConfig {
110 /* IO handle that will be used for capture. N/A if captureRequested
111 * is false */
112 AudioIoHandle captureHandle;
113 /* Input device requested for detection capture */
114 AudioDevice captureDevice;
115 /* Capture and buffer audio for this recognition instance */
116 bool captureRequested;
117 /* Configuration for each key phrase */
118 vec<PhraseRecognitionExtra> phrases;
119 /* Opaque capture configuration data transparent to the framework */
120 vec<uint8_t> data;
121 };
122
123
124 /*
125 * Retrieve implementation properties.
126 * @return retval Operation completion status: 0 in case of success,
127 * -ENODEV in case of initialization error.
128 * @return properties A Properties structure containing implementation
129 * description and capabilities.
130 */
131 getProperties() generates (int32_t retval, Properties properties);
132
133 /*
134 * Load a sound model. Once loaded, recognition of this model can be
135 * started and stopped. Only one active recognition per model at a time.
136 * The SoundTrigger service must handle concurrent recognition requests by
137 * different users/applications on the same model.
138 * The implementation returns a unique handle used by other functions
139 * (unloadSoundModel(), startRecognition(), etc...
140 * @param soundModel A SoundModel structure describing the sound model to
141 * load.
142 * @param callback The callback interface on which the soundmodelCallback()
143 * method will be called upon completion.
144 * @param cookie The value of the cookie argument passed to the completion
145 * callback. This unique context information is assigned and
146 * used only by the framework.
147 * @return retval Operation completion status: 0 in case of success,
148 * -EINVAL in case of invalid sound model (e.g 0 data size),
149 * -ENOSYS in case of invalid operation (e.g max number of
150 * models exceeded),
151 * -ENOMEM in case of memory allocation failure,
152 * -ENODEV in case of initialization error.
153 * @return modelHandle A unique handle assigned by the HAL for use by the
154 * framework when controlling activity for this sound model.
155 */
156 loadSoundModel(SoundModel soundModel,
157 ISoundTriggerHwCallback callback,
158 CallbackCookie cookie)
159 generates (int32_t retval, SoundModelHandle modelHandle);
160
161 /*
Eric Laurenta4b776c2016-10-13 15:11:24 -0700162 * Load a key phrase sound model. Once loaded, recognition of this model can
163 * be started and stopped. Only one active recognition per model at a time.
164 * The SoundTrigger service must handle concurrent recognition requests by
165 * different users/applications on the same model.
166 * The implementation returns a unique handle used by other functions
167 * (unloadSoundModel(), startRecognition(), etc...
168 * @param soundModel A PhraseSoundModel structure describing the sound model
169 * to load.
170 * @param callback The callback interface on which the soundmodelCallback()
171 * method will be called upon completion.
172 * @param cookie The value of the cookie argument passed to the completion
173 * callback. This unique context information is assigned and
174 * used only by the framework.
175 * @return retval Operation completion status: 0 in case of success,
176 * -EINVAL in case of invalid sound model (e.g 0 data size),
177 * -ENOSYS in case of invalid operation (e.g max number of
178 * models exceeded),
179 * -ENOMEM in case of memory allocation failure,
180 * -ENODEV in case of initialization error.
181 * @return modelHandle A unique handle assigned by the HAL for use by the
182 * framework when controlling activity for this sound model.
183 */
184 loadPhraseSoundModel(PhraseSoundModel soundModel,
185 ISoundTriggerHwCallback callback,
186 CallbackCookie cookie)
187 generates (int32_t retval, SoundModelHandle modelHandle);
188
189 /*
Eric Laurentfc496a22016-08-05 12:13:45 -0700190 * Unload a sound model. A sound model may be unloaded to make room for a
191 * new one to overcome implementation limitations.
192 * @param modelHandle the handle of the sound model to unload
193 * @return retval Operation completion status: 0 in case of success,
194 * -ENOSYS if the model is not loaded,
195 * -ENODEV in case of initialization error.
196 */
197 unloadSoundModel(SoundModelHandle modelHandle)
198 generates (int32_t retval);
199
200 /*
201 * Start recognition on a given model. Only one recognition active
202 * at a time per model. Once recognition succeeds of fails, the callback
203 * is called.
204 * @param modelHandle the handle of the sound model to use for recognition
205 * @param config A RecognitionConfig structure containing attributes of the
206 * recognition to perform
207 * @param callback The callback interface on which the recognitionCallback()
208 * method must be called upon recognition.
209 * @param cookie The value of the cookie argument passed to the recognition
210 * callback. This unique context information is assigned and
211 * used only by the framework.
212 * @return retval Operation completion status: 0 in case of success,
213 * -EINVAL in case of invalid recognition attributes,
214 * -ENOSYS in case of invalid model handle,
215 * -ENOMEM in case of memory allocation failure,
216 * -ENODEV in case of initialization error.
217 */
218 startRecognition(SoundModelHandle modelHandle,
219 RecognitionConfig config,
220 ISoundTriggerHwCallback callback,
221 CallbackCookie cookie)
222 generates (int32_t retval);
223
224 /*
225 * Stop recognition on a given model.
226 * The implementation must not call the recognition callback when stopped
227 * via this method.
228 * @param modelHandle The handle of the sound model to use for recognition
229 * @return retval Operation completion status: 0 in case of success,
230 * -ENOSYS in case of invalid model handle,
231 * -ENODEV in case of initialization error.
232 */
233 stopRecognition(SoundModelHandle modelHandle)
234 generates (int32_t retval);
235
236 /*
237 * Stop recognition on all models.
238 * @return retval Operation completion status: 0 in case of success,
239 * -ENODEV in case of initialization error.
240 */
241 stopAllRecognitions()
242 generates (int32_t retval);
243};