2 * Copyright (c) 2011-2017 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 * @addtogroup CAPI_UIX_VCE_MODULE
33 * @brief Enumerations of error codes.
37 VCE_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
38 VCE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of Memory */
39 VCE_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
40 VCE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,/**< Invalid parameter */
41 VCE_ERROR_OUT_OF_NETWORK = TIZEN_ERROR_NETWORK_DOWN, /**< Out of network */
42 VCE_ERROR_INVALID_STATE = TIZEN_ERROR_VOICE_CONTROL | 0x011, /**< Invalid state */
43 VCE_ERROR_INVALID_LANGUAGE = TIZEN_ERROR_VOICE_CONTROL | 0x012, /**< Invalid language */
44 VCE_ERROR_OPERATION_FAILED = TIZEN_ERROR_VOICE_CONTROL | 0x014, /**< Operation failed */
45 VCE_ERROR_NOT_SUPPORTED_FEATURE = TIZEN_ERROR_VOICE_CONTROL | 0x022 /**< Not supported feature of current engine */
49 * @brief Enumerations of audio type.
53 VCE_AUDIO_TYPE_PCM_S16_LE = 0, /**< Signed 16bit audio type, Little endian */
54 VCE_AUDIO_TYPE_PCM_U8 /**< Unsigned 8bit audio type */
58 * @brief Enumerations of callback event.
62 VCE_RESULT_EVENT_SUCCESS = 0, /**< Event when the recognition full result is ready */
63 VCE_RESULT_EVENT_REJECTED, /**< Event when the recognition result is rejected */
64 VCE_RESULT_EVENT_ERROR /**< Event when the recognition has failed */
68 * @brief Enumerations of command type.
72 VCE_COMMAND_FORMAT_FIXED = 0, /**< Fixed command */
73 VCE_COMMAND_FORMAT_FIXED_AND_VFIXED, /**< Fixed command + variable-fixed command */
74 VCE_COMMAND_FORMAT_VFIXED_AND_FIXED, /**< variable-fixed command + Fixed command */
75 VCE_COMMAND_FORMAT_FIXED_AND_NONFIXED, /**< Fixed command + Non-fixed command */
76 VCE_COMMAND_FORMAT_NONFIXED_AND_FIXED, /**< Non-fixed command + Fixed command */
77 VCE_COMMAND_FORMAT_ACTION,
78 VCE_COMMAND_FORMAT_PARTIAL
79 } vce_command_format_e;
82 * @brief Definition for foreground command type.
85 #define VCE_COMMAND_TYPE_FOREGROUND 1
88 * @brief Definition for background command type.
91 #define VCE_COMMAND_TYPE_BACKGROUND 2
94 * @brief Definition for widget command type.
97 #define VCE_COMMAND_TYPE_WIDGET 3
100 * @brief Definition for system command type.
103 #define VCE_COMMAND_TYPE_SYSTEM 4
106 * @brief Definition for system background command type.
109 #define VCE_COMMAND_TYPE_SYSTEM_BACKGROUND 5
112 * @brief Definitions for exclusive command type.
115 #define VCE_COMMAND_TYPE_EXCLUSIVE 6
119 * @brief Enumerations of speech detect.
123 VCE_SPEECH_DETECT_NONE = 0, /**< No event */
124 VCE_SPEECH_DETECT_BEGIN, /**< Begin of speech detected */
125 VCE_SPEECH_DETECT_END, /**< End of speech detected */
126 } vce_speech_detect_e;
129 * @brief Enumerations of ASR result events
133 VCE_ASR_RESULT_EVENT_FINAL_RESULT = 0,
134 VCE_ASR_RESULT_EVENT_PARTIAL_RESULT,
135 VCE_ASR_RESULT_EVENT_ERROR
136 } vce_asr_result_event_e;
139 * @brief A structure of handle for VC command
142 typedef int vce_cmd_h;
145 * @brief Definition of bluetooth audio id.
148 #define VCE_AUDIO_ID_BLUETOOTH "VC_AUDIO_ID_BLUETOOTH" /**< Bluetooth audio id */
151 * @brief Definition of Wi-Fi audio id.
154 #define VCE_AUDIO_ID_WIFI "VC_AUDIO_ID_WIFI" /**< Wi-Fi audio id */
157 * @brief Definition for none message.
159 #define VC_RESULT_MESSAGE_NONE "vc.result.message.none"
162 * @brief Definition for failed recognition because the speech is too loud to listen.
164 #define VC_RESULT_MESSAGE_ERROR_TOO_LOUD "vc.result.message.error.too.loud"
169 * @brief Called when VC engine informs the engine service user about whole supported languages.
170 * @details This callback function is implemented by the engine service user. Therefore, the engine developer does NOT have to implement this callback function.
172 * @remarks This callback function is called by vce_foreach_supported_languages_cb() to retrieve the whole supported language list.
173 * @a user_data must be transferred from vce_foreach_supported_languages_cb().
175 * @param[in] language A language is specified as an ISO 3166 alpha-2 two letter country-code
176 * followed by ISO 639-1 for the two-letter language code \n
177 * For example, "ko_KR" for Korean, "en_US" for American English
178 * @param[in] user_data The user data passed from the foreach function
180 * @return @c true to continue with the next iteration of the loop \n @c false to break out of the loop
182 * @pre vce_foreach_supported_languages() will invoke this callback.
184 * @see vce_foreach_supported_languages()
186 typedef bool (*vce_supported_language_cb)(const char* language, void* user_data);
189 * @brief Called when the engine service user initializes VC engine.
191 * @remarks This callback function is mandatory and must be registered using vce_main().
193 * @return 0 on success, otherwise a negative error value
194 * @retval #VCE_ERROR_NONE Successful
195 * @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter
196 * @retval #VCE_ERROR_INVALID_STATE Already initialized
197 * @retval #VCE_ERROR_OPERATION_FAILED Operation failed
199 * @see vce_deinitialize_cb()
201 typedef int (*vce_initialize_cb)(void);
204 * @brief Called when the engine service user deinitializes VC engine
206 * @remarks This callback function is mandatory and must be registered using vce_main().
208 * @return 0 on success, otherwise a negative error value
209 * @retval #VCE_ERROR_NONE Successful
210 * @retval #VCE_ERROR_INVALID_STATE Not initialized
212 * @see vce_initialize_cb()
214 typedef int (*vce_deinitialize_cb)(void);
217 * @brief Called when the engine service user requests the recording format of VC engine.
219 * @param[in] audio_id The audio device id.
220 * @param[out] types The format used by the recorder.
221 * @param[out] rate The sample rate used by the recorder.
222 * @param[out] channels The number of channels used by the recorder.
224 * @return 0 on success, otherwise a negative error value
225 * @retval #VCE_ERROR_NONE Successful
226 * @retval #VCE_ERROR_INVALID_PARAMETER Not initialized
228 typedef int (*vce_get_recording_format_cb)(const char* audio_id, vce_audio_type_e* types, int* rate, int* channels);
231 * @brief Called when the engine service user retrieves all supported languages of VC engine.
233 * @param[in] callback a callback function
234 * @param[in] user_data The user data to be passed to the callback function
236 * @return 0 on success, otherwise a negative error value
237 * @retval #VCE_ERROR_NONE Successful
238 * @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter
239 * @retval #VCE_ERROR_INVALID_STATE Not initialized
241 * @post This function invokes vce_supported_language_cb() repeatedly for getting supported languages.
243 * @see vce_supported_language_cb()
245 typedef int (*vce_foreach_supported_languages_cb)(vce_supported_language_cb callback, void* user_data);
248 * @brief Called when the engine service user checks whether a language is supported or not.
250 * @param[in] language A language
252 * @return @c true = supported, \n @c false = not supported.
254 typedef bool (*vce_is_language_supported_cb)(const char* language);
257 * @brief Called when the engine service user sets language.
259 * @param[in] language A language.
261 * @return 0 on success, otherwise a negative error value
262 * @retval #VCE_ERROR_NONE Successful
263 * @retval #VCE_ERROR_INVALID_LANGUAGE Invalid language
264 * @retval #VCE_ERROR_INVALID_STATE Not initialized
266 typedef int (*vce_set_language_cb)(const char* language);
269 * @brief Called when the engine service user sets command list before recognition.
271 * @remark This function should set commands via vcd_foreach_command().
273 * @param[in] vc_command command handle.
275 * @return 0 on success, otherwise a negative error value
276 * @retval #VCE_ERROR_NONE Successful
277 * @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter
278 * @retval #VCE_ERROR_INVALID_STATE Invalid state
279 * @retval #VCE_ERROR_OPERATION_FAILED Operation failed
280 * @retval #VCE_ERROR_NOT_SUPPORTED_FEATURE Not supported command type
282 * @post vce_start() is called after this function is successful.
285 * @see vcd_foreach_command()
286 * @see vce_unset_commands()
288 typedef int (*vce_set_commands_cb)(vce_cmd_h vc_command);
291 * @brief Called when the engine service user unsets command list for reset.
293 * @return 0 on success, otherwise a negative error value
294 * @retval #VCE_ERROR_NONE Successful
295 * @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter
296 * @retval #VCE_ERROR_INVALID_STATE Invalid state
297 * @retval #VCE_ERROR_OPERATION_FAILED Operation failed
299 * @see vce_set_commands()
301 typedef int (*vce_unset_commands_cb)();
304 * @brief Called when the engine service user starts recognition.
306 * @return 0 on success, otherwise a negative error value
307 * @retval #VCE_ERROR_NONE Successful
308 * @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter
309 * @retval #VCE_ERROR_INVALID_STATE Invalid state
310 * @retval #VCE_ERROR_INVALID_LANGUAGE Invalid language
311 * @retval #VCE_ERROR_OUT_OF_NETWORK Out of network
312 * @retval #VCE_ERROR_OPERATION_FAILED Operation failed
314 * @pre vcd_foreach_command() is successful.
316 * @see vce_set_recording_data()
320 typedef int (*vce_start_cb)(bool stop_by_silence);
323 * @brief Called when the engine service user sets recording data for speech recognition from recorder.
325 * @remark This function should be returned immediately after recording data copy.
327 * @param[in] data A recording data
328 * @param[in] length A length of recording data
329 * @param[out] silence_detected @c true Silence detected \n @c false No silence detected
331 * @return 0 on success, otherwise a negative error value
332 * @retval #VCE_ERROR_NONE Successful
333 * @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter
334 * @retval #VCE_ERROR_INVALID_STATE Invalid state
335 * @retval #VCE_ERROR_OPERATION_FAILED Operation failed
337 * @pre vce_start() is successful.
343 typedef int(*vce_set_recording_data_cb)(const void* data, unsigned int length, vce_speech_detect_e* speech_detected);
346 * @brief Called when the engine service user stops to get the result of recognition.
348 * @return 0 on success, otherwise a negative error value
349 * @retval #VCE_ERROR_NONE Successful
350 * @retval #VCE_ERROR_INVALID_STATE Invalid state
351 * @retval #VCE_ERROR_OPERATION_FAILED Operation failed
352 * @retval #VCE_ERROR_OUT_OF_NETWORK Out of network
354 * @pre vce_set_recording_data() is successful.
357 * @see vce_set_recording_data()
358 * @see vce_result_cb()
361 typedef int (*vce_stop_cb)(void);
364 * @brief Called when the engine service user cancels the recognition process.
366 * @return 0 on success, otherwise a negative error value.
367 * @retval #VCE_ERROR_NONE Successful.
368 * @retval #VCE_ERROR_INVALID_STATE Invalid state.
370 * @pre vce_start() is successful.
375 typedef int (*vce_cancel_cb)(void);
378 * @brief Set audio recording type.
380 * @return 0 on success, otherwise a negative error value.
381 * @retval #VCE_ERROR_NONE Successful.
384 typedef int (*vce_set_audio_type)(const char* audio);
388 * @brief Called when the engine service user sets domain (Agent or device type)
390 * @param[in] domain Available agent or device type
392 * @return 0 on success, otherwise a negative error value.
395 typedef int (*vce_set_domain_cb)(const char* domain);
398 * @brief Called when the engine service user requests essential value from nlu result.
400 * @remarks This function is available inside vce_nlu_result_cb()
402 * @param[in] key NLU base info key
403 * @parma[out] value NLU base info value
405 * @return 0 on success, otherwise a negative error value.
408 typedef int (*vce_nlu_base_info_requested_cb)(const char* key, char** value);
411 * @brief Called when the engine service user sets private data between app and engine.
413 * @param[in] key Private key
414 * @param[in] data Private data
416 * @return 0 on success, otherwise a negative error value.
419 typedef int (*vce_private_data_set_cb)(const char* key, const char* data);
422 * @brief Called when the engine service user requests private data between app and engine.
424 * @param[in] key Private key
425 * @param[out] data Private data
427 * @return 0 on success, otherwise a negative error value.
430 typedef int (*vce_private_data_requested_cb)(const char* key, char** data);
433 * @brief Called when the engine service user requests process text.
435 * @param[in] text Requested text
437 * @return 0 on success, otherwise a negative error value.
440 typedef int (*vce_process_text_cb)(const char* text);
443 * @brief Called when the engine service user requests list event.
445 * @param[in] event Requested list event
447 * @return 0 on success, otherwise a negative error value.
450 typedef int (*vce_process_list_event_cb)(const char* event);
453 * @brief Called when the engine service user requests haptic event.
455 * @param[in] event Requested haptic event
457 * @return 0 on success, otherwise a negative error value.
460 typedef int (*vce_process_haptic_event_cb)(const char* event);
463 * @brief Called when the engine service user requests the base information of VC engine.
466 * @param[out] engine_uuid The engine id
467 * @param[out] engine_name The engine name
468 * @param[out] engine_setting The setting path name
469 * @param[out] use_network @c true to need network @c false not to need network.
471 typedef int (*vce_get_info_cb)(char** engine_uuid, char** engine_name, char** engine_setting, bool* use_network);
479 * @brief Called to retrieve the commands.
481 * @param[in] id command id
482 * @param[in] type command type
483 * @param[in] format command format
484 * @param[in] command command text
485 * @param[in] param parameter text
486 * @param[in] domain command domain
487 * @param[in] user_data The user data passed from the foreach function
489 * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop.
490 * @pre vce_get_foreach_command() will invoke this callback.
492 * @see vce_get_foreach_command()
494 typedef bool (*vce_command_cb)(int id, int type, int format, const char* command, const char* param, int domain, void* user_data);
497 * @brief Retrieves all commands using callback function.
499 * @param[in] vce_command The handle to be passed to the vce_set_commands() function
500 * @param[in] callback The callback function to invoke
501 * @param[in] user_data The user data to be passed to the callback function
503 * @return 0 on success, otherwise a negative error value
504 * @retval #VCE_ERROR_NONE Successful
505 * @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter
506 * @retval #VCE_ERROR_OPERATION_FAILED Operation failure
507 * @retval #VCE_ERROR_INVALID_STATE Invalid state
509 * @post This function invokes vce_command_cb() repeatedly for getting commands.
511 * @see vce_foreach_command_cb()
512 * @see vce_set_commands()
514 int vce_get_foreach_command(vce_cmd_h vce_command, vce_command_cb callback, void* user_data);
517 * @brief Gets command length.
519 * @param[in] vce_command The handle to be passed to the vce_set_commands() function
521 * @return the value greater than 0 on success, otherwise a negative error value
523 * @see vce_set_commands()
525 int vce_get_command_count(vce_cmd_h vce_command);
528 * @brief Gets current audio type.
530 * @remarks audio_type must be released using free() when it is no longer required.
532 * @param[in] audio_type Current audio type (e.g. #VCE_AUDIO_ID_BLUETOOTH or usb device id)
534 * @return the value greater than 0 on success, otherwise a negative error value
537 int vce_get_audio_type(char** audio_type);
540 * @brief Sets private data to Manager client.
542 * @param[in] key Private key
543 * @param[in] data Private data
545 * @return 0 on success, otherwise a negative error value.
548 int vce_set_private_data(const char* key, const char* data);
551 * @brief Gets private data from Manager client.
553 * @param[in] key Private key
554 * @param[out] data Private data
556 * @return 0 on success, otherwise a negative error value.
559 int vce_get_private_data(const char* key, char** data);
562 * @brief Request start recording.
564 * @return 0 on success, otherwise a negative error value.
567 int vce_start_recording();
570 * @brief Request stop recording.
572 * @return 0 on success, otherwise a negative error value.
575 int vce_stop_recording();
579 * @brief A structure for the VC engine functions.
580 * @details This structure contains essential callback functions for operating VC engine.
582 * @remarks These functions ar mandatory for operating VC engine. Therefore, all functions MUST be implemented.
585 int version; /**< Version */
587 /* Get engine information */
588 vce_get_info_cb get_info; /**< Called when the engine service user requests the basic information of VC engine */
589 vce_get_recording_format_cb get_recording_format; /**< Get recording format */
590 vce_foreach_supported_languages_cb foreach_langs; /**< Foreach language list */
591 vce_is_language_supported_cb is_lang_supported; /**< Check language */
593 vce_initialize_cb initialize; /**< Initialize engine */
594 vce_deinitialize_cb deinitialize; /**< Shutdown engine */
597 vce_set_language_cb set_language; /**< Set language */
598 vce_set_commands_cb set_commands; /**< Request to set current commands */
599 vce_unset_commands_cb unset_commands; /**< Request to unset current commands */
601 /* Control recognition */
602 vce_start_cb start; /**< Start recognition */
603 vce_set_recording_data_cb set_recording; /**< Set recording data */
604 vce_stop_cb stop; /**< Stop recording for getting result */
605 vce_cancel_cb cancel; /**< Cancel recording and processing */
607 vce_set_audio_type set_audio_type; /**< Set audio type */
609 vce_set_domain_cb set_domain; /**< Set domain */
610 vce_process_text_cb process_text; /**< Request to process text */
611 vce_process_list_event_cb process_list_event; /**< Request to process list event */
612 vce_process_haptic_event_cb process_haptic_event; /**< Request to process haptic event */
613 } vce_request_callback_s;
616 * @brief Loads the engine.
618 * @param[in] argc The argument count(original)
619 * @param[in] argv The argument(original)
620 * @param[in] callback The structure of engine request callback function
622 * @return This function returns zero on success, or negative with error code on failure
623 * @retval #VCE_ERROR_NONE Successful
624 * @retval #VCE_ERROR_INVALID_PARAMETER Invalid parameter
625 * @retval #VCE_ERROR_OPERATION_FAILED Operation failed
627 * @pre The vce_get_engine_info() should be successful.
628 * @post The daemon calls engine functions of vce_funcs_s.
630 * @see vce_get_engine_info()
631 * @see vce_unload_engine()
633 int vce_main(int argc, char** argv, vce_request_callback_s *callback);
637 * @brief Sends the results to the engine service user.
640 * @param[in] event A result event
641 * @param[in] result_id Result ids
642 * @param[in] count Result count
643 * @param[in] all_result All result text
644 * @param[in] non_fixed_result Non-fixed command result text
645 * @param[in] nlu_result NLU result text
646 * @param[in] msg Engine message (e.g. #VC_RESULT_MESSAGE_NONE, #VC_RESULT_MESSAGE_ERROR_TOO_LOUD)
647 * @param[out] user_info A user info (e.g. If ASR result is consumed, the value is 0x01. If not, the value is 0x00.)
648 * @param[in] user_data The user data passed from set callback function
650 * @pre The vce_main() function should be invoked before this function is called.
651 * vce_stop_cb() will invoke this callback.
655 int vce_send_result(vce_result_event_e event, int* result_id, int count, const char* all_result, const char* non_fixed_result, const char* nlu_result, const char* msg, int* user_info, void *user_data);
658 * @brief Sends the ASR result to the engine service user.
661 * @param[in] event A asr result event
662 * @param[in] asr_result A asr result text
663 * @param[in] user_data The user data passed from the start
665 * @pre The vce_main() function should be invoked before this function is called.
667 int vce_send_asr_result(vce_asr_result_event_e event, const char* asr_result, void *user_data);
670 * @brief Called when the daemon gets nlg(natural language generation) result.
672 * @param[in] nlg_result A nlg result
673 * @param[in] user_data The user data passed from the start
675 int vce_send_nlg_result(const char* nlg_result, void *user_data);
678 * @brief Sends the error to the engine service user.
679 * @details The following error codes can be delivered.
681 * #VCE_ERROR_OUT_OF_MEMORY,
682 * #VCE_ERROR_IO_ERROR,
683 * #VCE_ERROR_INVALID_PARAMETER,
684 * #VCE_ERROR_OUT_OF_NETWORK,
685 * #VCE_ERROR_INVALID_STATE,
686 * #VCE_ERROR_INVALID_LANGUAGE,
687 * #VCE_ERROR_OPERATION_FAILED,
688 * #VCE_ERROR_NOT_SUPPORTED_FEATURE.
691 * @param[in] error Error type
692 * @param[in] msg Error message
693 * @param[in] user_data The user data passed from set callback function
695 * @pre The vce_main() function should be invoked before this function is called.
697 int vce_send_error(vce_error_e error, const char* msg, void *user_data);
700 * @brief Sets a callback function for setting the private data to the engine service.
702 * @remarks The vce_private_data_set_cb() function is called when the engine service user sets the private data to the engine service.
704 * @param[in] callback_func vce_private_data_set event callback function
707 * @see vce_private_data_set_cb()
709 int vce_set_private_data_set_cb(vce_private_data_set_cb callback_func);
712 * @brief Sets a callback function for requesting the private data to the engine service.
714 * @remarks The vce_private_data_requested_cb() function is called when the engine service user requests the private data to the engine service.
716 * @param[in] callback_func vce_private_data_requested event callback function
719 * @see vce_private_data_requested_cb()
721 int vce_set_private_data_requested_cb(vce_private_data_requested_cb callback_func);
724 * @brief Sets a callback function for requesting the NLU base information to the engine service.
726 * @remarks The vce_nlu_base_info_requested_cb() function is called when the engine service user requests the NLU base information to the engine service.
728 * @param[in] callback_func vce_nlu_base_info_requested event callback function
731 * @see vce_nlu_base_info_requested_cb()
733 int vce_set_nlu_base_info_requested_cb(vce_nlu_base_info_requested_cb callback_func);
744 #endif /* __VCE_H__ */