1 /* 2 * Copyright (C) 2019 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 package android.media.soundtrigger_middleware; 17 18 import android.media.soundtrigger.ModelParameter; 19 import android.media.soundtrigger.ModelParameterRange; 20 import android.media.soundtrigger.SoundModel; 21 import android.media.soundtrigger.PhraseSoundModel; 22 import android.media.soundtrigger.RecognitionConfig; 23 24 /** 25 * A sound-trigger module. 26 * 27 * This interface allows a client to operate a sound-trigger device, intended for low-power 28 * detection of various sound patterns, represented by a "sound model". 29 * 30 * Basic operation is to load a sound model (either a generic one or a "phrase" model), then 31 * initiate recognition on this model. A trigger will be delivered asynchronously via a callback 32 * provided by the caller earlier, when attaching to this interface. 33 * 34 * In additon to recognition events, this module will also produce abort events in cases where 35 * recognition has been externally preempted. 36 * 37 * {@hide} 38 */ 39 interface ISoundTriggerModule { 40 /** 41 * Load a sound model. Will return a handle to the model on success or will throw a 42 * ServiceSpecificException with one of the {@link Status} error codes upon a recoverable error 43 * (for example, lack of resources of loading a model at the time of call. 44 * Model must eventually be unloaded using {@link #unloadModel(int)} prior to detaching. 45 * 46 * May throw a ServiceSpecificException with an RESOURCE_CONTENTION status to indicate that 47 * resources required for loading the model are currently consumed by other clients. 48 */ loadModel(in SoundModel model)49 int loadModel(in SoundModel model); 50 51 /** 52 * Load a phrase sound model. Will return a handle to the model on success or will throw a 53 * ServiceSpecificException with one of the {@link Status} error codes upon a recoverable error 54 * (for example, lack of resources of loading a model at the time of call. 55 * Model must eventually be unloaded using unloadModel prior to detaching. 56 * 57 * May throw a ServiceSpecificException with an RESOURCE_CONTENTION status to indicate that 58 * resources required for loading the model are currently consumed by other clients. 59 */ loadPhraseModel(in PhraseSoundModel model)60 int loadPhraseModel(in PhraseSoundModel model); 61 62 /** 63 * Unload a model, previously loaded with loadModel or loadPhraseModel. After unloading, model 64 * can no longer be used for recognition and the resources occupied by it are released. 65 * Model must not be active at the time of unloading. Cient may call stopRecognition to ensure 66 * that. 67 */ unloadModel(int modelHandle)68 void unloadModel(int modelHandle); 69 70 /** 71 * Initiate recognition on a previously loaded model. 72 * Recognition event would eventually be delivered via the client-provided callback, typically 73 * supplied during attachment to this interface. 74 * 75 * Once a recognition event is passed to the client, the recognition automatically become 76 * inactive, unless the event is of the RecognitionStatus.FORCED kind. Client can also shut down 77 * the recognition explicitly, via stopRecognition. 78 * 79 * May throw a ServiceSpecificException with an RESOURCE_CONTENTION status to indicate that 80 * resources required for starting the model are currently consumed by other clients. 81 */ startRecognition(int modelHandle, in RecognitionConfig config)82 void startRecognition(int modelHandle, in RecognitionConfig config); 83 84 /** 85 * Stop a recognition of a previously active recognition. Will NOT generate a recognition event. 86 * This call is idempotent - calling it on an inactive model has no effect. However, it must 87 * only be used with a loaded model handle. 88 */ stopRecognition(int modelHandle)89 void stopRecognition(int modelHandle); 90 91 /** 92 * Force generation of a recognition event. Handle must be that of a loaded model. If 93 * recognition is inactive, will do nothing. If recognition is active, will asynchronously 94 * deliever an event with RecognitionStatus.FORCED status and leave recognition in active state. 95 * To avoid any race conditions, once an event signalling the automatic stopping of recognition 96 * is sent, no more forced events will get sent (even if previously requested) until recognition 97 * is explicitly started again. 98 * 99 * Since not all module implementations support this feature, may throw a 100 * ServiceSpecificException with an OPERATION_NOT_SUPPORTED status. 101 */ forceRecognitionEvent(int modelHandle)102 void forceRecognitionEvent(int modelHandle); 103 104 /** 105 * Set a model specific parameter with the given value. This parameter 106 * will keep its value for the duration the model is loaded regardless of starting and stopping 107 * recognition. Once the model is unloaded, the value will be lost. 108 * It is expected to check if the handle supports the parameter via the 109 * queryModelParameterSupport API prior to calling this method. 110 * 111 * @param modelHandle The sound model handle indicating which model to modify parameters 112 * @param modelParam Parameter to set which will be validated against the 113 * ModelParameter type. 114 * @param value The value to set for the given model parameter 115 */ setModelParameter(int modelHandle, ModelParameter modelParam, int value)116 void setModelParameter(int modelHandle, ModelParameter modelParam, int value); 117 118 /** 119 * Get a model specific parameter. This parameter will keep its value 120 * for the duration the model is loaded regardless of starting and stopping recognition. 121 * Once the model is unloaded, the value will be lost. If the value is not set, a default 122 * value is returned. See ModelParameter for parameter default values. 123 * It is expected to check if the handle supports the parameter via the 124 * queryModelParameterSupport API prior to calling this method. 125 * 126 * @param modelHandle The sound model associated with given modelParam 127 * @param modelParam Parameter to set which will be validated against the 128 * ModelParameter type. 129 * @return Value set to the requested parameter. 130 */ getModelParameter(int modelHandle, ModelParameter modelParam)131 int getModelParameter(int modelHandle, ModelParameter modelParam); 132 133 /** 134 * Determine if parameter control is supported for the given model handle, and its valid value 135 * range if it is. 136 * 137 * @param modelHandle The sound model handle indicating which model to query 138 * @param modelParam Parameter to set which will be validated against the 139 * ModelParameter type. 140 * @return If parameter is supported, the return value is its valid range, otherwise null. 141 */ queryModelParameterSupport(int modelHandle, ModelParameter modelParam)142 @nullable ModelParameterRange queryModelParameterSupport(int modelHandle, 143 ModelParameter modelParam); 144 145 /** 146 * Detach from the module, releasing any active resources. 147 * This will ensure the client callback is no longer called after this call returns. 148 * All models must have been unloaded prior to calling this method. 149 */ detach()150 void detach(); 151 }