Tizen Native API
5.0
|
The Voice control API provides functions for registering command and getting notification when registered command is recognized.
#include <voice_control.h>
A main function of Voice Control API register command and gets notification for recognition result. Applications can add their own commands and be provided result when their command is recognized by user voice input. To use of Voice Control, use the following steps:
1. Initialize
2. Register callback functions for notifications
3. Connect to voice control service asynchronously. The state should be changed to Ready
4. Make command list as the following step and Step 4 is called repeatedly for each command which an application wants
4-1. Create command list handle
4-2. Create command handle
4-3. Set command and type for command handle
4-4. Add command handle to command list
5. Set command list for recognition
6. Set an invocation name for an application
7. Get recognition results
8. Request the dialogue
9. If an application wants to finish voice control,
9-1. Destroy command and command list handle
9-2. Deinitialize
An application can obtain command handle from command list, and also get information from handle. The Voice Control API also notifies you (by callback mechanism) when the states of client and service are changed, command is recognized, current language is changed or error occurred. An application should register callback functions: vc_state_changed_cb(), vc_service_state_changed_cb(), vc_result_cb(), vc_current_language_changed_cb(), vc_error_cb().
The following diagram shows the life cycle and the states of the Voice Control.
The following diagram shows the states of Voice Control service.
FUNCTION | PRE-STATE | POST-STATE | SYNC TYPE |
---|---|---|---|
vc_initialize() | None | Initialized | SYNC |
vc_deinitialize() | Initialized | None | SYNC |
vc_prepare() | Initialized | Ready | ASYNC |
vc_unprepare() | Ready | Initialized | SYNC |
The following table shows state-dependent function calls. It is forbidden to call functions listed below in wrong states. Violation of this rule may result in an unpredictable behavior.
This API is related with the following features:
Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Functions | |
int | vc_initialize (void) |
Initializes voice control. | |
int | vc_deinitialize (void) |
Deinitializes voice control. | |
int | vc_prepare (void) |
Connects the voice control service. | |
int | vc_unprepare (void) |
Disconnects the voice control service. | |
int | vc_foreach_supported_languages (vc_supported_language_cb callback, void *user_data) |
Retrieves all supported languages using callback function. | |
int | vc_get_current_language (char **language) |
Gets current language. | |
int | vc_get_state (vc_state_e *state) |
Gets current state of voice control client. | |
int | vc_get_service_state (vc_service_state_e *state) |
Gets current state of voice control service. | |
int | vc_get_system_command_list (vc_cmd_list_h *vc_sys_cmd_list) |
Gets the system command list. | |
int | vc_set_invocation_name (const char *name) |
Sets the invocation name. | |
int | vc_set_server_dialog (const char *app_id, const char *credential) |
Requests to set app id which is to want to ask the server dialogue. | |
int | vc_unset_server_dialog (const char *app_id) |
Requests to unset app id which is to not want to ask the server dialogue. | |
int | vc_request_dialog (const char *disp_text, const char *utt_text, bool auto_start) |
Requests to start the dialogue. | |
int | vc_set_command_list (vc_cmd_list_h vc_cmd_list, int type) |
Sets command list. | |
int | vc_unset_command_list (int type) |
Unsets command list. | |
int | vc_get_result (vc_result_cb callback, void *user_data) |
Gets the recognition result. | |
int | vc_set_result_cb (vc_result_cb callback, void *user_data) |
Registers a callback function for getting recognition result. | |
int | vc_unset_result_cb (void) |
Unregisters the callback function. | |
int | vc_set_service_state_changed_cb (vc_service_state_changed_cb callback, void *user_data) |
Registers a callback function to be called when state is changed. | |
int | vc_unset_service_state_changed_cb (void) |
Unregisters the callback function. | |
int | vc_set_state_changed_cb (vc_state_changed_cb callback, void *user_data) |
Registers a callback function to be called when state is changed. | |
int | vc_unset_state_changed_cb (void) |
Unregisters the callback function. | |
int | vc_set_current_language_changed_cb (vc_current_language_changed_cb callback, void *user_data) |
Registers a callback function to be called when current language is changed. | |
int | vc_unset_current_language_changed_cb (void) |
Unregisters the callback function. | |
int | vc_set_error_cb (vc_error_cb callback, void *user_data) |
Registers a callback function to be called when an error occurred. | |
int | vc_unset_error_cb (void) |
Unregisters the callback function. | |
Typedefs | |
typedef void(* | vc_result_cb )(vc_result_event_e event, vc_cmd_list_h vc_cmd_list, const char *result, void *user_data) |
Called when client gets the recognition result. | |
typedef void(* | vc_current_language_changed_cb )(const char *previous, const char *current, void *user_data) |
Called when default language is changed. | |
typedef bool(* | vc_supported_language_cb )(const char *language, void *user_data) |
Called to retrieve supported language. | |
typedef void(* | vc_state_changed_cb )(vc_state_e previous, vc_state_e current, void *user_data) |
Called when the state of voice control client is changed. | |
typedef void(* | vc_service_state_changed_cb )(vc_service_state_e previous, vc_service_state_e current, void *user_data) |
Called when the state of voice control service is changed. | |
typedef void(* | vc_error_cb )(vc_error_e reason, void *user_data) |
Called when error occurred. | |
Defines | |
#define | VC_COMMAND_TYPE_FOREGROUND 1 |
Definition for foreground command type. | |
#define | VC_COMMAND_TYPE_BACKGROUND 2 |
Definition for background command type. | |
#define | VC_DIALOG_END 0 |
Definition for ended dialog. | |
#define | VC_DIALOG_CONTINUE 1 |
Definition for continued dialog. |
#define VC_COMMAND_TYPE_BACKGROUND 2 |
Definition for background command type.
#define VC_COMMAND_TYPE_FOREGROUND 1 |
Definition for foreground command type.
#define VC_DIALOG_CONTINUE 1 |
Definition for continued dialog.
#define VC_DIALOG_END 0 |
Definition for ended dialog.
typedef void(* vc_current_language_changed_cb)(const char *previous, const char *current, void *user_data) |
Called when default language is changed.
[in] | previous | Previous language |
[in] | current | Current language |
[in] | user_data | The user data passed from the callback registration function |
typedef void(* vc_error_cb)(vc_error_e reason, void *user_data) |
Called when error occurred.
[in] | reason | The error type (e.g. VC_ERROR_OUT_OF_MEMORY, VC_ERROR_TIMED_OUT) |
[in] | user_data | The user data passed from the callback registration function |
typedef void(* vc_result_cb)(vc_result_event_e event, vc_cmd_list_h vc_cmd_list, const char *result, void *user_data) |
Called when client gets the recognition result.
[in] | event | The result event (e.g. VC_RESULT_EVENT_RESULT_SUCCESS, VC_RESULT_EVENT_REJECTED) |
[in] | vc_cmd_list | The recognized command list |
[in] | result | The spoken text |
[in] | user_data | The user data passed from the callback registration function |
typedef void(* vc_service_state_changed_cb)(vc_service_state_e previous, vc_service_state_e current, void *user_data) |
Called when the state of voice control service is changed.
[in] | previous | A previous state |
[in] | current | A current state |
[in] | user_data | The user data passed from the callback registration function |
typedef void(* vc_state_changed_cb)(vc_state_e previous, vc_state_e current, void *user_data) |
Called when the state of voice control client is changed.
[in] | previous | A previous state |
[in] | current | A current state |
[in] | user_data | The user data passed from the callback registration function |
typedef bool(* vc_supported_language_cb)(const char *language, void *user_data) |
Called to retrieve supported language.
[in] | language | A language is specified as an ISO 3166 alpha-2 two letter country-code followed by ISO 639-1 for the two-letter language code. For example, "ko_KR" for Korean, "en_US" for American English |
[in] | user_data | The user data passed from the foreach function |
true
to continue with the next iteration of the loop, false
to break out of the loop enum vc_audio_channel_e |
enum vc_audio_type_e |
enum vc_error_e |
Enumeration for error codes.
enum vc_feedback_event_e |
enum vc_result_event_e |
enum vc_service_state_e |
enum vc_state_e |
int vc_deinitialize | ( | void | ) |
Deinitializes voice control.
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_INVALID_STATE | Invalid state |
VC_ERROR_OPERATION_FAILED | Operation failure |
VC_ERROR_PERMISSION_DENIED | Permission denied |
VC_ERROR_NOT_SUPPORTED | Not supported |
int vc_foreach_supported_languages | ( | vc_supported_language_cb | callback, |
void * | user_data | ||
) |
Retrieves all supported languages using callback function.
[in] | callback | Callback function to invoke |
[in] | user_data | The user data to be passed to the callback function |
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_INVALID_PARAMETER | Invalid parameter |
VC_ERROR_OPERATION_FAILED | Operation failure |
VC_ERROR_INVALID_STATE | Invalid state |
VC_ERROR_PERMISSION_DENIED | Permission denied |
VC_ERROR_NOT_SUPPORTED | Not supported |
int vc_get_current_language | ( | char ** | language | ) |
Gets current language.
[out] | language | A language is specified as an ISO 3166 alpha-2 two letter country-code followed by ISO 639-1 for the two-letter language code. For example, "ko_KR" for Korean, "en_US" for American English |
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_INVALID_PARAMETER | Invalid parameter |
VC_ERROR_OUT_OF_MEMORY | Out of memory |
VC_ERROR_OPERATION_FAILED | Operation failure |
VC_ERROR_INVALID_STATE | Invalid state |
VC_ERROR_PERMISSION_DENIED | Permission denied |
VC_ERROR_NOT_SUPPORTED | Not supported |
int vc_get_result | ( | vc_result_cb | callback, |
void * | user_data | ||
) |
Gets the recognition result.
[in] | callback | Callback function to get recognition result |
[in] | user_data | The user data to be passed to the callback function |
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_INVALID_PARAMETER | Invalid parameter |
VC_ERROR_INVALID_STATE | Invalid state |
VC_ERROR_NOT_SUPPORTED | Not supported |
int vc_get_service_state | ( | vc_service_state_e * | state | ) |
Gets current state of voice control service.
[out] | state | The current state |
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_INVALID_PARAMETER | Invalid parameter |
VC_ERROR_PERMISSION_DENIED | Permission denied |
VC_ERROR_NOT_SUPPORTED | Not supported |
int vc_get_state | ( | vc_state_e * | state | ) |
Gets current state of voice control client.
[out] | state | The current state |
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_INVALID_PARAMETER | Invalid parameter |
VC_ERROR_PERMISSION_DENIED | Permission denied |
VC_ERROR_NOT_SUPPORTED | Not supported |
int vc_get_system_command_list | ( | vc_cmd_list_h * | vc_sys_cmd_list | ) |
Gets the system command list.
[out] | vc_sys_cmd_list | System command list handle |
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_INVALID_PARAMETER | Invalid parameter |
VC_ERROR_INVALID_STATE | Invalid state |
VC_ERROR_PERMISSION_DENIED | Permission denied |
VC_ERROR_NOT_SUPPORTED | Not supported |
int vc_initialize | ( | void | ) |
Initializes voice control.
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_OUT_OF_MEMORY | Out of memory |
VC_ERROR_OPERATION_FAILED | Operation failure |
VC_ERROR_PERMISSION_DENIED | Permission denied |
VC_ERROR_NOT_SUPPORTED | Not supported |
int vc_prepare | ( | void | ) |
Connects the voice control service.
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_INVALID_STATE | Invalid state |
VC_ERROR_OPERATION_FAILED | Operation failure |
VC_ERROR_PERMISSION_DENIED | Permission denied |
VC_ERROR_NOT_SUPPORTED | Not supported |
int vc_request_dialog | ( | const char * | disp_text, |
const char * | utt_text, | ||
bool | auto_start | ||
) |
Requests to start the dialogue.
Using this function, the developer can request starting the dialogue to the framework. When the developer requests the dialogue, two types of texts, disp_text and utt_text, can be sent by this function. disp_text is a text for displaying, and utt_text is that for uttering. For example, if disp_text is "October 10th" and utt_text is "Today is October 10th.", "October 10th" will be displayed on the screen and "Today is October 10th." will be spoken. Also, the developer can set whether the dialogue starts automatically or not, using auto_start. If the developer sets auto_start as true
, the framework will start to record next speech and continue the dialogue.
true
, the recognition will start again. In this case, it can be restarted up to 4 times. [in] | disp_text | Text to be displayed on the screen |
[in] | utt_text | Text to be spoken |
[in] | auto_start | A variable for setting whether the dialog session will be restarted automatically or not |
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_INVALID_PARAMETER | Invalid parameter |
VC_ERROR_INVALID_STATE | Invalid state |
VC_ERROR_PERMISSION_DENIED | Permission denied |
VC_ERROR_NOT_SUPPORTED | Not supported |
int vc_set_command_list | ( | vc_cmd_list_h | vc_cmd_list, |
int | type | ||
) |
Sets command list.
[in] | vc_cmd_list | Command list handle |
[in] | type | Command type |
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_INVALID_PARAMETER | Invalid parameter |
VC_ERROR_INVALID_STATE | Invalid state |
VC_ERROR_PERMISSION_DENIED | Permission denied |
VC_ERROR_NOT_SUPPORTED | Not supported |
int vc_set_current_language_changed_cb | ( | vc_current_language_changed_cb | callback, |
void * | user_data | ||
) |
Registers a callback function to be called when current language is changed.
[in] | callback | Callback function to register |
[in] | user_data | The user data to be passed to the callback function |
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_INVALID_PARAMETER | Invalid parameter |
VC_ERROR_INVALID_STATE | Invalid state |
VC_ERROR_PERMISSION_DENIED | Permission denied |
VC_ERROR_NOT_SUPPORTED | Not supported |
int vc_set_error_cb | ( | vc_error_cb | callback, |
void * | user_data | ||
) |
Registers a callback function to be called when an error occurred.
[in] | callback | Callback function to register |
[in] | user_data | The user data to be passed to the callback function |
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_INVALID_PARAMETER | Invalid parameter |
VC_ERROR_INVALID_STATE | Invalid state |
VC_ERROR_PERMISSION_DENIED | Permission denied |
VC_ERROR_NOT_SUPPORTED | Not supported |
int vc_set_invocation_name | ( | const char * | name | ) |
Sets the invocation name.
[in] | name | Invocation name that an application wants to be invoked by |
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_INVALID_PARAMETER | Invalid parameter |
VC_ERROR_INVALID_STATE | Invalid state |
VC_ERROR_PERMISSION_DENIED | Permission denied |
VC_ERROR_NOT_SUPPORTED | Not supported |
int vc_set_result_cb | ( | vc_result_cb | callback, |
void * | user_data | ||
) |
Registers a callback function for getting recognition result.
[in] | callback | Callback function to register |
[in] | user_data | The user data to be passed to the callback function |
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_INVALID_PARAMETER | Invalid parameter |
VC_ERROR_INVALID_STATE | Invalid state |
VC_ERROR_PERMISSION_DENIED | Permission denied |
VC_ERROR_NOT_SUPPORTED | Not supported |
int vc_set_server_dialog | ( | const char * | app_id, |
const char * | credential | ||
) |
Requests to set app id which is to want to ask the server dialogue.
Using this function, the developer can request registering the application on vc framework. If developer requests to register app_id with credential which is valid, the application will be set on vc framework. and then, when the developer requests the dialogue using vc_request_dialog(), dialog from specific engine server will be played by vc framework.
[in] | app_id | App id which is to want to ask server dialog. |
[in] | credential | Credential key. |
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_INVALID_PARAMETER | Invalid parameter |
VC_ERROR_INVALID_STATE | Invalid state |
VC_ERROR_PERMISSION_DENIED | Permission denied |
VC_ERROR_NOT_SUPPORTED | Not supported |
int vc_set_service_state_changed_cb | ( | vc_service_state_changed_cb | callback, |
void * | user_data | ||
) |
Registers a callback function to be called when state is changed.
[in] | callback | Callback function to register |
[in] | user_data | The user data to be passed to the callback function |
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_INVALID_PARAMETER | Invalid parameter |
VC_ERROR_INVALID_STATE | Invalid state |
VC_ERROR_PERMISSION_DENIED | Permission denied |
VC_ERROR_NOT_SUPPORTED | Not supported |
int vc_set_state_changed_cb | ( | vc_state_changed_cb | callback, |
void * | user_data | ||
) |
Registers a callback function to be called when state is changed.
[in] | callback | Callback function to register |
[in] | user_data | The user data to be passed to the callback function |
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_INVALID_PARAMETER | Invalid parameter |
VC_ERROR_INVALID_STATE | Invalid state |
VC_ERROR_PERMISSION_DENIED | Permission denied |
VC_ERROR_NOT_SUPPORTED | Not supported |
int vc_unprepare | ( | void | ) |
Disconnects the voice control service.
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_INVALID_STATE | Invalid state |
VC_ERROR_PERMISSION_DENIED | Permission denied |
VC_ERROR_NOT_SUPPORTED | Not supported |
int vc_unset_command_list | ( | int | type | ) |
Unsets command list.
[in] | type | Command type |
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_INVALID_PARAMETER | Invalid parameter |
VC_ERROR_INVALID_STATE | Invalid state |
VC_ERROR_PERMISSION_DENIED | Permission denied |
VC_ERROR_NOT_SUPPORTED | Not supported |
int vc_unset_current_language_changed_cb | ( | void | ) |
Unregisters the callback function.
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_INVALID_STATE | Invalid state |
VC_ERROR_PERMISSION_DENIED | Permission denied |
VC_ERROR_NOT_SUPPORTED | Not supported |
int vc_unset_error_cb | ( | void | ) |
Unregisters the callback function.
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_INVALID_STATE | Invalid state |
VC_ERROR_PERMISSION_DENIED | Permission denied |
VC_ERROR_NOT_SUPPORTED | Not supported |
int vc_unset_result_cb | ( | void | ) |
Unregisters the callback function.
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_INVALID_STATE | Invalid state |
VC_ERROR_NOT_SUPPORTED | Not supported |
int vc_unset_server_dialog | ( | const char * | app_id | ) |
Requests to unset app id which is to not want to ask the server dialogue.
Using this function, the developer can disable function to ask dialog based on server.
[in] | app_id | App id which is to not want to ask server dialog. |
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_INVALID_PARAMETER | Invalid parameter |
VC_ERROR_INVALID_STATE | Invalid state |
VC_ERROR_PERMISSION_DENIED | Permission denied |
VC_ERROR_NOT_SUPPORTED | Not supported |
int vc_unset_service_state_changed_cb | ( | void | ) |
Unregisters the callback function.
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_INVALID_STATE | Invalid state |
VC_ERROR_PERMISSION_DENIED | Permission denied |
VC_ERROR_NOT_SUPPORTED | Not supported |
int vc_unset_state_changed_cb | ( | void | ) |
Unregisters the callback function.
0
on success, otherwise a negative error value VC_ERROR_NONE | Successful |
VC_ERROR_INVALID_STATE | Invalid state |
VC_ERROR_PERMISSION_DENIED | Permission denied |
VC_ERROR_NOT_SUPPORTED | Not supported |