Add critical section to avoid thread safety issue
[platform/core/uifw/stt.git] / include / stt_internal.h
1 /*
2  * Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
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 #ifndef __STT_INTERNAL_H__
18 #define __STT_INTERNAL_H__
19
20 #include <tizen.h>
21 #include <stt.h>
22
23 /**
24  * @file stt_internal.h
25  */
26
27 #ifdef __cplusplus
28 extern "C"
29 {
30 #endif
31
32 #define STT_SPEECH_STATUS_BEGINNING_POINT_DETECTED      0
33
34 /**
35 * @brief Enumerations of audio type.
36 */
37 typedef enum {
38         STT_AUDIO_TYPE_RAW_S16 = 0,     /**< Signed 16-bit audio sample */
39         STT_AUDIO_TYPE_RAW_U8,          /**< Unsigned 8-bit audio sample */
40 } stt_audio_type_e;
41
42 /**
43  * @brief Called when user speaking is detected.
44  *
45  * @param[in] stt The STT handle
46  * @param[in] status The speech status
47  * @param[in] user_data The user data passed from the callback registration function
48  *
49  * @pre An application registers callback function using stt_set_speech_status_cb().
50  *
51  * @see stt_set_speech_status_cb()
52  * @see stt_unset_speech_status_cb()
53  */
54 typedef void (*stt_speech_status_cb)(stt_h stt, int status, void *user_data);
55
56
57 /**
58  * @brief Registers a callback function to detect the speech status is changed.
59  * @since_tizen 3.0
60  * @privilege %http://tizen.org/privilege/recorder
61  *
62  * @param[in] stt The STT handle
63  * @param[in] callback The callback function to register
64  * @param[in] user_data The user data to be passed to the callback function
65  *
66  * @return 0 on success, otherwise a negative error value
67  * @retval #STT_ERROR_NONE Successful
68  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
69  * @retval #STT_ERROR_INVALID_STATE Invalid state
70  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
71  * @retval #STT_ERROR_PERMISSION_DENIED Permission denied
72  *
73  * @pre The state should be #STT_STATE_CREATED.
74  *
75  * @see stt_speech_status_cb()
76  * @see stt_unset_speech_status_cb()
77 */
78 int stt_set_speech_status_cb(stt_h stt, stt_speech_status_cb callback, void* user_data);
79
80 /**
81  * @brief Unregisters the callback function.
82  * @since_tizen 3.0
83  * @privilege %http://tizen.org/privilege/recorder
84  *
85  * @param[in] stt The STT handle
86  *
87  * @return 0 on success, otherwise a negative error value
88  * @retval #STT_ERROR_NONE Successful
89  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
90  * @retval #STT_ERROR_INVALID_STATE Invalid state
91  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
92  * @retval #STT_ERROR_PERMISSION_DENIED Permission denied
93  *
94  * @pre The state should be #STT_STATE_CREATED.
95  *
96  * @see stt_set_speech_status_cb()
97 */
98 int stt_unset_speech_status_cb(stt_h stt);
99
100 /**
101  * @brief Sets server STT.
102  * @details Using this API, the application can set server STT with a @a key as a @a user_data
103  *      The key is a private data to set STT server.
104  *      There are 3 types of keys; "server", "rampcode" and "epd".
105  *              "server": STT server address
106  *              "rampcode": ASR ramp code
107  *              "epd": A threshold for end-point detection
108  *
109  *      The application can input the @a user_data corresponding to the @a key.
110  *              "server": "qa", "sbx"
111  *              "rampcode": "dash_dict", "dash_da"
112  *              "epd": "100", "750", etc
113  *
114  *  If the application sets those keys, it will be able to use corresponding STT engines and options.
115  *
116  * @since_tizen 3.0
117  * @privilege %http://tizen.org/privilege/recorder
118  *
119  * @param[in] stt The STT handle
120  * @param[in] key The key
121  * @param[in] user_data The user data corresponding to the key
122  *
123  * @return 0 on success, otherwise a negative error value
124  * @retval #STT_ERROR_NONE Successful
125  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
126  * @retval #STT_ERROR_INVALID_STATE Invalid state
127  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
128  * @retval #STT_ERROR_OUT_OF_MEMORY STT Out of memory
129  * @retval #STT_ERROR_PERMISSION_DENIED Permission denied
130  *
131  * @pre The state should be #STT_STATE_READY.
132  */
133 int stt_set_server_stt(stt_h stt, const char* key, char* user_data);
134
135 /**
136  * @brief Starts file recognition asynchronously.
137  * @privlevel public
138  * @privilege %http://tizen.org/privilege/recorder
139  * @remarks This function starts sending recorded data from file to engine.
140  * @param[in] stt The STT handle
141  * @param[in] language The language selected from stt_foreach_supported_languages()
142  * @param[in] type The type for recognition (e.g. #STT_RECOGNITION_TYPE_FREE, #STT_RECOGNITION_TYPE_FREE_PARTIAL)
143  * @param[in] filepath PCM filepath for recognition
144  * @param[in] audio_type audio type of file
145  * @param[in] sample_rate sample rate of file
146  * @return @c 0 on success,
147  *         otherwise a negative error value
148  * @retval #STT_ERROR_NONE Successful
149  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
150  * @retval #STT_ERROR_INVALID_STATE Invalid state
151  * @retval #STT_ERROR_OPERATION_FAILED Operation failure
152  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
153  * @retval #STT_ERROR_PERMISSION_DENIED Permission denied
154  * @retval #STT_ERROR_IN_PROGRESS_TO_RECORDING Progress to recording is not finished
155  * @pre The state should be #STT_STATE_READY.
156  * @post It will invoke stt_state_changed_cb(), if you register a callback with stt_state_changed_cb().
157  *       If this function succeeds, the STT state will be #STT_STATE_RECORDING.
158  *       If you call this function again before state changes, you will receive STT_ERROR_IN_PROGRESS_TO_RECORDING.
159  * @see stt_cancel_file()
160  * @see stt_state_changed_cb()
161 */
162 int stt_start_file(stt_h stt, const char* language, const char* type, const char* filepath, stt_audio_type_e audio_type, int sample_rate);
163
164 /**
165  * @brief Cancels processing file recognition asynchronously.
166  * @privlevel public
167  * @privilege %http://tizen.org/privilege/recorder
168  * @remarks This function cancels recording and engine cancels recognition processing.
169  *          After successful cancel, stt_state_changed_cb() is called otherwise if error is occurred, stt_error_cb() is called.
170  * @param[in] stt The STT handle
171  * @return @c 0 on success,
172  *         otherwise a negative error value
173  * @retval #STT_ERROR_NONE Successful
174  * @retval #STT_ERROR_INVALID_PARAMETER Invalid parameter
175  * @retval #STT_ERROR_INVALID_STATE Invalid state
176  * @retval #STT_ERROR_OPERATION_FAILED Operation failure
177  * @retval #STT_ERROR_NOT_SUPPORTED STT NOT supported
178  * @retval #STT_ERROR_PERMISSION_DENIED Permission denied
179  * @retval #STT_ERROR_IN_PROGRESS_TO_READY Progress to ready is not finished
180  * @retval #STT_ERROR_IN_PROGRESS_TO_RECORDING Progress to recording is not finished
181  * @retval #STT_ERROR_IN_PROGRESS_TO_PROCESSING Progress to processing is not finished
182  * @pre The state should be #STT_STATE_RECORDING or #STT_STATE_PROCESSING.
183  * @post It will invoke stt_state_changed_cb(), if you register a callback with stt_state_changed_cb().
184  *       If this function succeeds, the STT state will be #STT_STATE_READY.
185  *       If you call this function again before state changes, you will receive STT_ERROR_IN_PROGRESS_TO_READY.
186  * @see stt_start_file()
187  * @see stt_state_changed_cb()
188 */
189 int stt_cancel_file(stt_h stt);
190
191 #ifdef __cplusplus
192 }
193 #endif
194
195 /**
196  * @}@}
197  */
198
199 #endif /* __STT_INTERNAL_H__ */
200