1fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent/*
2fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent * Copyright 2016 The Android Open Source Project
3fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent *
4fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent * Licensed under the Apache License, Version 2.0 (the "License");
5fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent * you may not use this file except in compliance with the License.
6fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent * You may obtain a copy of the License at
7fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent *
8fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent *      http://www.apache.org/licenses/LICENSE-2.0
9fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent *
10fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent * Unless required by applicable law or agreed to in writing, software
11fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent * distributed under the License is distributed on an "AS IS" BASIS,
12fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent * See the License for the specific language governing permissions and
14fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent * limitations under the License.
15fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent */
16fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent
17fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurentpackage android.hardware.soundtrigger@2.0;
18fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent
19fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurentimport android.hardware.audio.common@2.0;
20fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent
21fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurentinterface ISoundTriggerHwCallback {
22fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent    enum RecognitionStatus : uint32_t {
23fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent        SUCCESS  = 0,
24fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent        ABORT    = 1,
25fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent        FAILURE  = 2,
26fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent    };
27fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent
28fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent    enum SoundModelStatus : uint32_t {
29fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent        UPDATED  = 0,
30fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent    };
31fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent
3240d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber    /**
33fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent     * Generic recognition event sent via recognition callback
34fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent     */
35fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent    struct RecognitionEvent {
3640d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber        /** Recognition status e.g. SUCCESS */
37fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent        RecognitionStatus status;
3840d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber        /** Sound model type for this event. e.g SoundModelType.TYPE_KEYPHRASE */
39fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent        SoundModelType    type;
4040d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber        /** Handle of loaded sound model which triggered the event */
41fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent        SoundModelHandle  model;
4240d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber        /** It is possible to capture audio from this */
4340d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber        /** utterance buffered by the implementation */
44fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent        bool              captureAvailable;
4540d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber        /** Audio session ID. framework use */
46fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent        int32_t           captureSession;
4740d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber        /**
4840d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber         * Delay in ms between end of model detection and start of audio
4940d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber        /**
5040d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber         * available for capture. A negative value is possible
51fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent         * (e.g. if key phrase is also available for capture */
52fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent        int32_t           captureDelayMs;
5340d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber        /**
5440d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber         * Duration in ms of audio captured before the start of the trigger.
55fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent         * 0 if none. */
56fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent        int32_t           capturePreambleMs;
5740d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber        /** The opaque data is the capture of the trigger sound */
58fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent        bool              triggerInData;
5940d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber        /**
6040d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber         * Audio format of either the trigger in event data or to use for
61fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent         * capture of the rest of the utterance */
62fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent        AudioConfig       audioConfig;
6340d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber        /** Opaque event data */
64fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent        vec<uint8_t>      data;
65fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent    };
66fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent
6740d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber    /**
68fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent     * Specialized recognition event for key phrase recognitions
69fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent     */
70fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent    struct PhraseRecognitionEvent {
7140d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber        /** Common part of the recognition event */
72fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent        RecognitionEvent common;
7340d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber        /** List of descriptors for each recognized key phrase */
74fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent        vec<PhraseRecognitionExtra> phraseExtras;
75fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent    };
76fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent
7740d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber    /**
78fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent     * Event sent via load sound model callback
79fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent     */
80fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent    struct ModelEvent {
8140d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber         /** Sound model status e.g. SoundModelStatus.UPDATED */
82fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent        SoundModelStatus status;
8340d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber        /** Loaded sound model that triggered the event */
84fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent        SoundModelHandle model;
8540d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber        /** Opaque event data, passed transparently by the framework */
86fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent        vec<uint8_t>     data;
87fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent    };
88fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent
89fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent    typedef int32_t CallbackCookie;
90fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent
9140d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber    /**
92fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent     * Callback method called by the HAL when the sound recognition triggers
93fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent     * @param event A RecognitionEvent structure containing detailed results
94fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent     *              of the recognition triggered
95fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent     * @param cookie The cookie passed by the framework when recognition was
96fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent     *               started (see ISoundtriggerHw.startRecognition()
97fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent     */
98fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent    recognitionCallback(RecognitionEvent event, CallbackCookie cookie);
99a4b776c97a07498aa76e186d5eec88ea8b32dbdfEric Laurent
10040d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber    /**
101a4b776c97a07498aa76e186d5eec88ea8b32dbdfEric Laurent     * Callback method called by the HAL when the sound recognition triggers
102a4b776c97a07498aa76e186d5eec88ea8b32dbdfEric Laurent     * for a key phrase sound model.
103a4b776c97a07498aa76e186d5eec88ea8b32dbdfEric Laurent     * @param event A RecognitionEvent structure containing detailed results
104a4b776c97a07498aa76e186d5eec88ea8b32dbdfEric Laurent     *              of the recognition triggered
105a4b776c97a07498aa76e186d5eec88ea8b32dbdfEric Laurent     * @param cookie The cookie passed by the framework when recognition was
106a4b776c97a07498aa76e186d5eec88ea8b32dbdfEric Laurent     *               started (see ISoundtriggerHw.startRecognition()
107a4b776c97a07498aa76e186d5eec88ea8b32dbdfEric Laurent     */
108a4b776c97a07498aa76e186d5eec88ea8b32dbdfEric Laurent    phraseRecognitionCallback(PhraseRecognitionEvent event,
109a4b776c97a07498aa76e186d5eec88ea8b32dbdfEric Laurent                              CallbackCookie cookie);
11040d3a9bd8c62714ee58f9363c4456f764aa5a95dAndreas Huber    /**
111fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent     * Callback method called by the HAL when the sound model loading completes
112fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent     * @param event A ModelEvent structure containing detailed results of the
113fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent     *              model loading operation
114fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent     * @param cookie The cookie passed by the framework when loading was
115fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent     *               initiated (see ISoundtriggerHw.loadSoundModel()
116fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent     */
117fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent    soundModelCallback(ModelEvent event, CallbackCookie cookie);
118fc496a2fffd5e6a5bb49871ea08bb6f13a57103aEric Laurent};
119