2 * Copyright (c) 2011-2015 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.
18 #ifndef __VOICE_CONTROL_PLUGIN_ENGINE_H__
19 #define __VOICE_CONTROL_PLUGIN_ENGINE_H__
24 * @addtogroup VOICE_CONTROL_PLUGIN_ENGINE
33 * @brief Enumerations of error codes.
36 VCP_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
37 VCP_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of Memory */
38 VCP_ERROR_IO_ERROR = TIZEN_ERROR_IO_ERROR, /**< I/O error */
39 VCP_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,/**< Invalid parameter */
40 VCP_ERROR_OUT_OF_NETWORK = TIZEN_ERROR_NETWORK_DOWN, /**< Out of network */
41 VCP_ERROR_INVALID_STATE = -0x0100031, /**< Invalid state */
42 VCP_ERROR_INVALID_LANGUAGE = -0x0100032, /**< Invalid language */
43 VCP_ERROR_OPERATION_FAILED = -0x0100034, /**< Operation failed */
44 VCP_ERROR_NOT_SUPPORTED_FEATURE = -0x0100035 /**< Not supported feature */
48 * @brief Enumerations of audio type.
51 VCP_AUDIO_TYPE_PCM_S16_LE = 0, /**< Signed 16bit audio type, Little endian */
52 VCP_AUDIO_TYPE_PCM_U8 /**< Unsigned 8bit audio type */
56 * @brief Enumerations of callback event.
59 VCP_RESULT_EVENT_SUCCESS = 0, /**< Event when the recognition full result is ready */
60 VCP_RESULT_EVENT_REJECTED, /**< Event when the recognition result is rejected */
61 VCP_RESULT_EVENT_ERROR /**< Event when the recognition has failed */
65 * @brief Enumerations of command type.
68 VCP_COMMAND_FORMAT_FIXED = 0, /**< Fixed command */
69 VCP_COMMAND_FORMAT_FIXED_AND_VFIXED, /**< Fixed command + variable-fixed command */
70 VCP_COMMAND_FORMAT_VFIXED_AND_FIXED, /**< variable-fixed command + Fixed command */
71 VCP_COMMAND_FORMAT_FIXED_AND_NONFIXED, /**< Fixed command + Non-fixed command */
72 VCP_COMMAND_FORMAT_NONFIXED_AND_FIXED, /**< Non-fixed command + Fixed command */
73 VCP_COMMAND_FORMAT_ACTION,
74 VCP_COMMAND_FORMAT_PARTIAL
75 } vcp_command_format_e;
78 * @brief Definition for foreground command type.
79 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
81 #define VCP_COMMAND_TYPE_FOREGROUND 1
84 * @brief Definition for background command type.
85 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
87 #define VCP_COMMAND_TYPE_BACKGROUND 2
90 * @brief Definition for widget command type.
91 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
93 #define VCP_COMMAND_TYPE_WIDGET 3
96 * @brief Definition for system command type.
97 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
99 #define VCP_COMMAND_TYPE_SYSTEM 4
102 * @brief Definition for exclusive command type.
103 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
105 #define VCP_COMMAND_TYPE_SYSTEM_BACKGROUND 5
108 * @brief Definitions for exclusive command type.
111 #define VCP_COMMAND_TYPE_EXCLUSIVE 6
115 * @brief Enumerations of speech detect.
118 VCP_SPEECH_DETECT_NONE = 0, /**< No event */
119 VCP_SPEECH_DETECT_BEGIN, /**< Begin of speech detected */
120 VCP_SPEECH_DETECT_END, /**< End of speech detected */
121 } vcp_speech_detect_e;
124 VCP_ASR_RESULT_EVENT_FINAL_RESULT = 0,
125 VCP_ASR_RESULT_EVENT_PARTIAL_RESULT,
126 VCP_ASR_RESULT_EVENT_ERROR
127 } vcp_asr_result_event_e;
130 * @brief A structure of handle for VC command
132 typedef int vcp_cmd_h;
135 * @brief Definition of bluetooth audio id.
137 #define VCP_AUDIO_ID_BLUETOOTH "VC_AUDIO_ID_BLUETOOTH" /**< Bluetooth audio id */
140 * @brief Definition of MSF(wifi) audio id.
142 #define VCP_AUDIO_ID_MSF "VC_AUDIO_ID_MSF" /**< MSF (wifi) audio id */
145 * @brief Definition for none message.
147 #define VC_RESULT_MESSAGE_NONE "vc.result.message.none"
150 * @brief Definition for failed recognition because the speech is too loud to listen.
152 #define VC_RESULT_MESSAGE_ERROR_TOO_LOUD "vc.result.message.error.too.loud"
156 * @brief Called when the daemon gets synthesized result.
158 * @param[in] event A result event
159 * @param[in] result_id Result ids
160 * @param[in] count Result count
161 * @param[in] all_result All result text
162 * @param[in] non_fixed_result Non-fixed command result text
163 * @param[in] nlu_result NLU result text
164 * @param[in] msg Engine message (e.g. #VC_RESULT_MESSAGE_NONE, #VC_RESULT_MESSAGE_ERROR_TOO_LOUD)
165 * @param[in] user_data The user data passed from set callback function
167 * @pre vcpe_stop() will invoke this callback.
171 typedef void (*vcpe_result_cb)(vcp_result_event_e event, int* result_id, int count,
172 const char* all_result, const char* non_fixed_result, const char* nlu_result, const char* msg, void *user_data);
176 * @brief Called when the daemon gets ASR result.
178 * @param[in] event A asr result event
179 * @param[in] pre_result result text
180 * @param[in] user_data The user data passed from the start
182 typedef void (*vcpe_asr_result_cb)(vcp_asr_result_event_e event, const char* asr_result, void *user_data);
185 * @brief Called when the daemon gets error.
187 * @param[in] error Error type
188 * @param[in] msg Error message
189 * @param[in] user_data The user data passed from set callback function
192 typedef void (*vcpe_error_cb)(vcp_error_e error, const char* msg, void *user_data);
195 * @brief Called to retrieve the supported languages.
197 * @param[in] language A language is specified as an ISO 3166 alpha-2 two letter country-code
198 * followed by ISO 639-1 for the two-letter language code \n
199 * For example, "ko_KR" for Korean, "en_US" for American English
200 * @param[in] user_data The user data passed from the foreach function
202 * @return @c true to continue with the next iteration of the loop \n @c false to break out of the loop
204 * @pre vcpe_foreach_supported_languages() will invoke this callback.
206 * @see vcpe_foreach_supported_languages()
208 typedef bool (*vcpe_supported_language_cb)(const char* language, void* user_data);
211 * @brief Initializes the engine.
213 * @param[in] result_cb A callback function for recognition result
214 * @param[in] silence_cb A callback function for silence detection
216 * @return 0 on success, otherwise a negative error value
217 * @retval #VCP_ERROR_NONE Successful
218 * @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter
219 * @retval #VCP_ERROR_INVALID_STATE Already initialized
220 * @retval #VCP_ERROR_OPERATION_FAILED Operation failed
222 * @see vcpe_deinitialize()
224 typedef int (*vcpe_initialize)(void);
227 * @brief Deinitializes the engine
229 * @return 0 on success, otherwise a negative error value
230 * @retval #VCP_ERROR_NONE Successful
231 * @retval #VCP_ERROR_INVALID_STATE Not initialized
233 * @see vcpe_initialize()
235 typedef void (*vcpe_deinitialize)(void);
238 * @brief Registers a callback function for getting recognition result.
240 * @param[in] callback Callback function to register
241 * @param[in] user_data The user data to be passed to the callback function
243 * @return 0 on success, otherwise a negative error value
244 * @retval #VCP_ERROR_NONE Successful
245 * @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter
247 * @see vcpe_result_cb()
249 typedef int (*vcpe_set_result_cb)(vcpe_result_cb callback, void* user_data);
252 * @brief Registers a callback function for getting ASR recognition result.
254 * @param[in] callback Callback function to register
255 * @param[in] user_data The user data to be passed to the callback function
257 * @return 0 on success, otherwise a negative error value
259 * @see vcpe_asr_result_cb()
261 typedef int (*vcpe_set_asr_result_cb)(vcpe_asr_result_cb callback, void* user_data);
265 * @brief Registers a callback function for getting partial recognition result.
267 * @param[in] callback Callback function to register
268 * @param[in] user_data The user data to be passed to the callback function
270 * @return 0 on success, otherwise a negative error value
272 * @see vcpe_pre_result_cb()
274 typedef int (*vcpe_set_pre_result_cb)(vcpe_pre_result_cb callback, void* user_data);
278 * @brief Registers a callback function for error.
280 * @param[in] callback Callback function to register
281 * @param[in] user_data The user data to be passed to the callback function
283 * @return 0 on success, otherwise a negative error value
286 typedef int (*vcpe_set_error_cb)(vcpe_error_cb callback, void* user_data);
290 * @brief Registers a callback function for getting NLU result.
292 * @param[in] callback Callback function to register
293 * @param[in] user_data The user data to be passed to the callback function
295 * @return 0 on success, otherwise a negative error value
298 typedef int (*vcpe_set_nlu_result_cb)(vcpe_nlu_result_cb, void* user_data);
302 * @brief Gets recording format of the engine.
304 * @param[in] audio_id The audio device id.
305 * @param[out] types The format used by the recorder.
306 * @param[out] rate The sample rate used by the recorder.
307 * @param[out] channels The number of channels used by the recorder.
309 * @return 0 on success, otherwise a negative error value
310 * @retval #VCP_ERROR_NONE Successful
311 * @retval #VCP_ERROR_INVALID_PARAMETER Not initialized
313 typedef int (*vcpe_get_recording_format)(const char* audio_id, vcp_audio_type_e* types, int* rate, int* channels);
316 * @brief Retrieves all supported languages of the engine.
318 * @param[in] callback a callback function
319 * @param[in] user_data The user data to be passed to the callback function
321 * @return 0 on success, otherwise a negative error value
322 * @retval #VCP_ERROR_NONE Successful
323 * @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter
324 * @retval #VCP_ERROR_INVALID_STATE Not initialized
326 * @post This function invokes vcpe_supported_language_cb() repeatedly for getting supported languages.
328 * @see vcpe_supported_language_cb()
330 typedef int (*vcpe_foreach_supported_languages)(vcpe_supported_language_cb callback, void* user_data);
333 * @brief Checks whether a language is supported or not.
335 * @param[in] language A language
337 * @return @c true = supported, \n @c false = not supported.
339 typedef bool (*vcpe_is_language_supported)(const char* language);
342 * @brief Sets language.
344 * @param[in] language language.
346 * @return 0 on success, otherwise a negative error value
347 * @retval #VCP_ERROR_NONE Successful
348 * @retval #VCP_ERROR_INVALID_LANGUAGE Invalid language
349 * @retval #VCP_ERROR_INVALID_STATE Not initialized
351 typedef int (*vcpe_set_language)(const char* language);
354 * @brief Sets command list before recognition.
356 * @remark This function should set commands via vcpd_foreach_command().
358 * @param[in] vcp_command command handle.
360 * @return 0 on success, otherwise a negative error value
361 * @retval #VCP_ERROR_NONE Successful
362 * @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter
363 * @retval #VCP_ERROR_INVALID_STATE Invalid state
364 * @retval #VCP_ERROR_OPERATION_FAILED Operation failed
365 * @retval #VCP_ERROR_NOT_SUPPORTED_FEATURE Not supported command type
367 * @post vcpe_start() is called after this function is successful.
370 * @see vcpd_foreach_command()
371 * @see vcpe_unset_commands()
373 typedef int (*vcpe_set_commands)(vcp_cmd_h vcp_command);
376 * @brief Unset command list for reset.
378 * @return 0 on success, otherwise a negative error value
379 * @retval #VCP_ERROR_NONE Successful
380 * @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter
381 * @retval #VCP_ERROR_INVALID_STATE Invalid state
382 * @retval #VCP_ERROR_OPERATION_FAILED Operation failed
384 * @see vcpe_set_commands()
386 typedef int (*vcpe_unset_commands)();
389 * @brief Start recognition.
391 * @return 0 on success, otherwise a negative error value
392 * @retval #VCP_ERROR_NONE Successful
393 * @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter
394 * @retval #VCP_ERROR_INVALID_STATE Invalid state
395 * @retval #VCP_ERROR_INVALID_LANGUAGE Invalid language
396 * @retval #VCP_ERROR_OUT_OF_NETWORK Out of network
397 * @retval #VCP_ERROR_OPERATION_FAILED Operation failed
399 * @pre vcpd_foreach_command() is successful.
401 * @see vcpe_set_recording_data()
405 typedef int (*vcpe_start)(bool stop_by_silence);
408 * @brief Sets recording data for speech recognition from recorder.
410 * @remark This function should be returned immediately after recording data copy.
412 * @param[in] data A recording data
413 * @param[in] length A length of recording data
414 * @param[out] silence_detected @c true Silence detected \n @c false No silence detected
416 * @return 0 on success, otherwise a negative error value
417 * @retval #VCP_ERROR_NONE Successful
418 * @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter
419 * @retval #VCP_ERROR_INVALID_STATE Invalid state
420 * @retval #VCP_ERROR_OPERATION_FAILED Operation failed
422 * @pre vcpe_start() is successful.
428 typedef int(*vcpe_set_recording_data)(const void* data, unsigned int length, vcp_speech_detect_e* speech_detected);
431 * @brief Stops to get the result of recognition.
433 * @return 0 on success, otherwise a negative error value
434 * @retval #VCP_ERROR_NONE Successful
435 * @retval #VCP_ERROR_INVALID_STATE Invalid state
436 * @retval #VCP_ERROR_OPERATION_FAILED Operation failed
437 * @retval #VCP_ERROR_OUT_OF_NETWORK Out of network
439 * @pre vcpe_set_recording_data() is successful.
442 * @see vcpe_set_recording_data()
443 * @see vcpe_result_cb()
446 typedef int (*vcpe_stop)(void);
449 * @brief Cancels the recognition process.
451 * @return 0 on success, otherwise a negative error value.
452 * @retval #VCP_ERROR_NONE Successful.
453 * @retval #VCP_ERROR_INVALID_STATE Invalid state.
455 * @pre vcpe_start() is successful.
460 typedef int (*vcpe_cancel)(void);
463 * @brief Sets domain (Agent or device type)
465 * @param[in] domain available Agent or device type
467 * @return 0 on success, otherwise a negative error value.
470 typedef int (*vcpe_set_domain)(const char* domain);
473 * @brief Gets essential value from nlu result. This function is available inside vcpe_nlu_result_cb()
475 * @param[in] key NLU base info key
476 * @parma[out] value NLU base info value
478 * @return 0 on success, otherwise a negative error value.
481 typedef int (*vcpe_get_nlu_base_info)(const char* key, char** value);
484 * @brief Sets private data between app and engine.
486 * @param[in] key Private key
487 * @param[in] data Private data
489 * @return 0 on success, otherwise a negative error value.
492 typedef int (*vcpe_set_private_data)(const char* key, const char* data);
495 * @brief Gets private data between app and engine.
497 * @param[in] key Private key
498 * @param[out] data Private data
500 * @return 0 on success, otherwise a negative error value.
503 typedef int (*vcpe_get_private_data)(const char* key, char** data);
506 * @brief Request process text.
508 * @param[in] text Requested text
510 * @return 0 on success, otherwise a negative error value.
513 typedef int (*vcpe_process_text)(const char* text);
516 * @brief Request list event.
518 * @param[in] event Requested list event
520 * @return 0 on success, otherwise a negative error value.
523 typedef int (*vcpe_process_list_event)(const char* event);
526 * @brief Request haptic event.
528 * @param[in] event Requested haptic event
530 * @return 0 on success, otherwise a negative error value.
533 typedef int (*vcpe_process_haptic_event)(const char* event);
540 * @brief Called to retrieve the commands.
542 * @param[in] id command id
543 * @param[in] type command type
544 * @param[in] format command format
545 * @param[in] command command text
546 * @param[in] param parameter text
547 * @param[in] domain command domain
548 * @param[in] user_data The user data passed from the foreach function
550 * @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop.
551 * @pre vcpd_foreach_command() will invoke this callback.
553 * @see vcpd_foreach_command()
555 typedef bool (*vcpd_foreach_command_cb)(int id, int type, int format, const char* command, const char* param, int domain, void* user_data);
558 * @brief Retrieves all commands using callback function.
560 * @param[in] vcp_command The handle to be passed to the vcpe_set_commands() function
561 * @param[in] callback The callback function to invoke
562 * @param[in] user_data The user data to be passed to the callback function
564 * @return 0 on success, otherwise a negative error value
565 * @retval #VCP_ERROR_NONE Successful
566 * @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter
567 * @retval #VCP_ERROR_OPERATION_FAILED Operation failure
568 * @retval #VCP_ERROR_INVALID_STATE Invalid state
570 * @post This function invokes vcpd_foreach_command_cb() repeatedly for getting commands.
572 * @see vcpd_foreach_command_cb()
573 * @see vcpe_set_commands()
575 typedef int (*vcpd_foreach_command)(vcp_cmd_h vcp_command, vcpd_foreach_command_cb callback, void* user_data);
578 * @brief Gets command length.
580 * @param[in] vcp_command The handle to be passed to the vcpe_set_commands() function
582 * @return the value greater than 0 on success, otherwise a negative error value
584 * @see vcpe_set_commands()
586 typedef int (*vcpd_get_command_count)(vcp_cmd_h vcp_command);
589 * @brief Gets current audio type.
591 * @remarks audio_type must be released using free() when it is no longer required.
593 * @param[in] audio_type Current audio type (e.g. #VCP_AUDIO_ID_BLUETOOTH or usb device id)
595 * @return the value greater than 0 on success, otherwise a negative error value
598 typedef int (*vcpd_get_audio_type)(char** audio_type);
601 * @brief A structure of the engine functions.
604 int size; /**< Size of structure */
605 int version; /**< Version */
607 vcpe_initialize initialize; /**< Initialize engine */
608 vcpe_deinitialize deinitialize; /**< Shutdown engine */
610 /* Get engine information */
611 vcpe_get_recording_format get_recording_format; /**< Get recording format */
612 vcpe_foreach_supported_languages foreach_langs; /**< Foreach language list */
613 vcpe_is_language_supported is_lang_supported; /**< Check language */
616 vcpe_set_result_cb set_result_cb; /**< Set result callback */
617 vcpe_set_language set_language; /**< Set language */
618 vcpe_set_commands set_commands; /**< Request to set current commands */
619 vcpe_unset_commands unset_commands; /**< Request to unset current commands */
621 /* Control recognition */
622 vcpe_start start; /**< Start recognition */
623 vcpe_set_recording_data set_recording; /**< Set recording data */
624 vcpe_stop stop; /**< Stop recording for getting result */
625 vcpe_cancel cancel; /**< Cancel recording and processing */
627 //vcpe_set_pre_result_cb set_pre_result_cb; /**< Set pre result callback */
628 vcpe_set_asr_result_cb set_asr_result_cb; /**< Set asr result callback */
629 vcpe_set_error_cb set_error_cb; /**< Set error callback */
630 vcpe_set_domain set_domain; /**< Set domain */
631 vcpe_get_nlu_base_info get_nlu_base_info; /**< Get essential info */
632 //vcpe_set_nlu_result_cb set_nlu_result_cb; /**< Set nlu result callback */
633 vcpe_set_private_data set_private_data; /**< Set private data */
634 vcpe_get_private_data get_private_data; /**< Get private data */
635 vcpe_process_text process_text; /**< Request to process text */
636 vcpe_process_list_event process_list_event; /**< Request to process list event */
637 vcpe_process_haptic_event process_haptic_event; /**< Request to process haptic event */
641 * @brief A structure of the daemon functions.
644 int size; /**< Size of structure */
645 int version; /**< Version */
647 vcpd_foreach_command foreach_command; /**< Foreach command */
648 vcpd_get_command_count get_command_count; /**< Get command count */
650 vcpd_get_audio_type get_audio_type; /**< Get audio type */
654 * @brief Loads the engine.
656 * @param[in] pdfuncs The daemon functions
657 * @param[out] pefuncs The engine functions
659 * @return This function returns zero on success, or negative with error code on failure
660 * @retval #VCP_ERROR_NONE Successful
661 * @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter
662 * @retval #VCP_ERROR_OPERATION_FAILED Operation failed
664 * @pre The vcp_get_engine_info() should be successful.
665 * @post The daemon calls engine functions of vcpe_funcs_s.
667 * @see vcp_get_engine_info()
668 * @see vcp_unload_engine()
670 int vcp_load_engine(vcpd_funcs_s* pdfuncs, vcpe_funcs_s* pefuncs);
673 * @brief Unloads this engine by the daemon.
675 * @pre The vcp_load_engine() should be successful.
677 * @see vcp_load_engine()
679 void vcp_unload_engine(void);
682 * @brief Called to get the engine base information.
684 * @param[in] engine_uuid The engine id
685 * @param[in] engine_name The engine name
686 * @param[in] engine_setting The setting ug name
687 * @param[in] use_network @c true to need network @c false not to need network.
688 * @param[in] user_data The User data passed from vcp_get_engine_info()
690 * @pre vcp_get_engine_info() will invoke this callback.
692 * @see vcp_get_engine_info()
694 typedef void (*vcpe_engine_info_cb)(const char* engine_uuid, const char* engine_name, const char* engine_setting,
695 bool use_network, void* user_data);
698 * @brief Gets the engine base information before the engine is loaded by the daemon.
700 * @param[in] callback Callback function
701 * @param[in] user_data User data to be passed to the callback function
703 * @return This function returns zero on success, or negative with error code on failure
704 * @retval #VCP_ERROR_NONE Successful
705 * @retval #VCP_ERROR_INVALID_PARAMETER Invalid parameter
706 * @retval #VCP_ERROR_OPERATION_FAILED Operation failed
708 * @post This function invokes vcpe_engine_info_cb() for getting engine information.
710 * @see vcpe_engine_info_cb()
711 * @see vcp_load_engine()
713 int vcp_get_engine_info(vcpe_engine_info_cb callback, void* user_data);
724 #endif /* __VOICE_CONTROL_PLUGIN_ENGINE_H__ */