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.
15 #ifndef __STT_ENGINE_MAIN_H__
16 #define __STT_ENGINE_MAIN_H__
23 * @addtogroup CAPI_UIX_STTE_MODULE
34 * @brief Enumeration for error codes.
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 */
54 * @brief Enumeration for audio type.
58 STTE_AUDIO_TYPE_PCM_S16_LE = 0, /**< Signed 16bit audio type, Little endian */
59 STTE_AUDIO_TYPE_PCM_U8 /**< Unsigned 8bit audio type */
64 * @brief Enumeration for callback event.
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;
75 * @brief Enumeration for result time callback event.
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;
86 * @brief Enumeration for speech status.
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;
96 * @brief Definition for free form dictation and default type.
99 #define STTE_RECOGNITION_TYPE_FREE "stt.recognition.type.FREE"
103 * @brief Definition for free form dictation continuously.
106 #define STTE_RECOGNITION_TYPE_FREE_PARTIAL "stt.recognition.type.FREE.PARTIAL"
110 * @brief Definition for None message.
113 #define STTE_RESULT_MESSAGE_NONE "stt.result.message.none"
117 * @brief Definition for failed recognition because the speech started too soon.
120 #define STTE_RESULT_MESSAGE_ERROR_TOO_SOON "stt.result.message.error.too.soon"
124 * @brief Definition for failed recognition because the speech started too short.
127 #define STTE_RESULT_MESSAGE_ERROR_TOO_SHORT "stt.result.message.error.too.short"
131 * @brief Definition for failed recognition because the speech started too long.
134 #define STTE_RESULT_MESSAGE_ERROR_TOO_LONG "stt.result.message.error.too.long"
138 * @brief Definition for failed recognition because the speech started too quiet to listen.
141 #define STTE_RESULT_MESSAGE_ERROR_TOO_QUIET "stt.result.message.error.too.quiet"
145 * @brief Definition for failed recognition because the speech started too loud to listen.
148 #define STTE_RESULT_MESSAGE_ERROR_TOO_LOUD "stt.result.message.error.too.loud"
152 * @brief Definition for failed recognition because the speech started too fast to listen.
155 #define STTE_RESULT_MESSAGE_ERROR_TOO_FAST "stt.result.message.error.too.fast"
159 * @brief Called when STT engine provides the time stamp of result to the engine service user.
160 * @details This callback function is implemented by the engine service user. Therefore, the engine developer does NOT have to implement this callback function.
162 * @remarks This callback function is called in stte_foreach_result_time_cb() for adding time information.
163 * @a user_data must be transferred from stte_foreach_result_time_cb().
164 * @param[in] index The result index
165 * @param[in] event The token event
166 * @param[in] text The result text
167 * @param[in] start_time The time started speaking the result text
168 * @param[in] end_time The time finished speaking the result text
169 * @param[in] user_data The user data passed from stte_foreach_result_time_cb()
170 * @return @c true to continue with the next iteration of the loop
171 * @c false to break out of the loop
172 * @pre stte_send_result() should be called.
173 * @see stte_send_result()
174 * @see stte_foreach_result_time_cb()
176 typedef bool (*stte_result_time_cb)(int index, stte_result_time_event_e event, const char* text,
177 long start_time, long end_time, void* user_data);
181 * @brief Called when STT engine informs the engine service user about whole supported language list.
182 * @details This callback function is implemented by the engine service user. Therefore, the engine developer does NOT have to implement this callback function.
184 * @remarks This callback function is called in stte_foreach_supported_langs_cb() to inform the whole supported language list.
185 * @a user_data must be transferred from stte_foreach_supported_langs_cb().
186 * @param[in] language The language is specified as an ISO 3166 alpha-2 two letter country-code
187 * followed by ISO 639-1 for the two-letter language code
188 * For example, "ko_KR" for Korean, "en_US" for American English
189 * @param[in] user_data The user data passed from stte_foreach_supported_langs_cb()
190 * @return @c true to continue with the next iteration of the loop
191 * @c false to break out of the loop
192 * @pre stte_foreach_supported_langs_cb() will invoke this callback function.
193 * @see stte_foreach_supported_langs_cb()
195 typedef bool (*stte_supported_language_cb)(const char* language, void* user_data);
199 * @brief Called when the engine service user initializes STT engine.
200 * @details This callback function is called by the engine service user to request for STT engine to be started.
202 * @remarks This callback function is mandatory and must be registered using stte_main().
203 * @return @c 0 on success,
204 * otherwise a negative error value
205 * @retval #STTE_ERROR_NONE Successful
206 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
207 * @retval #STTE_ERROR_INVALID_STATE Already initialized
208 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
209 * @see stte_deinitialize_cb()
211 typedef int (*stte_initialize_cb)(void);
215 * @brief Called when the engine service user deinitializes STT engine
216 * @details This callback function is called by the engine service user to request for STT engine to be deinitialized.
218 * @remarks This callback function is mandatory and must be registered using stte_main().
219 * NOTE that the engine may be terminated automatically.
220 * When this callback function is invoked, the release of resources is necessary.
221 * @return @c 0 on success,
222 * otherwise a negative error value
223 * @retval #STTE_ERROR_NONE Successful
224 * @retval #STTE_ERROR_INVALID_STATE Not initialized
225 * @see stte_initialize_cb()
227 typedef int (*stte_deinitialize_cb)(void);
231 * @brief Called when the engine service user gets the whole supported language list.
233 * @remarks This callback function is mandatory and must be registered using stte_main().
234 * 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()'.
235 * If 'stte_supported_language_cb()' returns @c false, it should be stopped to call 'stte_supported_language_cb()'.
236 * @param[in] callback The callback function
237 * @param[in] user_data The user data which must be passed to the callback function 'stte_supported_language_cb()'
238 * @return @c 0 on success,
239 * otherwise a negative error value
240 * @retval #STTE_ERROR_NONE Successful
241 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
242 * @retval #STTE_ERROR_INVALID_STATE Not initialized
243 * @post This callback function invokes stte_supported_language_cb() repeatedly for getting supported languages.
244 * @see stte_supported_language_cb()
246 typedef int (*stte_foreach_supported_langs_cb)(stte_supported_language_cb callback, void* user_data);
250 * @brief Called when the engine service user checks whether the corresponding language is valid or not in STT engine.
252 * @remarks This callback function is mandatory and must be registered using stte_main().
253 * @param[in] language The language is specified as an ISO 3166 alpha-2 two letter country-code
254 * followed by ISO 639-1 for the two-letter language code
255 * For example, "ko_KR" for Korean, "en_US" for American English
256 * @param[out] is_valid A variable for checking whether the corresponding language is valid or not.
257 * @c true to be valid,
258 * @c false to be invalid
259 * @return @c 0 on success,
260 * otherwise a negative error value
261 * @retval #STTE_ERROR_NONE Successful
262 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
263 * @see stte_foreach_supported_languages_cb()
265 typedef int (*stte_is_valid_language_cb)(const char* language, bool* is_valid);
269 * @brief Called when the engine service user checks whether STT engine supports silence detection.
271 * @remarks This callback function is mandatory and must be registered using stte_main().
272 * @return @c true to support silence detection,
273 * @c false not to support silence detection
274 * @see stte_set_silence_detection_cb()
276 typedef bool (*stte_support_silence_detection_cb)(void);
280 * @brief Called when the engine service user checks whether STT engine supports the corresponding recognition type.
282 * @remarks This callback function is mandatory and must be registered using stte_main().
283 * @param[in] type The type for recognition (e.g. #STTE_RECOGNITION_TYPE_FREE)
284 * @param[out] is_supported A variable for checking whether STT engine supports the corresponding recognition type.
285 * @c true to support recognition type,
286 * @c false not to support recognition type
287 * @return @c 0 on success,
288 * otherwise a negative error value
289 * @retval #STTE_ERROR_NONE Successful
290 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
293 typedef int (*stte_support_recognition_type_cb)(const char* type, bool* is_supported);
297 * @brief Called when the engine service user gets the proper recording format of STT engine.
299 * @remarks This callback function is mandatory and must be registered using stte_main().
300 * The recording format is used for creating the recorder.
301 * @param[out] types The format used by the recorder
302 * @param[out] rate The sample rate used by the recorder
303 * @param[out] channels The number of channels used by the recorder
304 * @return @c 0 on success,
305 * otherwise a negative error value
306 * @retval #STTE_ERROR_NONE Successful
307 * @retval #STTE_ERROR_INVALID_STATE Not initialized
309 typedef int (*stte_get_recording_format_cb)(stte_audio_type_e* types, int* rate, int* channels);
313 * @brief Called when the engine service user sets the silence detection.
315 * @remarks This callback function is mandatory and must be registered using stte_main().
316 * If the engine service user sets this option as 'TRUE', STT engine will detect the silence (EPD) and send the callback event about it.
317 * @param[in] is_set A variable for setting the silence detection.
318 * @c true to detect the silence,
319 * @c false not to detect the silence
320 * @return @c 0 on success,
321 * otherwise a negative error value
322 * @retval #STTE_ERROR_NONE Successful
323 * @retval #STTE_ERROR_INVALID_STATE Not initialized
324 * @retval #STTE_ERROR_NOT_SUPPORTED_FEATURE Not supported feature
326 typedef int (*stte_set_silence_detection_cb)(bool is_set);
330 * @brief Called when the engine service user requests for STT engine to check whether the application agreed the usage of STT engine.
331 * @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.
332 * According to the need, the engine developer can provide some user interfaces to check the agreement.
334 * @remarks This callback function is mandatory and must be registered using stte_main().
335 * 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.
336 * 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.
337 * @param[in] appid The Application ID
338 * @param[out] is_agreed A variable for checking whether the application agreed to use STT engine or not.
340 * @c false to disagree
341 * @return @c 0 on success,
342 * otherwise a negative error value
343 * @retval #STTE_ERROR_NONE Successful
344 * @retval #STTE_ERROR_INVALID_STATE Not initialized
345 * @retval #STTE_ERROR_NOT_SUPPORTED_FEATURE Not supported feature
347 typedef int (*stte_check_app_agreed_cb)(const char* appid, bool* is_agreed);
351 * @brief Called when the engine service user checks whether STT engine needs the application's credential.
353 * @remarks This callback function is mandatory and must be registered using stte_main().
354 * @return @c true if STT engine needs the application's credential,
357 typedef bool (*stte_need_app_credential_cb)(void);
361 * @brief Called when the engine service user gets the result time information(stamp).
363 * @remarks This callback function is mandatory and must be registered using stte_main().
364 * 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()'.
365 * If 'stte_result_time_cb()' returns @c false, it should be stopped to call 'stte_result_time_cb()'.
366 * @a time_info is transferred from stte_send_result(). The type of @a time_info is up to the STT engine developer.
367 * @param[in] time_info The time information
368 * @param[in] callback The callback function
369 * @param[in] user_data The user data which must be passed to the callback function 'stte_result_time_cb()'
370 * @return @c 0 on success,
371 * otherwise a negative error value
372 * @retval #STTE_ERROR_NONE Successful
373 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
374 * @retval #STTE_ERROR_INVALID_STATE Not initialized
375 * @pre stte_send_result() will invoke this function.
376 * @post This function invokes stte_result_time_cb() repeatedly for getting result time information.
377 * @see stte_result_time_cb()
379 typedef int (*stte_foreach_result_time_cb)(void* time_info, stte_result_time_cb callback, void* user_data);
383 * @brief Called when the engine service user starts to recognize the recording data.
385 * @remarks This callback function is mandatory and must be registered using stte_main().
386 * In this callback function, STT engine must transfer the recognition result and @a user_data to the engine service user using stte_send_result().
387 * Also, if STT engine needs the application's credential, it sets the credential granted to the application.
388 * @param[in] language The language is specified as an ISO 3166 alpha-2 two letter country-code
389 * followed by ISO 639-1 for the two-letter language code
390 * For example, "ko_KR" for Korean, "en_US" for American English
391 * @param[in] type The recognition type. (e.g. #STTE_RECOGNITION_TYPE_FREE)
392 * @param[in] appid The Application ID
393 * @param[in] credential The credential granted to the application
394 * @param[in] user_data The user data to be passed to the callback function
395 * @return @c 0 on success,
396 * otherwise a negative error value
397 * @retval #STTE_ERROR_NONE Successful
398 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
399 * @retval #STTE_ERROR_INVALID_STATE Invalid state
400 * @retval #STTE_ERROR_INVALID_LANGUAGE Invalid language
401 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
402 * @retval #STTE_ERROR_NETWORK_DOWN Out of network
403 * @pre The engine is not in recognition processing.
404 * @see stte_set_recording_data_cb()
405 * @see stte_stop_cb()
406 * @see stte_cancel_cb()
407 * @see stte_need_app_credential_cb()
409 typedef int (*stte_start_cb)(const char* language, const char* type, const char* appid, const char* credential, void *user_data);
413 * @brief Called when the engine service user sets and sends the recording data for speech recognition.
414 * @details This callback function is called by the engine service user to send the recording data to STT engine.
415 * The engine receives the recording data and uses for speech recognition.
417 * @remarks This callback function is mandatory and must be registered using stte_main().
418 * Also, this function should be returned immediately after recording data copy.
419 * @param[in] data The recording data
420 * @param[in] length The length of recording data
421 * @return @c 0 on success,
422 * otherwise a negative error value
423 * @retval #STTE_ERROR_NONE Successful
424 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
425 * @retval #STTE_ERROR_INVALID_STATE Invalid state
426 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
427 * @pre stte_start_cb() should succeed.
428 * @post If the engine supports partial result, stte_send_result() should be invoked.
429 * @see stte_start_cb()
430 * @see stte_cancel_cb()
431 * @see stte_stop_cb()
433 typedef int (*stte_set_recording_data_cb)(const void* data, unsigned int length);
437 * @brief Called when the engine service user stops to recognize the recording data.
438 * @details This callback function is called by the engine service user to stop recording and to get the recognition result.
440 * @remarks This callback function is mandatory and must be registered using stte_main().
441 * @return @c 0 on success,
442 * otherwise a negative error value
443 * @retval #STTE_ERROR_NONE Successful
444 * @retval #STTE_ERROR_INVALID_STATE Invalid state
445 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
446 * @retval #STTE_ERROR_NETWORK_DOWN Out of network
447 * @pre stte_start_cb() should succeed.
448 * @post After processing of the engine, stte_send_result() must be called.
449 * @see stte_start_cb()
450 * @see stte_set_recording_data_cb()
451 * @see stte_cancel_cb()
452 * @see stte_send_result()
454 typedef int (*stte_stop_cb)(void);
458 * @brief Called when the engine service user cancels to recognize the recording data.
459 * @details This callback function is called by the engine service user to cancel to recognize the recording data.
460 * Also, when starting the recorder is failed, this function is called.
462 * @remarks This callback function is mandatory and must be registered using stte_main().
463 * @return @c 0 on success,
464 * otherwise a negative error value
465 * @retval #STTE_ERROR_NONE Successful.
466 * @retval #STTE_ERROR_INVALID_STATE Invalid state.
467 * @pre STT engine is in recognition processing or recording.
468 * @see stte_start_cb()
469 * @see stte_stop_cb()
471 typedef int (*stte_cancel_cb)(void);
475 * @brief Called when the engine service user requests the basic information of STT engine.
477 * @remarks This callback function is mandatory and must be registered using stte_main().
478 * The allocated @a engine_uuid, @a engine_name, and @a engine_setting will be released internally.
479 * In order to upload the engine at Tizen Appstore, both a service app and a ui app are necessary.
480 * Therefore, @a engine_setting must be transferred to the engine service user.
481 * @param[out] engine_uuid UUID of engine
482 * @param[out] engine_name Name of engine
483 * @param[out] engine_setting The engine setting application(ui app)'s app ID
484 * @param[out] use_network A variable for checking whether the network is used or not
485 * @return @c 0 on success,
486 * otherwise a negative error code on failure
487 * @retval #STTE_ERROR_NONE Successful
488 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
489 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
491 typedef int (*stte_get_info_cb)(char** engine_uuid, char** engine_name, char** engine_setting, bool* use_network);
495 * @brief Called when STT engine receives the private data from the engine service user.
496 * @details This callback function is called when the engine service user sends the private data to STT engine.
498 * @remarks This callback function is optional and is registered using stte_set_private_data_set_cb().
499 * @param[in] key The key field of private data
500 * @param[in] data The data field of private data
501 * @return @c 0 on success,
502 * otherwise a negative error value
503 * @retval #STTE_ERROR_NONE Successful
504 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
505 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
506 * @see stte_private_data_requested_cb()
507 * @see stte_set_private_data_set_cb()
509 typedef int (*stte_private_data_set_cb)(const char* key, const char* data);
513 * @brief Called when STT engine provides the engine service user with the private data.
514 * @details This callback function is called when the engine service user gets the private data from STT engine.
516 * @remarks This callback function is optional and is registered using stte_set_private_data_requested_cb().
517 * @param[out] key The key field of private data
518 * @param[out] data The data field of private data
519 * @return @c 0 on success,
520 * otherwise a negative error value
521 * @retval #STTE_ERROR_NONE Successful
522 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
523 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
524 * @see stte_private_data_set_cb()
525 * @see stte_set_private_data_requested_cb()
527 typedef int (*stte_private_data_requested_cb)(const char* key, char** data);
531 * @brief A structure for the STT engine functions.
532 * @details This structure contains essential callback functions for operating STT engine.
534 * @remarks These functions are mandatory for operating STT engine. Therefore, all functions MUST be implemented.
537 int version; /**< The version of the structure 'stte_request_callback_s' */
538 stte_get_info_cb get_info; /**< Called when the engine service user requests the basic information of STT engine */
540 stte_initialize_cb initialize; /**< Called when the engine service user initializes STT engine */
541 stte_deinitialize_cb deinitialize; /**< Called when the engine service user deinitializes STT engine */
543 stte_foreach_supported_langs_cb foreach_langs; /**< Called when the engine service user gets the whole supported language list */
544 stte_is_valid_language_cb is_valid_lang; /**< Called when the engine service user checks whether the corresponding language is valid or not*/
545 stte_support_silence_detection_cb support_silence; /**< Called when the engine service user checks whether STT engine supports silence detection*/
546 stte_support_recognition_type_cb support_recognition_type; /**< Called when the engine service user checks whether STT engine supports the corresponding recognition type */
547 stte_get_recording_format_cb get_audio_format; /**< Called when the engine service user gets the proper recording format of STT engine */
548 stte_foreach_result_time_cb foreach_result_time; /**< Called when the engine service user gets the result time information(stamp) */
550 stte_set_silence_detection_cb set_silence_detection; /**< Called when the engine service user sets the silence detection */
552 stte_start_cb start; /**< Called when the engine service user starts to recognize the recording data */
553 stte_set_recording_data_cb set_recording; /**< Called when the engine service user sets and sends the recording data for speech recognition */
554 stte_stop_cb stop; /**< Called when the engine service user stops to recognize the recording data */
555 stte_cancel_cb cancel; /**< Called when the engine service user cancels to recognize the recording data */
557 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 */
558 stte_need_app_credential_cb need_app_credential; /**< Called when the engine service user checks whether STT engine needs the application's credential */
559 } stte_request_callback_s;
563 * @brief Main function for Speech-To-Text (STT) engine.
564 * @details This function is the main function for operating STT engine.
567 * @privilege %http://tizen.org/privilege/recorder
568 * @remarks The service_app_main() should be used for working the engine after this function.
569 * @param[in] argc The argument count(original)
570 * @param[in] argv The argument(original)
571 * @param[in] callback The structure of engine request callback function
572 * @return This function returns @c zero on success,
573 * or negative with error code on failure
574 * @retval #STTE_ERROR_NONE Successful
575 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
576 * @retval #STTE_ERROR_PERMISSION_DENIED Permission denied
577 * @retval #STTE_ERROR_NOT_SUPPORTED Not supported
578 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
579 * @see stte_request_callback_s
583 // Required callback functions - MUST BE IMPLEMENTED
584 static int sttengine_get_info_cb(char** engine_uuid, char** engine_name, char** engine_setting, bool* use_network);
585 static int sttengine_initialize_cb(void);
586 static int sttengine_deinitialize_cb(void);
587 static int sttengine_is_valid_language_cb(const char* language, bool* is_valid);
588 static int sttengine_foreach_supported_langs_cb(stte_supported_language_cb callback, void* user_data);
589 static bool sttengine_support_silence_detection_cb(void);
590 static int sttengine_set_silence_detection_cb(bool is_set);
591 static int sttengine_support_recognition_type_cb(const char* type, bool* is_supported);
592 static int sttengine_get_recording_format_cb(stte_audio_type_e* types, int* rate, int* channels);
593 static int sttengine_set_recording_data_cb(const void* data, unsigned int length);
594 static int sttengine_foreach_result_time_cb(void* time_info, stte_result_time_cb callback, void* user_data);
595 static int sttengine_start_cb(const char* language, const char* type, const char* appid, const char* credential, void *user_data);
596 static int sttengine_stop_cb(void);
597 static int sttengine_cancel_cb(void);
598 static int sttengine_check_app_agreed_cb(const char* appid, bool* is_agreed);
599 static bool sttengine_need_app_credential_cb(void);
601 // Optional callback function
602 static int sttengine_private_data_set_cb(const char* key, const char* data);
604 int main(int argc, char* argv[])
606 // 1. Create a structure 'stte_request_callback_s'
607 stte_request_callback_s engine_callback = { 0, };
609 engine_callback.size = sizeof(stte_request_callback_s);
610 engine_callback.version = 1;
611 engine_callback.get_info = sttengine_get_info_cb;
613 engine_callback.initialize = sttengine_initialize_cb;
614 engine_callback.deinitialize = sttengine_deinitialize_cb;
616 engine_callback.foreach_langs = sttengine_foreach_supported_langs_cb;
617 engine_callback.is_valid_lang = sttengine_is_valid_language_cb;
618 engine_callback.support_silence = sttengine_support_silence_detection_cb;
619 engine_callback.support_recognition_type = sttengine_support_recognition_type_cb;
621 engine_callback.get_audio_format = sttengine_get_recording_format_cb;
622 engine_callback.foreach_result_time = sttengine_foreach_result_time_cb;
624 engine_callback.set_silence_detection = sttengine_set_silence_detection_cb;
626 engine_callback.start = sttengine_start_cb;
627 engine_callback.set_recording = sttengine_set_recording_data_cb;
628 engine_callback.stop = sttengine_stop_cb;
629 engine_callback.cancel = sttengine_cancel_cb;
631 engine_callback.check_app_agreed = sttengine_check_app_agreed_cb;
632 engine_callback.need_app_credential = sttengine_need_app_credential_cb;
634 // 2. Run 'stte_main()'
635 if (0 != stte_main(argc, argv, &engine_callback)) {
640 stte_set_private_data_set_cb(sttengine_private_data_set_cb);
642 // 3. Set event callbacks for service app and Run 'service_app_main()'
643 char ad[50] = { 0, };
645 service_app_lifecycle_callback_s event_callback;
646 app_event_handler_h handlers[5] = { NULL, };
648 event_callback.create = service_app_create;
649 event_callback.terminate = service_app_terminate;
650 event_callback.app_control = service_app_control;
652 service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad);
653 service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad);
654 service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad);
655 service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad);
657 return service_app_main(argc, argv, &event_callback, ad);
662 int stte_main(int argc, char** argv, stte_request_callback_s *callback);
666 * @brief Sends the recognition result to the engine service user.
668 * @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.
669 * 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.
670 * The recognition result and @a user_data must be transferred to the engine service user through this function.
671 * 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.
672 * @param[in] event The result event
673 * @param[in] type The recognition type (e.g. #STTE_RECOGNITION_TYPE_FREE, #STTE_RECOGNITION_TYPE_FREE_PARTIAL)
674 * @param[in] result Result texts
675 * @param[in] result_count Result text count
676 * @param[in] msg Engine message (e.g. #STTE_RESULT_MESSAGE_NONE, #STTE_RESULT_MESSAGE_ERROR_TOO_SHORT)
677 * @param[in] time_info The time information
678 * @param[in] user_data The user data passed from stte_start_cb()
679 * @return @c 0 on success,
680 * otherwise a negative error value
681 * @retval #STTE_ERROR_NONE Successful
682 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
683 * @retval #STTE_ERROR_PERMISSION_DENIED Permission denied
684 * @retval #STTE_ERROR_NOT_SUPPORTED Not supported
685 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
686 * @pre The stte_main() function should be invoked before this function is called.
687 * stte_stop_cb() will invoke this function.
688 * @post This function invokes stte_foreach_result_time_cb().
689 * @see stte_start_cb()
690 * @see stte_set_recording_data_cb()
691 * @see stte_stop_cb()
692 * @see stte_foreach_result_time_cb()
694 int stte_send_result(stte_result_event_e event, const char* type, const char** result, int result_count,
695 const char* msg, void* time_info, void* user_data);
699 * @brief Sends the error to the engine service user.
700 * @details The following error codes can be delivered.
702 * #STTE_ERROR_OUT_OF_MEMORY,
703 * #STTE_ERROR_IO_ERROR,
704 * #STTE_ERROR_INVALID_PARAMETER,
705 * #STTE_ERROR_NETWORK_DOWN,
706 * #STTE_ERROR_INVALID_STATE,
707 * #STTE_ERROR_INVALID_LANGUAGE,
708 * #STTE_ERROR_OPERATION_FAILED,
709 * #STTE_ERROR_NOT_SUPPORTED_FEATURE,
710 * #STTE_ERROR_NOT_SUPPORTED,
711 * #STTE_ERROR_PERMISSION_DENIED,
712 * #STTE_ERROR_RECORDING_TIMED_OUT.
714 * @param[in] error The error reason
715 * @param[in] msg The error message
716 * @return @c 0 on success,
717 * otherwise a negative error value
718 * @retval #STTE_ERROR_NONE Successful
719 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
720 * @retval #STTE_ERROR_PERMISSION_DENIED Permission denied
721 * @retval #STTE_ERROR_NOT_SUPPORTED Not supported
722 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
723 * @pre The stte_main() function should be invoked before this function is called.
725 int stte_send_error(stte_error_e error, const char* msg);
729 * @brief Sends the speech status to the engine service user when STT engine notifies the change of the speech status.
731 * @remarks This API is invoked when STT engine wants to notify the change of the speech status anytime.
732 * NOTE that this API can be invoked for recognizing the speech.
733 * @param[in] status The status of speech (e.g. STTE_SPEECH_STATUS_START_POINT_DETECTED or STTE_SPEECH_STATUS_END_POINT_DETECTED)
734 * @param[in] user_data The user data passed from the start function.
735 * @return @c 0 on success,
736 * otherwise a negative error value
737 * @retval #STTE_ERROR_NONE Successful
738 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
739 * @retval #STTE_ERROR_PERMISSION_DENIED Permission denied
740 * @retval #STTE_ERROR_NOT_SUPPORTED Not supported
741 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
742 * @pre The stte_main() function should be invoked before this function is called.
743 * stte_start_cb() and stte_set_recording_data_cb() will invoke this function.
744 * @see stte_start_cb()
745 * @see stte_set_recording_data_cb()
747 int stte_send_speech_status(stte_speech_status_e status, void* user_data);
751 * @brief Sets a callback function for setting the private data.
754 * @privilege %http://tizen.org/privilege/recorder
755 * @remarks The stte_private_data_set_cb() function is called when the engine service user sends the private data.
756 * @param[in] callback_func stte_private_data_set event callback function
757 * @return @c 0 on success,
758 * otherwise a negative error value
759 * @retval #STTE_ERROR_NONE Successful
760 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
761 * @retval #STTE_ERROR_PERMISSION_DENIED Permission denied
762 * @retval #STTE_ERROR_NOT_SUPPORTED Not supported
763 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
764 * @pre The stte_main() function should be invoked before this function is called.
765 * @see stte_private_data_set_cb()
767 int stte_set_private_data_set_cb(stte_private_data_set_cb callback_func);
771 * @brief Sets a callback function for requesting the private data.
774 * @privilege %http://tizen.org/privilege/recorder
775 * @remarks The stte_private_data_requested_cb() function is called when the engine service user gets the private data from STT engine.
776 * @param[in] callback_func stte_private_data_requested event callback function
777 * @return @c 0 on success,
778 * otherwise a negative error value
779 * @retval #STTE_ERROR_NONE Successful
780 * @retval #STTE_ERROR_INVALID_PARAMETER Invalid parameter
781 * @retval #STTE_ERROR_PERMISSION_DENIED Permission denied
782 * @retval #STTE_ERROR_NOT_SUPPORTED Not supported
783 * @retval #STTE_ERROR_OPERATION_FAILED Operation failure
784 * @pre The stte_main() function should be invoked before this function is called.
785 * @see stte_private_data_requested_cb()
787 int stte_set_private_data_requested_cb(stte_private_data_requested_cb callback_func);
800 #endif /* __STT_ENGINE_MAIN_H__ */