• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
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 com.android.server.soundtrigger;
18 
19 import android.annotation.Nullable;
20 import android.hardware.soundtrigger.IRecognitionStatusCallback;
21 import android.hardware.soundtrigger.ModelParams;
22 import android.hardware.soundtrigger.SoundTrigger;
23 import android.hardware.soundtrigger.SoundTrigger.Keyphrase;
24 import android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel;
25 import android.hardware.soundtrigger.SoundTrigger.ModelParamRange;
26 import android.hardware.soundtrigger.SoundTrigger.ModuleProperties;
27 import android.hardware.soundtrigger.SoundTrigger.RecognitionConfig;
28 
29 import com.android.server.voiceinteraction.VoiceInteractionManagerService;
30 
31 import java.io.FileDescriptor;
32 import java.io.PrintWriter;
33 
34 /**
35  * Provides a local service for managing voice-related recoginition models. This is primarily used
36  * by the {@link VoiceInteractionManagerService}.
37  */
38 public abstract class SoundTriggerInternal {
39     /**
40      * Return codes for {@link #startRecognition(int, KeyphraseSoundModel,
41      *      IRecognitionStatusCallback, RecognitionConfig)},
42      * {@link #stopRecognition(int, IRecognitionStatusCallback)}
43      */
44     public static final int STATUS_ERROR = SoundTrigger.STATUS_ERROR;
45     public static final int STATUS_OK = SoundTrigger.STATUS_OK;
46 
47     /**
48      * Starts recognition for the given keyphraseId.
49      *
50      * @param keyphraseId The identifier of the keyphrase for which
51      *        the recognition is to be started.
52      * @param soundModel The sound model to use for recognition.
53      * @param listener The listener for the recognition events related to the given keyphrase.
54      * @return One of {@link #STATUS_ERROR} or {@link #STATUS_OK}.
55      */
startRecognition(int keyphraseId, KeyphraseSoundModel soundModel, IRecognitionStatusCallback listener, RecognitionConfig recognitionConfig)56     public abstract int startRecognition(int keyphraseId, KeyphraseSoundModel soundModel,
57             IRecognitionStatusCallback listener, RecognitionConfig recognitionConfig);
58 
59     /**
60      * Stops recognition for the given {@link Keyphrase} if a recognition is
61      * currently active.
62      *
63      * @param keyphraseId The identifier of the keyphrase for which
64      *        the recognition is to be stopped.
65      * @param listener The listener for the recognition events related to the given keyphrase.
66      *
67      * @return One of {@link #STATUS_ERROR} or {@link #STATUS_OK}.
68      */
stopRecognition(int keyphraseId, IRecognitionStatusCallback listener)69     public abstract int stopRecognition(int keyphraseId, IRecognitionStatusCallback listener);
70 
getModuleProperties()71     public abstract ModuleProperties getModuleProperties();
72 
73     /**
74      * Set a model specific {@link ModelParams} with the given value. This
75      * parameter will keep its value for the duration the model is loaded regardless of starting and
76      * stopping recognition. Once the model is unloaded, the value will be lost.
77      * {@link SoundTriggerInternal#queryParameter} should be checked first before calling this
78      * method.
79      *
80      * @param keyphraseId The identifier of the keyphrase for which
81      *        to modify model parameters
82      * @param modelParam   {@link ModelParams}
83      * @param value        Value to set
84      * @return - {@link SoundTrigger#STATUS_OK} in case of success
85      *         - {@link SoundTrigger#STATUS_NO_INIT} if the native service cannot be reached
86      *         - {@link SoundTrigger#STATUS_BAD_VALUE} invalid input parameter
87      *         - {@link SoundTrigger#STATUS_INVALID_OPERATION} if the call is out of sequence or
88      *           if API is not supported by HAL
89      */
setParameter(int keyphraseId, @ModelParams int modelParam, int value)90     public abstract int setParameter(int keyphraseId, @ModelParams int modelParam, int value);
91 
92     /**
93      * Get a model specific {@link ModelParams}. This parameter will keep its value
94      * for the duration the model is loaded regardless of starting and stopping recognition.
95      * Once the model is unloaded, the value will be lost. If the value is not set, a default
96      * value is returned. See ModelParams for parameter default values.
97      * {@link SoundTriggerInternal#queryParameter} should be checked first before calling this
98      * method.
99      *
100      * @param keyphraseId The identifier of the keyphrase for which
101      *        to modify model parameters
102      * @param modelParam   {@link ModelParams}
103      * @return value of parameter
104      * @throws UnsupportedOperationException if hal or model do not support this API.
105      *         queryParameter should be checked first.
106      * @throws IllegalArgumentException if invalid model handle or parameter is passed.
107      *         queryParameter should be checked first.
108      */
getParameter(int keyphraseId, @ModelParams int modelParam)109     public abstract int getParameter(int keyphraseId, @ModelParams int modelParam);
110 
111     /**
112      * Determine if parameter control is supported for the given model handle.
113      * This method should be checked prior to calling {@link SoundTriggerInternal#setParameter}
114      * or {@link SoundTriggerInternal#getParameter}.
115      *
116      * @param keyphraseId The identifier of the keyphrase for which
117      *        to modify model parameters
118      * @param modelParam {@link ModelParams}
119      * @return supported range of parameter, null if not supported
120      */
121     @Nullable
queryParameter(int keyphraseId, @ModelParams int modelParam)122     public abstract ModelParamRange queryParameter(int keyphraseId,
123             @ModelParams int modelParam);
124 
125     /**
126      * Unloads (and stops if running) the given keyphraseId
127      */
unloadKeyphraseModel(int keyphaseId)128     public abstract int unloadKeyphraseModel(int keyphaseId);
129 
dump(FileDescriptor fd, PrintWriter pw, String[] args)130     public abstract void dump(FileDescriptor fd, PrintWriter pw, String[] args);
131 }
132