[ACR-1449] Add new api to set audio type
[platform/core/uifw/stt.git] / include / stte.h
1 /*
2 *  Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
3 *  Licensed under the Apache License, Version 2.0 (the "License");
4 *  you may not use this file except in compliance with the License.
5 *  You may obtain a copy of the License at
6 *  http://www.apache.org/licenses/LICENSE-2.0
7 *  Unless required by applicable law or agreed to in writing, software
8 *  distributed under the License is distributed on an "AS IS" BASIS,
9 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 *  See the License for the specific language governing permissions and
11 *  limitations under the License.
12 */
13
14
15 #ifndef __STT_ENGINE_MAIN_H__
16 #define __STT_ENGINE_MAIN_H__
17
18
19 #include <tizen.h>
20
21
22 /**
23 * @addtogroup CAPI_UIX_STTE_MODULE
24 * @{
25 */
26
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32
33 /**
34 * @brief Enumeration for error codes.
35 * @since_tizen 3.0
36 */
37 typedef enum {
38         STTE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
39         STTE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of Memory */
40         STTE_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
41         STTE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
42         STTE_ERROR_NETWORK_DOWN = TIZEN_ERROR_NETWORK_DOWN, /**< Network down(Out of network) */
43         STTE_ERROR_INVALID_STATE = TIZEN_ERROR_STT | 0x01, /**< Invalid state */
44         STTE_ERROR_INVALID_LANGUAGE = TIZEN_ERROR_STT | 0x02, /**< Invalid language */
45         STTE_ERROR_OPERATION_FAILED = TIZEN_ERROR_STT | 0x04, /**< Operation failed */
46         STTE_ERROR_NOT_SUPPORTED_FEATURE = TIZEN_ERROR_STT | 0x05, /**< Not supported feature */
47         STTE_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */
48         STTE_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
49         STTE_ERROR_RECORDING_TIMED_OUT = TIZEN_ERROR_STT | 0x06 /**< Recording timed out */
50 } stte_error_e;
51
52
53 /**
54 * @brief Enumeration for audio type.
55 * @since_tizen 3.0
56 */
57 typedef enum {
58         STTE_AUDIO_TYPE_PCM_S16_LE = 0, /**< Signed 16bit audio type, Little endian */
59         STTE_AUDIO_TYPE_PCM_U8 /**< Unsigned 8bit audio type */
60 } stte_audio_type_e;
61
62
63 /**
64 * @brief Enumeration for callback event.
65 * @since_tizen 3.0
66 */
67 typedef enum {
68         STTE_RESULT_EVENT_FINAL_RESULT = 0, /**< Event when either the full matched or the final result is delivered */
69         STTE_RESULT_EVENT_PARTIAL_RESULT, /**< Event when the partial matched result is delivered */
70         STTE_RESULT_EVENT_ERROR /**< Event when the recognition has failed */
71 } stte_result_event_e;
72
73
74 /**
75 * @brief Enumeration for result time callback event.
76 * @since_tizen 3.0
77 */
78 typedef enum {
79         STTE_RESULT_TIME_EVENT_BEGINNING = 0, /**< Event when the token is beginning type */
80         STTE_RESULT_TIME_EVENT_MIDDLE, /**< Event when the token is middle type */
81         STTE_RESULT_TIME_EVENT_END /**< Event when the token is end type */
82 } stte_result_time_event_e;
83
84
85 /**
86 * @brief Enumeration for speech status.
87 * @since_tizen 3.0
88 */
89 typedef enum {
90         STTE_SPEECH_STATUS_BEGINNING_POINT_DETECTED = 0, /**< Beginning point of speech is detected */
91         STTE_SPEECH_STATUS_END_POINT_DETECTED /**< End point of speech is detected */
92 } stte_speech_status_e;
93
94
95 /**
96 * @brief Definition for free form dictation and default type.
97 * @since_tizen 3.0
98 */
99 #define STTE_RECOGNITION_TYPE_FREE              "stt.recognition.type.FREE"
100
101
102 /**
103 * @brief Definition for free form dictation continuously.
104 * @since_tizen 3.0
105 */
106 #define STTE_RECOGNITION_TYPE_FREE_PARTIAL      "stt.recognition.type.FREE.PARTIAL"
107
108
109 /**
110 * @brief Definition for None message.
111 * @since_tizen 3.0
112 */
113 #define STTE_RESULT_MESSAGE_NONE                "stt.result.message.none"
114
115
116 /**
117 * @brief Definition for failed recognition because the speech started too soon.
118 * @since_tizen 3.0
119 */
120 #define STTE_RESULT_MESSAGE_ERROR_TOO_SOON      "stt.result.message.error.too.soon"
121
122
123 /**
124 * @brief Definition for failed recognition because the speech started too short.
125 * @since_tizen 3.0
126 */
127 #define STTE_RESULT_MESSAGE_ERROR_TOO_SHORT     "stt.result.message.error.too.short"
128
129
130 /**
131 * @brief Definition for failed recognition because the speech started too long.
132 * @since_tizen 3.0
133 */
134 #define STTE_RESULT_MESSAGE_ERROR_TOO_LONG      "stt.result.message.error.too.long"
135
136
137 /**
138 * @brief Definition for failed recognition because the speech started too quiet to listen.
139 * @since_tizen 3.0
140 */
141 #define STTE_RESULT_MESSAGE_ERROR_TOO_QUIET     "stt.result.message.error.too.quiet"
142
143
144 /**
145 * @brief Definition for failed recognition because the speech started too loud to listen.
146 * @since_tizen 3.0
147 */
148 #define STTE_RESULT_MESSAGE_ERROR_TOO_LOUD      "stt.result.message.error.too.loud"
149
150
151 /**
152 * @brief Definition for failed recognition because the speech started too fast to listen.
153 * @since_tizen 3.0
154 */
155 #define STTE_RESULT_MESSAGE_ERROR_TOO_FAST      "stt.result.message.error.too.fast"
156
157
158 /**
159  * @brief Definition of audio ID that means audio source from bluetooth.
160  * @since_tizen 5.5
161  */
162 #define STTE_AUDIO_ID_BLUETOOTH         "STT_AUDIO_ID_BLUETOOTH"
163
164
165 /**
166  * @brief Definition of audio ID that means audio source from wifi.
167  * @since_tizen 5.5
168  */
169 #define STTE_AUDIO_ID_WIFI              "STT_AUDIO_ID_WIFI"
170
171
172 /**
173 * @brief Called when STT engine provides the time stamp of result to the engine service user.
174 * @details This callback function is implemented by the engine service user. Therefore, the engine developer does NOT have to implement this callback function.
175 * @since_tizen 3.0
176 * @remarks This callback function is called in stte_foreach_result_time_cb() for adding time information.
177 *          @a user_data must be transferred from stte_foreach_result_time_cb().
178 * @param[in] index The result index
179 * @param[in] event The token event
180 * @param[in] text The result text
181 * @param[in] start_time The time started speaking the result text
182 * @param[in] end_time The time finished speaking the result text
183 * @param[in] user_data The user data passed from stte_foreach_result_time_cb()
184 * @return @c true to continue with the next iteration of the loop
185 *         @c false to break out of the loop
186 * @pre stte_send_result() should be called.
187 * @see stte_send_result()
188 * @see stte_foreach_result_time_cb()
189 */
190 typedef bool (*stte_result_time_cb)(int index, stte_result_time_event_e event, const char* text,
191                                 long start_time, long end_time, void* user_data);
192
193
194 /**
195 * @brief Called when STT engine informs the engine service user about whole supported language list.
196 * @details This callback function is implemented by the engine service user. Therefore, the engine developer does NOT have to implement this callback function.
197 * @since_tizen 3.0
198 * @remarks This callback function is called in stte_foreach_supported_langs_cb() to inform the whole supported language list.
199 *          @a user_data must be transferred from stte_foreach_supported_langs_cb().
200 * @param[in] language The language is specified as an ISO 3166 alpha-2 two letter country-code
201 *                     followed by ISO 639-1 for the two-letter language code
202 *                     For example, "ko_KR" for Korean, "en_US" for American English
203 * @param[in] user_data The user data passed from stte_foreach_supported_langs_cb()
204 * @return @c true to continue with the next iteration of the loop
205 *         @c false to break out of the loop
206 * @pre stte_foreach_supported_langs_cb() will invoke this callback function.
207 * @see stte_foreach_supported_langs_cb()
208 */
209 typedef bool (*stte_supported_language_cb)(const char* language, void* user_data);
210
211
212 /**
213 * @brief Called when the engine service user initializes STT engine.
214 * @details This callback function is called by the engine service user to request for STT engine to be started.
215 * @since_tizen 3.0
216 * @remarks This callback function is mandatory and must be registered using stte_main().
217 * @return @c 0 on success, 
218 *         otherwise a negative error value
219 * @retval #STTE_ERROR_NONE Successful
220 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
221 * @retval #STTE_ERROR_INVALID_STATE Already initialized
222 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
223 * @see stte_deinitialize_cb()
224 */
225 typedef int (*stte_initialize_cb)(void);
226
227
228 /**
229 * @brief Called when the engine service user deinitializes STT engine
230 * @details This callback function is called by the engine service user to request for STT engine to be deinitialized.
231 * @since_tizen 3.0
232 * @remarks This callback function is mandatory and must be registered using stte_main().
233 *          NOTE that the engine may be terminated automatically.
234 *          When this callback function is invoked, the release of resources is necessary.
235 * @return @c 0 on success, 
236 *         otherwise a negative error value
237 * @retval #STTE_ERROR_NONE Successful
238 * @retval #STTE_ERROR_INVALID_STATE Not initialized
239 * @see stte_initialize_cb()
240 */
241 typedef int (*stte_deinitialize_cb)(void);
242
243
244 /**
245 * @brief Called when the engine service user gets the whole supported language list.
246 * @since_tizen 3.0
247 * @remarks This callback function is mandatory and must be registered using stte_main().
248 *          In this function, the engine service user's callback function 'stte_supported_language_cb()' is invoked repeatedly for getting all supported languages, and @a user_data must be transferred to 'stte_supported_language_cb()'.
249 *          If 'stte_supported_language_cb()' returns @c false, it should be stopped to call 'stte_supported_language_cb()'.
250 * @param[in] callback The callback function
251 * @param[in] user_data The user data which must be passed to the callback function 'stte_supported_language_cb()'
252 * @return @c 0 on success, 
253 *         otherwise a negative error value
254 * @retval #STTE_ERROR_NONE Successful
255 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
256 * @retval #STTE_ERROR_INVALID_STATE Not initialized
257 * @post This callback function invokes stte_supported_language_cb() repeatedly for getting supported languages.
258 * @see stte_supported_language_cb()
259 */
260 typedef int (*stte_foreach_supported_langs_cb)(stte_supported_language_cb callback, void* user_data);
261
262
263 /**
264 * @brief Called when the engine service user checks whether the corresponding language is valid or not in STT engine.
265 * @since_tizen 3.0
266 * @remarks This callback function is mandatory and must be registered using stte_main().
267 * @param[in] language The language is specified as an ISO 3166 alpha-2 two letter country-code
268 *                     followed by ISO 639-1 for the two-letter language code
269 *                     For example, "ko_KR" for Korean, "en_US" for American English
270 * @param[out] is_valid A variable for checking whether the corresponding language is valid or not.
271 *                      @c true to be valid,
272 *                      @c false to be invalid
273 * @return @c 0 on success, 
274 *         otherwise a negative error value
275 * @retval #STTE_ERROR_NONE Successful
276 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
277 * @see stte_foreach_supported_languages_cb()
278 */
279 typedef int (*stte_is_valid_language_cb)(const char* language, bool* is_valid);
280
281
282 /**
283 * @brief Called when the engine service user checks whether STT engine supports silence detection.
284 * @since_tizen 3.0
285 * @remarks This callback function is mandatory and must be registered using stte_main().
286 * @return @c true to support silence detection, 
287 *         @c false not to support silence detection
288 * @see stte_set_silence_detection_cb()
289 */
290 typedef bool (*stte_support_silence_detection_cb)(void);
291
292
293 /**
294 * @brief Called when the engine service user checks whether STT engine supports the corresponding recognition type.
295 * @since_tizen 3.0
296 * @remarks This callback function is mandatory and must be registered using stte_main().
297 * @param[in] type The type for recognition (e.g. #STTE_RECOGNITION_TYPE_FREE)
298 * @param[out] is_supported A variable for checking whether STT engine supports the corresponding recognition type.
299 *                          @c true to support recognition type,
300 *                          @c false not to support recognition type
301 * @return @c 0 on success, 
302 *         otherwise a negative error value
303 * @retval #STTE_ERROR_NONE Successful
304 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
305 *
306 */
307 typedef int (*stte_support_recognition_type_cb)(const char* type, bool* is_supported);
308
309
310 /**
311 * @brief Called when the engine service user gets the proper recording format of STT engine.
312 * @since_tizen 3.0
313 * @remarks This callback function is mandatory and must be registered using stte_main().
314 *          The recording format is used for creating the recorder.
315 * @param[out] types The format used by the recorder
316 * @param[out] rate The sample rate used by the recorder
317 * @param[out] channels The number of channels used by the recorder
318 * @return @c 0 on success, 
319 *         otherwise a negative error value
320 * @retval #STTE_ERROR_NONE Successful
321 * @retval #STTE_ERROR_INVALID_STATE Not initialized
322 */
323 typedef int (*stte_get_recording_format_cb)(stte_audio_type_e* types, int* rate, int* channels);
324
325
326 /**
327 * @brief Called when the engine service user sets the silence detection.
328 * @since_tizen 3.0
329 * @remarks This callback function is mandatory and must be registered using stte_main().
330 *          If the engine service user sets this option as 'TRUE', STT engine will detect the silence (EPD) and send the callback event about it.
331 * @param[in] is_set A variable for setting the silence detection.
332 *                   @c true to detect the silence,
333 *                   @c false not to detect the silence
334 * @return @c 0 on success, 
335 *         otherwise a negative error value
336 * @retval #STTE_ERROR_NONE Successful
337 * @retval #STTE_ERROR_INVALID_STATE Not initialized
338 * @retval #STTE_ERROR_NOT_SUPPORTED_FEATURE Not supported feature
339 */
340 typedef int (*stte_set_silence_detection_cb)(bool is_set);
341
342
343 /**
344 * @brief Called when the engine service user requests for STT engine to check whether the application agreed the usage of STT engine.
345 * @details This callback function is called when the engine service user requests for STT engine to check the application's agreement about using the engine.
346 *          According to the need, the engine developer can provide some user interfaces to check the agreement.
347 * @since_tizen 3.0
348 * @remarks This callback function is mandatory and must be registered using stte_main().
349 *          If the STT engine developer wants not to check the agreement, the developer has need to return proper values as @a is_agreed in accordance with the intention. @c true if the developer regards that every application agreed the usage of the engine, @c false if the developer regards that every application disagreed.
350 *          NOTE that, however, there may be any legal issue unless the developer checks the agreement. Therefore, we suggest that the engine developers should provide a function to check the agreement.
351 * @param[in] appid The Application ID
352 * @param[out] is_agreed A variable for checking whether the application agreed to use STT engine or not.
353 *                       @c true to agree,
354 *                       @c false to disagree
355 * @return @c 0 on success, 
356 *         otherwise a negative error value
357 * @retval #STTE_ERROR_NONE Successful
358 * @retval #STTE_ERROR_INVALID_STATE Not initialized
359 * @retval #STTE_ERROR_NOT_SUPPORTED_FEATURE Not supported feature
360 */
361 typedef int (*stte_check_app_agreed_cb)(const char* appid, bool* is_agreed);
362
363
364 /**
365 * @brief Called when the engine service user checks whether STT engine needs the application's credential.
366 * @since_tizen 3.0
367 * @remarks This callback function is mandatory and must be registered using stte_main().
368 * @return @c true if STT engine needs the application's credential, 
369 *         otherwise @c false
370 */
371 typedef bool (*stte_need_app_credential_cb)(void);
372
373
374 /**
375 * @brief Called when the engine service user gets the result time information(stamp).
376 * @since_tizen 3.0
377 * @remarks This callback function is mandatory and must be registered using stte_main().
378 *          In this function, the engine service user's callback function 'stte_result_time_cb()' is invoked repeatedly for sending the time information to the engine service user, and @a user_data must be transferred to 'stte_result_time_cb()'.
379 *          If 'stte_result_time_cb()' returns @c false, it should be stopped to call 'stte_result_time_cb()'.
380 *          @a time_info is transferred from stte_send_result(). The type of @a time_info is up to the STT engine developer.
381 * @param[in] time_info The time information
382 * @param[in] callback The callback function
383 * @param[in] user_data The user data which must be passed to the callback function 'stte_result_time_cb()'
384 * @return @c 0 on success, 
385 *         otherwise a negative error value
386 * @retval #STTE_ERROR_NONE Successful
387 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
388 * @retval #STTE_ERROR_INVALID_STATE Not initialized
389 * @pre stte_send_result() will invoke this function.
390 * @post This function invokes stte_result_time_cb() repeatedly for getting result time information.
391 * @see stte_result_time_cb()
392 */
393 typedef int (*stte_foreach_result_time_cb)(void* time_info, stte_result_time_cb callback, void* user_data);
394
395
396 /**
397 * @brief Called when the engine service user starts to recognize the recording data.
398 * @since_tizen 3.0
399 * @remarks This callback function is mandatory and must be registered using stte_main().
400 *          In this callback function, STT engine must transfer the recognition result and @a user_data to the engine service user using stte_send_result().
401 *          Also, if STT engine needs the application's credential, it sets the credential granted to the application.
402 * @param[in] language The language is specified as an ISO 3166 alpha-2 two letter country-code
403 *                     followed by ISO 639-1 for the two-letter language code
404 *                     For example, "ko_KR" for Korean, "en_US" for American English
405 * @param[in] type The recognition type. (e.g. #STTE_RECOGNITION_TYPE_FREE)
406 * @param[in] appid The Application ID
407 * @param[in] credential The credential granted to the application
408 * @param[in] user_data The user data to be passed to the callback function
409 * @return @c 0 on success, 
410 *         otherwise a negative error value
411 * @retval #STTE_ERROR_NONE Successful
412 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
413 * @retval #STTE_ERROR_INVALID_STATE Invalid state
414 * @retval #STTE_ERROR_INVALID_LANGUAGE Invalid language
415 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
416 * @retval #STTE_ERROR_NETWORK_DOWN Out of network
417 * @pre The engine is not in recognition processing.
418 * @see stte_set_recording_data_cb()
419 * @see stte_stop_cb()
420 * @see stte_cancel_cb()
421 * @see stte_need_app_credential_cb()
422 */
423 typedef int (*stte_start_cb)(const char* language, const char* type, const char* appid, const char* credential, void *user_data);
424
425
426 /**
427 * @brief Called when the engine service user sets and sends the recording data for speech recognition.
428 * @details This callback function is called by the engine service user to send the recording data to STT engine.
429 *          The engine receives the recording data and uses for speech recognition.
430 * @since_tizen 3.0
431 * @remarks This callback function is mandatory and must be registered using stte_main().
432 *          Also, this function should be returned immediately after recording data copy.
433 * @param[in] data The recording data
434 * @param[in] length The length of recording data
435 * @return @c 0 on success, 
436 *         otherwise a negative error value
437 * @retval #STTE_ERROR_NONE Successful
438 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
439 * @retval #STTE_ERROR_INVALID_STATE Invalid state
440 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
441 * @pre stte_start_cb() should succeed.
442 * @post If the engine supports partial result, stte_send_result() should be invoked.
443 * @see stte_start_cb()
444 * @see stte_cancel_cb()
445 * @see stte_stop_cb()
446 */
447 typedef int (*stte_set_recording_data_cb)(const void* data, unsigned int length);
448
449
450 /**
451 * @brief Called when the engine service user stops to recognize the recording data.
452 * @details This callback function is called by the engine service user to stop recording and to get the recognition result.
453 * @since_tizen 3.0
454 * @remarks This callback function is mandatory and must be registered using stte_main().
455 * @return @c 0 on success, 
456 *         otherwise a negative error value
457 * @retval #STTE_ERROR_NONE Successful
458 * @retval #STTE_ERROR_INVALID_STATE Invalid state
459 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
460 * @retval #STTE_ERROR_NETWORK_DOWN Out of network
461 * @pre stte_start_cb() should succeed.
462 * @post After processing of the engine, stte_send_result() must be called.
463 * @see stte_start_cb()
464 * @see stte_set_recording_data_cb()
465 * @see stte_cancel_cb()
466 * @see stte_send_result()
467 */
468 typedef int (*stte_stop_cb)(void);
469
470
471 /**
472 * @brief Called when the engine service user cancels to recognize the recording data.
473 * @details This callback function is called by the engine service user to cancel to recognize the recording data.
474 *          Also, when starting the recorder is failed, this function is called.
475 * @since_tizen 3.0
476 * @remarks This callback function is mandatory and must be registered using stte_main().
477 * @return @c 0 on success, 
478 *         otherwise a negative error value
479 * @retval #STTE_ERROR_NONE Successful.
480 * @retval #STTE_ERROR_INVALID_STATE Invalid state.
481 * @pre STT engine is in recognition processing or recording.
482 * @see stte_start_cb()
483 * @see stte_stop_cb()
484 */
485 typedef int (*stte_cancel_cb)(void);
486
487
488 /**
489 * @brief Called when the engine service user requests the basic information of STT engine.
490 * @since_tizen 3.0
491 * @remarks This callback function is mandatory and must be registered using stte_main().
492 *          The allocated @a engine_uuid, @a engine_name, and @a engine_setting will be released internally.
493 *          In order to upload the engine at Tizen Appstore, both a service app and a ui app are necessary.
494 *          Therefore, @a engine_setting must be transferred to the engine service user.
495 * @param[out] engine_uuid UUID of engine
496 * @param[out] engine_name Name of engine
497 * @param[out] engine_setting The engine setting application(ui app)'s app ID
498 * @param[out] use_network A variable for checking whether the network is used or not
499 * @return @c 0 on success, 
500 *         otherwise a negative error code on failure
501 * @retval #STTE_ERROR_NONE Successful
502 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
503 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
504 */
505 typedef int (*stte_get_info_cb)(char** engine_uuid, char** engine_name, char** engine_setting, bool* use_network);
506
507
508 /**
509 * @brief Called when STT engine receives the private data from the engine service user.
510 * @details This callback function is called when the engine service user sends the private data to STT engine.
511 * @since_tizen 3.0
512 * @remarks This callback function is optional and is registered using stte_set_private_data_set_cb().
513 * @param[in] key The key field of private data
514 * @param[in] data The data field of private data
515 * @return @c 0 on success, 
516 *         otherwise a negative error value
517 * @retval #STTE_ERROR_NONE Successful
518 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
519 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
520 * @see stte_private_data_requested_cb()
521 * @see stte_set_private_data_set_cb()
522 */
523 typedef int (*stte_private_data_set_cb)(const char* key, const char* data);
524
525
526 /**
527 * @brief Called when STT engine provides the engine service user with the private data.
528 * @details This callback function is called when the engine service user gets the private data from STT engine.
529 * @since_tizen 3.0
530 * @remarks This callback function is optional and is registered using stte_set_private_data_requested_cb().
531 * @param[out] key The key field of private data
532 * @param[out] data The data field of private data
533 * @return @c 0 on success, 
534 *         otherwise a negative error value
535 * @retval #STTE_ERROR_NONE Successful
536 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
537 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
538 * @see stte_private_data_set_cb()
539 * @see stte_set_private_data_requested_cb()
540 */
541 typedef int (*stte_private_data_requested_cb)(const char* key, char** data);
542
543
544 /**
545  * @brief Called when the engine service user sets audio recording type.
546  * @since_tizen 5.5
547  * @remarks The @a audio_type can be used only in the callback. To use outside, make a copy.
548  * @param[in] audio_type Current audio type (e.g. #STTE_AUDIO_ID_BLUETOOTH or #STTE_AUDIO_ID_WIFI)
549  * @param[in] user_data user_data The user data to be passed to the callback function
550  * @return 0 on success, otherwise a negative error value.
551  * @retval #VCE_ERROR_NONE Successful.
552  * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
553  * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
554  */
555 typedef int (*stte_audio_type_cb)(const char* audio_type, void* user_data);
556
557
558 /**
559 * @brief A structure for the STT engine functions.
560 * @details This structure contains essential callback functions for operating STT engine.
561 * @since_tizen 3.0
562 * @remarks These functions are mandatory for operating STT engine. Therefore, all functions MUST be implemented.
563 */
564 typedef struct {
565         int version; /**< The version of the structure 'stte_request_callback_s' */
566         stte_get_info_cb                        get_info; /**< Called when the engine service user requests the basic information of STT engine */
567
568         stte_initialize_cb                      initialize; /**< Called when the engine service user initializes STT engine */
569         stte_deinitialize_cb                    deinitialize; /**< Called when the engine service user deinitializes STT engine */
570
571         stte_foreach_supported_langs_cb         foreach_langs; /**< Called when the engine service user gets the whole supported language list */
572         stte_is_valid_language_cb               is_valid_lang; /**< Called when the engine service user checks whether the corresponding language is valid or not*/
573         stte_support_silence_detection_cb       support_silence; /**< Called when the engine service user checks whether STT engine supports silence detection*/
574         stte_support_recognition_type_cb        support_recognition_type; /**< Called when the engine service user checks whether STT engine supports the corresponding recognition type */
575         stte_get_recording_format_cb            get_audio_format; /**< Called when the engine service user gets the proper recording format of STT engine */
576         stte_foreach_result_time_cb             foreach_result_time; /**< Called when the engine service user gets the result time information(stamp) */
577
578         stte_set_silence_detection_cb           set_silence_detection; /**< Called when the engine service user sets the silence detection */
579
580         stte_start_cb                           start; /**< Called when the engine service user starts to recognize the recording data */
581         stte_set_recording_data_cb              set_recording; /**< Called when the engine service user sets and sends the recording data for speech recognition */
582         stte_stop_cb                            stop; /**< Called when the engine service user stops to recognize the recording data */
583         stte_cancel_cb                          cancel; /**< Called when the engine service user cancels to recognize the recording data */
584
585         stte_check_app_agreed_cb                check_app_agreed; /**< Called when the engine service user requests for STT engine to check whether the application agreed the usage of STT engine */
586         stte_need_app_credential_cb             need_app_credential; /**< Called when the engine service user checks whether STT engine needs the application's credential */
587 } stte_request_callback_s;
588
589
590 /**
591 * @brief Main function for Speech-To-Text (STT) engine.
592 * @details This function is the main function for operating STT engine.
593 * @since_tizen 3.0
594 * @privlevel public
595 * @privilege %http://tizen.org/privilege/recorder
596 * @remarks The service_app_main() should be used for working the engine after this function.
597 * @param[in] argc The argument count(original)
598 * @param[in] argv The argument(original)
599 * @param[in] callback The structure of engine request callback function
600 * @return This function returns @c zero on success, 
601 *         or negative with error code on failure
602 * @retval #STTE_ERROR_NONE Successful
603 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
604 * @retval #STTE_ERROR_PERMISSION_DENIED Permission denied
605 * @retval #STTE_ERROR_NOT_SUPPORTED Not supported
606 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
607 * @see stte_request_callback_s
608 * @code
609 #include <stte.h>
610
611 // Required callback functions - MUST BE IMPLEMENTED
612 static int sttengine_get_info_cb(char** engine_uuid, char** engine_name, char** engine_setting, bool* use_network);
613 static int sttengine_initialize_cb(void);
614 static int sttengine_deinitialize_cb(void);
615 static int sttengine_is_valid_language_cb(const char* language, bool* is_valid);
616 static int sttengine_foreach_supported_langs_cb(stte_supported_language_cb callback, void* user_data);
617 static bool sttengine_support_silence_detection_cb(void);
618 static int sttengine_set_silence_detection_cb(bool is_set);
619 static int sttengine_support_recognition_type_cb(const char* type, bool* is_supported);
620 static int sttengine_get_recording_format_cb(stte_audio_type_e* types, int* rate, int* channels);
621 static int sttengine_set_recording_data_cb(const void* data, unsigned int length);
622 static int sttengine_foreach_result_time_cb(void* time_info, stte_result_time_cb callback, void* user_data);
623 static int sttengine_start_cb(const char* language, const char* type, const char* appid, const char* credential, void *user_data);
624 static int sttengine_stop_cb(void);
625 static int sttengine_cancel_cb(void);
626 static int sttengine_check_app_agreed_cb(const char* appid, bool* is_agreed);
627 static bool sttengine_need_app_credential_cb(void);
628
629 // Optional callback function
630 static int sttengine_private_data_set_cb(const char* key, const char* data);
631
632 int main(int argc, char* argv[])
633 {
634         // 1. Create a structure 'stte_request_callback_s'
635         stte_request_callback_s engine_callback = { 0, };
636
637         engine_callback.size = sizeof(stte_request_callback_s);
638         engine_callback.version = 1;
639         engine_callback.get_info = sttengine_get_info_cb;
640
641         engine_callback.initialize = sttengine_initialize_cb;
642         engine_callback.deinitialize = sttengine_deinitialize_cb;
643
644         engine_callback.foreach_langs = sttengine_foreach_supported_langs_cb;
645         engine_callback.is_valid_lang = sttengine_is_valid_language_cb;
646         engine_callback.support_silence = sttengine_support_silence_detection_cb;
647         engine_callback.support_recognition_type = sttengine_support_recognition_type_cb;
648
649         engine_callback.get_audio_format = sttengine_get_recording_format_cb;
650         engine_callback.foreach_result_time = sttengine_foreach_result_time_cb;
651
652         engine_callback.set_silence_detection = sttengine_set_silence_detection_cb;
653
654         engine_callback.start = sttengine_start_cb;
655         engine_callback.set_recording = sttengine_set_recording_data_cb;
656         engine_callback.stop = sttengine_stop_cb;
657         engine_callback.cancel = sttengine_cancel_cb;
658
659         engine_callback.check_app_agreed = sttengine_check_app_agreed_cb;
660         engine_callback.need_app_credential = sttengine_need_app_credential_cb;
661
662         // 2. Run 'stte_main()'
663         if (0 != stte_main(argc, argv, &engine_callback)) {
664                 return -1;
665         }
666
667         // Optional
668         stte_set_private_data_set_cb(sttengine_private_data_set_cb);
669
670         // 3. Set event callbacks for service app and Run 'service_app_main()'
671         char ad[50] = { 0, };
672
673         service_app_lifecycle_callback_s event_callback;
674         app_event_handler_h handlers[5] = { NULL, };
675
676         event_callback.create = service_app_create;
677         event_callback.terminate = service_app_terminate;
678         event_callback.app_control = service_app_control;
679
680         service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad);
681         service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad);
682         service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad);
683         service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad);
684
685         return service_app_main(argc, argv, &event_callback, ad);
686 }
687
688 * @endcode
689 */
690 int stte_main(int argc, char** argv, stte_request_callback_s *callback);
691
692
693 /**
694 * @brief Sends the recognition result to the engine service user.
695 * @since_tizen 3.0
696 * @remarks This API is used in stte_set_recording_data_cb() and stte_stop_cb(), when STT engine sends the recognition result to the engine service user.
697 *          This function is called in the following situations; 1) after stte_stop_cb() is called, 2) the end point of speech is detected from recording, or 3) partial result is occurred.
698 *          The recognition result and @a user_data must be transferred to the engine service user through this function.
699 *          Also, @a time_info must be transferred to stte_foreach_result_time_cb(). The type of @a time_info is up to the STT engine developer.
700 * @param[in] event The result event
701 * @param[in] type The recognition type (e.g. #STTE_RECOGNITION_TYPE_FREE, #STTE_RECOGNITION_TYPE_FREE_PARTIAL)
702 * @param[in] result Result texts
703 * @param[in] result_count Result text count
704 * @param[in] msg Engine message (e.g. #STTE_RESULT_MESSAGE_NONE, #STTE_RESULT_MESSAGE_ERROR_TOO_SHORT)
705 * @param[in] time_info The time information
706 * @param[in] user_data The user data passed from stte_start_cb()
707 * @return @c 0 on success, 
708 *         otherwise a negative error value
709 * @retval #STTE_ERROR_NONE Successful
710 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
711 * @retval #STTE_ERROR_PERMISSION_DENIED Permission denied
712 * @retval #STTE_ERROR_NOT_SUPPORTED Not supported
713 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
714 * @pre The stte_main() function should be invoked before this function is called.
715 *      stte_stop_cb() will invoke this function.
716 * @post This function invokes stte_foreach_result_time_cb().
717 * @see stte_start_cb()
718 * @see stte_set_recording_data_cb()
719 * @see stte_stop_cb()
720 * @see stte_foreach_result_time_cb()
721 */
722 int stte_send_result(stte_result_event_e event, const char* type, const char** result, int result_count,
723                                 const char* msg, void* time_info, void* user_data);
724
725
726 /**
727 * @brief Sends the error to the engine service user.
728 * @details The following error codes can be delivered.
729 *          #STTE_ERROR_NONE,
730 *          #STTE_ERROR_OUT_OF_MEMORY,
731 *          #STTE_ERROR_IO_ERROR,
732 *          #STTE_ERROR_INVALID_PARAMETER,
733 *          #STTE_ERROR_NETWORK_DOWN,
734 *          #STTE_ERROR_INVALID_STATE,
735 *          #STTE_ERROR_INVALID_LANGUAGE,
736 *          #STTE_ERROR_OPERATION_FAILED,
737 *          #STTE_ERROR_NOT_SUPPORTED_FEATURE,
738 *          #STTE_ERROR_NOT_SUPPORTED,
739 *          #STTE_ERROR_PERMISSION_DENIED,
740 *          #STTE_ERROR_RECORDING_TIMED_OUT.
741 * @since_tizen 3.0
742 * @param[in] error The error reason
743 * @param[in] msg The error message
744 * @return @c 0 on success, 
745 *         otherwise a negative error value
746 * @retval #STTE_ERROR_NONE Successful
747 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
748 * @retval #STTE_ERROR_PERMISSION_DENIED Permission denied
749 * @retval #STTE_ERROR_NOT_SUPPORTED Not supported
750 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
751 * @pre The stte_main() function should be invoked before this function is called.
752 */
753 int stte_send_error(stte_error_e error, const char* msg);
754
755
756 /**
757 * @brief Sends the speech status to the engine service user when STT engine notifies the change of the speech status.
758 * @since_tizen 3.0
759 * @remarks This API is invoked when STT engine wants to notify the change of the speech status anytime.
760 *          NOTE that this API can be invoked for recognizing the speech.
761 * @param[in] status The status of speech (e.g. STTE_SPEECH_STATUS_START_POINT_DETECTED or STTE_SPEECH_STATUS_END_POINT_DETECTED)
762 * @param[in] user_data The user data passed from the start function.
763 * @return @c 0 on success, 
764 *         otherwise a negative error value
765 * @retval #STTE_ERROR_NONE Successful
766 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
767 * @retval #STTE_ERROR_PERMISSION_DENIED Permission denied
768 * @retval #STTE_ERROR_NOT_SUPPORTED Not supported
769 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
770 * @pre The stte_main() function should be invoked before this function is called.
771 *      stte_start_cb() and stte_set_recording_data_cb() will invoke this function.
772 * @see stte_start_cb()
773 * @see stte_set_recording_data_cb()
774 */
775 int stte_send_speech_status(stte_speech_status_e status, void* user_data);
776
777
778 /**
779 * @brief Sets a callback function for setting the private data.
780 * @since_tizen 3.0
781 * @privlevel public
782 * @privilege %http://tizen.org/privilege/recorder
783 * @remarks The stte_private_data_set_cb() function is called when the engine service user sends the private data.
784 * @param[in] callback_func stte_private_data_set event callback function
785 * @return @c 0 on success, 
786 *         otherwise a negative error value
787 * @retval #STTE_ERROR_NONE Successful
788 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
789 * @retval #STTE_ERROR_PERMISSION_DENIED Permission denied
790 * @retval #STTE_ERROR_NOT_SUPPORTED Not supported
791 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
792 * @pre The stte_main() function should be invoked before this function is called.
793 * @see stte_private_data_set_cb()
794 */
795 int stte_set_private_data_set_cb(stte_private_data_set_cb callback_func);
796
797
798 /**
799 * @brief Sets a callback function for requesting the private data.
800 * @since_tizen 3.0
801 * @privlevel public
802 * @privilege %http://tizen.org/privilege/recorder
803 * @remarks The stte_private_data_requested_cb() function is called when the engine service user gets the private data from STT engine.
804 * @param[in] callback_func stte_private_data_requested event callback function
805 * @return @c 0 on success, 
806 *         otherwise a negative error value
807 * @retval #STTE_ERROR_NONE Successful
808 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
809 * @retval #STTE_ERROR_PERMISSION_DENIED Permission denied
810 * @retval #STTE_ERROR_NOT_SUPPORTED Not supported
811 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
812 * @pre The stte_main() function should be invoked before this function is called.
813 * @see stte_private_data_requested_cb()
814 */
815 int stte_set_private_data_requested_cb(stte_private_data_requested_cb callback_func);
816
817
818 /**
819 * @brief Sets a callback function for setting the audio type.
820 * @since_tizen 5.5
821 * @remarks The stte_audio_type_cb() function is called when STT framework sets audio type to the STT engine.
822 * @param[in] callback_func stte_audio_type_set event callback function
823 * @param[in] user_data The user data passed to the callback function
824 * @return @c 0 on success,
825 *         otherwise a negative error value
826 * @retval #STTE_ERROR_NONE Successful
827 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
828 * @retval #STTE_ERROR_NOT_SUPPORTED Not supported
829 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
830 * @pre The stte_main() function should be invoked before this function is called.
831 * @see stte_audio_type_cb()
832 * @see stte_unset_audio_type_set_cb()
833 */
834 int stte_set_audio_type_set_cb(stte_audio_type_cb callback_func, void* user_data);
835
836
837 /**
838 * @brief Unsets a callback function for setting the audio type.
839 * @since_tizen 5.5
840 * @return @c 0 on success,
841 *         otherwise a negative error value
842 * @retval #STTE_ERROR_NONE Successful
843 * @retval #STTE_ERROR_NOT_SUPPORTED Not supported
844 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
845 * @pre The stte_main() function should be invoked before this function is called.
846 * @see stte_set_audio_type_set_cb()
847 */
848 int stte_unset_audio_type_set_cb(void);
849
850
851 #ifdef __cplusplus
852 }
853 #endif
854
855
856 /**
857  * @}
858  */
859
860
861 #endif /* __STT_ENGINE_MAIN_H__ */