Tizen Native API
4.0
|
The TTS Engine APIs provide functions to operate Text-To-Speech Engine.
#include <ttse.h>
Text-To-Speech Engine (below TTSE) is an engine for synthesizing voice from text and playing synthesized sound data. Using the TTS Engine APIs, TTSE developers can provide TTSE service users, who want to apply TTSE, with functions necessary to operate the engine. According to the indispensability of TTSE services, there are two ways to provide them to the users.
A. Required TTSE services
These services are indispensable to operate TTSE. Therefore, the TTSE developers MUST implement callback functions corresponding to the required TTSE services. The following is a list of the callback functions.
FUNCTION | DESCRIPTION |
---|---|
ttse_get_info_cb() | Called when the engine service user requests the basic information of TTS engine. |
ttse_initialize_cb() | Called when the engine service user initializes TTS engine. |
ttse_deinitialize_cb() | Called when the engine service user deinitializes TTS engine. |
ttse_is_valid_voice_cb() | Called when the engine service user checks whether the voice is valid or not in TTS engine. |
ttse_foreach_supported_voices_cb() | Called when the engine service user gets the whole supported voice list. |
ttse_set_pitch_cb() | Called when the engine service user sets the default pitch of TTS engine. |
ttse_load_voice_cb() | Called when the engine service user requests to load the corresponding voice type for the first time. |
ttse_unload_voice_cb() | Called when the engine service user requests to unload the corresponding voice type or to stop using voice. |
ttse_start_synthesis_cb() | Called when the engine service user starts to synthesize a voice, asynchronously. |
ttse_cancel_synthesis_cb() | Called when the engine service user cancels to synthesize a voice. |
ttse_check_app_agreed_cb() | Called when the engine service user requests for TTS engine to check whether the application agreed the usage of TTS engine. |
ttse_need_app_credential_cb() | Called when the engine service user checks whether TTS engine needs the application's credential. |
The TTSE developers can register the above callback functions at a time with using a structure 'ttse_request_callback_s' and an API 'ttse_main()'. To operate TTSE, the following steps should be used:
1. Create a structure 'ttse_request_callback_s' 2. Implement callback functions. (NOTE that the callback functions should return appropriate values in accordance with the instruction. If the callback function returns an unstated value, TTS framework will handle it as TTSE_ERROR_OPERATION_FAILED.)
3. Register callback functions using 'ttse_main()'. (The registered callback functions will be invoked when the TTSE service users request the TTSE services.)
4. Use 'service_app_main()' for working TTSE.
B. Optional TTSE services
Unlike the required TTSE services, these services are optional to operate TTSE. The followings are optional TTSE services.
FUNCTION | DESCRIPTION | CORRESPONDING CALLBACK |
---|---|---|
ttse_set_private_data_set_cb() | Sets a callback function for receiving the private data from the engine service user. | ttse_private_data_set_cb() |
ttse_set_private_data_requested_cb() | Sets a callback function for providing the private data to the engine service user. | ttse_private_data_requested_cb() |
FUNCTION | DESCRIPTION |
---|---|
ttse_get_speed_range() | Gets the speed range from Tizen platform. |
ttse_get_pitch_range() | Gets the pitch range from Tizen platform. |
ttse_send_result() | Sends the synthesized result to the engine service user. |
ttse_send_error() | Sends the error to the engine service user. |
This API is related with the following features:
Functions | |
int | ttse_main (int argc, char **argv, ttse_request_callback_s *callback) |
Main function for Text-To-Speech (TTS) engine. | |
int | ttse_get_speed_range (int *min, int *normal, int *max) |
Gets the speed range from Tizen platform. | |
int | ttse_get_pitch_range (int *min, int *normal, int *max) |
Gets the pitch range from Tizen platform. | |
int | ttse_send_result (ttse_result_event_e event, const void *data, unsigned int data_size, ttse_audio_type_e audio_type, int rate, void *user_data) |
Sends the synthesized result to the engine service user. | |
int | ttse_send_error (ttse_error_e error, const char *msg) |
Sends the error to the engine service user. | |
int | ttse_set_private_data_set_cb (ttse_private_data_set_cb callback_func) |
Sets a callback function for setting the private data. | |
int | ttse_set_private_data_requested_cb (ttse_private_data_requested_cb callback_func) |
Sets a callback function for requesting the private data. | |
Typedefs | |
typedef bool(* | ttse_supported_voice_cb )(const char *language, int type, void *user_data) |
Called when TTS engine informs the engine service user about whole supported language and voice type list. | |
typedef int(* | ttse_initialize_cb )(void) |
Called when the engine service user initializes TTS engine. | |
typedef int(* | ttse_deinitialize_cb )(void) |
Called when the engine service user deinitializes TTS engine. | |
typedef int(* | ttse_foreach_supported_voices_cb )(ttse_supported_voice_cb callback, void *user_data) |
Called when the engine service user gets the whole supported voice list. | |
typedef int(* | ttse_is_valid_voice_cb )(const char *language, int type, bool *is_valid) |
Called when the engine service user checks whether the voice is valid or not in TTS engine. | |
typedef int(* | ttse_set_pitch_cb )(int pitch) |
Called when the engine service user sets the default pitch of TTS engine. | |
typedef int(* | ttse_load_voice_cb )(const char *language, int type) |
Called when the engine service user requests to load the corresponding voice type for the first time. | |
typedef int(* | ttse_unload_voice_cb )(const char *language, int type) |
Called when the engine service user requests to unload the corresponding voice type or to stop using voice. | |
typedef int(* | ttse_check_app_agreed_cb )(const char *appid, bool *is_agreed) |
Called when the engine service user requests for TTS engine to check whether the application agreed the usage of TTS engine. | |
typedef bool(* | ttse_need_app_credential_cb )(void) |
Called when the engine service user checks whether TTS engine needs the application's credential. | |
typedef int(* | ttse_start_synthesis_cb )(const char *language, int type, const char *text, int speed, const char *appid, const char *credential, void *user_data) |
Called when the engine service user starts to synthesize a voice, asynchronously. | |
typedef int(* | ttse_cancel_synthesis_cb )(void) |
Called when the engine service user cancels to synthesize a voice. | |
typedef int(* | ttse_get_info_cb )(char **engine_uuid, char **engine_name, char **engine_setting, bool *use_network) |
Called when the engine service user requests the basic information of TTS engine. | |
typedef int(* | ttse_private_data_set_cb )(const char *key, const char *data) |
Called when TTS engine receives the private data from the engine service user. | |
typedef int(* | ttse_private_data_requested_cb )(const char *key, char **data) |
Called when TTS engine provides the engine service user with the private data. | |
Defines | |
#define | TTSE_VOICE_TYPE_MALE 1 |
Definition for male voice type. | |
#define | TTSE_VOICE_TYPE_FEMALE 2 |
Definition for female voice type. | |
#define | TTSE_VOICE_TYPE_CHILD 3 |
Definition for child's voice type. |
#define TTSE_VOICE_TYPE_CHILD 3 |
Definition for child's voice type.
#define TTSE_VOICE_TYPE_FEMALE 2 |
Definition for female voice type.
#define TTSE_VOICE_TYPE_MALE 1 |
Definition for male voice type.
typedef int(* ttse_cancel_synthesis_cb)(void) |
Called when the engine service user cancels to synthesize a voice.
0
on success, otherwise a negative error value TTSE_ERROR_NONE | Successful |
TTSE_ERROR_INVALID_STATE | Not initialized or not started synthesis |
typedef int(* ttse_check_app_agreed_cb)(const char *appid, bool *is_agreed) |
Called when the engine service user requests for TTS engine to check whether the application agreed the usage of TTS engine.
This callback function is called when the engine service user requests for TTS engine to check the application's agreement about using the engine. According to the need, the engine developer can provide some user interfaces to check the agreement.
true
if the developer regards that every application agreed the usage of the engine, false
if the developer regards that every application disagreed. 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. [in] | appid | The Application ID |
[out] | is_agreed | A variable for checking whether the application agreed to use TTS engine or not. true to agree, false to disagree |
0
on success, otherwise a negative error value TTSE_ERROR_NONE | Successful |
TTSE_ERROR_INVALID_STATE | Not initialized |
TTSE_ERROR_INVALID_PARAMETER | Invalid parameter |
TTSE_ERROR_NOT_SUPPORTED_FEATURE | Not supported feature |
typedef int(* ttse_deinitialize_cb)(void) |
Called when the engine service user deinitializes TTS engine.
0
on success, otherwise a negative error value TTSE_ERROR_NONE | Successful |
TTSE_ERROR_INVALID_STATE | Not initialized |
typedef int(* ttse_foreach_supported_voices_cb)(ttse_supported_voice_cb callback, void *user_data) |
Called when the engine service user gets the whole supported voice list.
false
, it should be stopped to call 'ttse_supported_voice_cb()'. [in] | callback | The callback function |
[in] | user_data | The user data which must be passed to ttse_supported_voice_cb() |
0
on success, otherwise a negative error value TTSE_ERROR_NONE | Successful |
TTSE_ERROR_INVALID_PARAMETER | Invalid parameter |
TTSE_ERROR_INVALID_STATE | Not initialized |
typedef int(* ttse_get_info_cb)(char **engine_uuid, char **engine_name, char **engine_setting, bool *use_network) |
Called when the engine service user requests the basic information of TTS engine.
[out] | engine_uuid | UUID of engine |
[out] | engine_name | Name of engine |
[out] | engine_setting | The engine setting application(ui app)'s app ID |
[out] | use_network | The status for using network |
0
on success, otherwise a negative error code on failure TTSE_ERROR_NONE | Successful |
TTSE_ERROR_INVALID_PARAMETER | Invalid parameter |
TTSE_ERROR_OPERATION_FAILED | Operation failure |
typedef int(* ttse_initialize_cb)(void) |
Called when the engine service user initializes TTS engine.
0
on success, otherwise a negative error value TTSE_ERROR_NONE | Successful |
TTSE_ERROR_INVALID_PARAMETER | Invalid parameter |
TTSE_ERROR_INVALID_STATE | Already initialized |
TTSE_ERROR_OPERATION_FAILED | Operation failure |
TTSE_ERROR_PERMISSION_DENIED | Permission denied |
typedef int(* ttse_is_valid_voice_cb)(const char *language, int type, bool *is_valid) |
Called when the engine service user checks whether the voice is valid or not in TTS engine.
[in] | language | The 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] | type | The voice type |
[out] | is_valid | A variable for checking whether the corresponding voice is valid or not. true to be valid, false to be invalid |
0
on success, otherwise a negative error value TTSE_ERROR_NONE | Successful |
TTSE_ERROR_INVALID_PARAMETER | Invalid parameter |
typedef int(* ttse_load_voice_cb)(const char *language, int type) |
Called when the engine service user requests to load the corresponding voice type for the first time.
[in] | language | The 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] | type | The voice type |
0
on success, otherwise a negative error value TTSE_ERROR_NONE | Successful |
TTSE_ERROR_INVALID_PARAMETER | Invalid parameter |
TTSE_ERROR_INVALID_STATE | Not initialized |
TTSE_ERROR_OUT_OF_MEMORY | Out of memory |
TTSE_ERROR_INVALID_VOICE | Invalid voice |
TTSE_ERROR_OPERATION_FAILED | Operation failure |
typedef bool(* ttse_need_app_credential_cb)(void) |
Called when the engine service user checks whether TTS engine needs the application's credential.
true
if TTS engine needs the application's credential, otherwise false
typedef int(* ttse_private_data_requested_cb)(const char *key, char **data) |
Called when TTS engine provides the engine service user with the private data.
This callback function is called when the engine service user gets the private data from TTS engine.
[out] | key | The key field of private data |
[out] | data | The data field of private data |
0
on success, otherwise a negative error value TTSE_ERROR_NONE | Successful |
TTSE_ERROR_INVALID_PARAMETER | Invalid parameter |
TTSE_ERROR_OPERATION_FAILED | Operation failure |
TTSE_ERROR_NOT_SUPPORTED_FEATURE | Not supported feature |
typedef int(* ttse_private_data_set_cb)(const char *key, const char *data) |
Called when TTS engine receives the private data from the engine service user.
This callback function is called when the engine service user sends the private data to TTS engine.
[in] | key | The key field of private data |
[in] | data | The data field of private data |
0
on success, otherwise a negative error value TTSE_ERROR_NONE | Successful |
TTSE_ERROR_INVALID_PARAMETER | Invalid parameter |
TTSE_ERROR_OPERATION_FAILED | Operation failure |
TTSE_ERROR_NOT_SUPPORTED_FEATURE | Not supported feature |
typedef int(* ttse_set_pitch_cb)(int pitch) |
Called when the engine service user sets the default pitch of TTS engine.
[in] | pitch | The default pitch |
0
on success, otherwise a negative error value TTSE_ERROR_NONE | Successful |
TTSE_ERROR_INVALID_PARAMETER | Invalid parameter |
TTSE_ERROR_INVALID_STATE | Not initialized |
TTSE_ERROR_OPERATION_FAILED | Operation failure |
typedef int(* ttse_start_synthesis_cb)(const char *language, int type, const char *text, int speed, const char *appid, const char *credential, void *user_data) |
Called when the engine service user starts to synthesize a voice, asynchronously.
[in] | language | The 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] | type | The voice type |
[in] | text | Texts |
[in] | speed | The speed of speaking |
[in] | appid | The Application ID |
[in] | credential | The credential granted to the application |
[in] | user_data | The user data which must be passed to ttse_send_result() |
0
on success, otherwise a negative error value TTSE_ERROR_NONE | Successful |
TTSE_ERROR_INVALID_PARAMETER | Invalid parameter |
TTSE_ERROR_INVALID_STATE | Not initialized or already started synthesis |
TTSE_ERROR_INVALID_VOICE | Invalid voice |
TTSE_ERROR_OPERATION_FAILED | Operation failure |
TTSE_ERROR_NETWORK_DOWN | Out of network |
TTSE_ERROR_PERMISSION_DENIED | Permission denied |
typedef bool(* ttse_supported_voice_cb)(const char *language, int type, void *user_data) |
Called when TTS engine informs the engine service user about whole supported language and voice type list.
This callback function is implemented by the engine service user. Therefore, the engine developer does NOT have to implement this callback function.
[in] | language | The 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] | type | The voice type |
[in] | user_data | The user data passed from ttse_foreach_supported_voices_cb() |
true
to continue with the next iteration of the loop false
to break out of the loop typedef int(* ttse_unload_voice_cb)(const char *language, int type) |
Called when the engine service user requests to unload the corresponding voice type or to stop using voice.
[in] | language | The 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] | type | The voice type |
0
on success, otherwise a negative error value TTSE_ERROR_NONE | Successful |
TTSE_ERROR_INVALID_PARAMETER | Invalid parameter |
TTSE_ERROR_INVALID_STATE | Not initialized |
TTSE_ERROR_INVALID_VOICE | Invalid voice |
TTSE_ERROR_OPERATION_FAILED | Operation failure |
enum ttse_audio_type_e |
enum ttse_error_e |
Enumeration for error codes.
enum ttse_result_event_e |
Enumeration for result event type.
int ttse_get_pitch_range | ( | int * | min, |
int * | normal, | ||
int * | max | ||
) |
Gets the pitch range from Tizen platform.
[out] | min | The minimum pitch value |
[out] | normal | The normal pitch value |
[out] | max | The maximum pitch value |
0
on success, otherwise a negative error value TTSE_ERROR_NONE | Successful |
TTSE_ERROR_INVALID_PARAMETER | Invalid parameter |
TTSE_ERROR_NOT_SUPPORTED | Not supported |
TTSE_ERROR_OPERATION_FAILED | Operation failure |
int ttse_get_speed_range | ( | int * | min, |
int * | normal, | ||
int * | max | ||
) |
Gets the speed range from Tizen platform.
[out] | min | The minimum speed value |
[out] | normal | The normal speed value |
[out] | max | The maximum speed value |
0
on success, otherwise a negative error value TTSE_ERROR_NONE | Successful |
TTSE_ERROR_INVALID_PARAMETER | Invalid parameter |
TTSE_ERROR_NOT_SUPPORTED | Not supported |
TTSE_ERROR_OPERATION_FAILED | Operation failure |
int ttse_main | ( | int | argc, |
char ** | argv, | ||
ttse_request_callback_s * | callback | ||
) |
Main function for Text-To-Speech (TTS) engine.
This function is the main function for operating TTS engine.
[in] | argc | The argument count(original) |
[in] | argv | The argument(original) |
[in] | callback | The structure of engine request callback function |
TTSE_ERROR_NONE | Successful |
TTSE_ERROR_INVALID_PARAMETER | Invalid parameter |
TTSE_ERROR_OPERATION_FAILED | Operation failure |
TTSE_ERROR_NOT_SUPPORTED | Not supported |
#include <ttse.h> // Required callback functions - MUST BE IMPLEMENTED static int ttsengine_get_info_cb(char** engine_uuid, char** engine_name, char** engine_setting, bool* use_network); static int ttsengine_initialize_cb(void); static int ttsengine_deinitialize_cb(void); static int ttsengine_is_valid_voice_cb(const char* language, int type, bool* is_valid); static int ttsengine_foreach_supported_voices_cb(ttse_supported_voice_cb callback, void* user_data); static int ttsengine_set_pitch_cb(int pitch); static int ttsengine_load_voice_cb(const char* language, int type); static int ttsengine_unload_voice_cb(const char* language, int type); static int ttsengine_start_synthesis_cb(const char* language, int type, const char* text, int speed, void* user_data); static int ttsengine_cancel_synthesis_cb(void); static int ttsengine_check_app_agreed_cb(const char* appid, bool* is_agreed); static bool ttsengine_need_app_credential_cb(void); // Optional callback function static int ttsengine_private_data_set_cb(const char* key, const char* data); int main(int argc, char* argv[]) { // 1. Create a structure 'ttse_request_callback_s' ttse_request_callback_s engine_callback = { 0, }; engine_callback.size = sizeof(ttse_request_callback_s); engine_callback.version = 1; engine_callback.get_info = ttsengine_get_info_cb; engine_callback.initialize = ttsengine_initialize_cb; engine_callback.deinitialize = ttsengine_deinitialize_cb; engine_callback.foreach_voices = ttsengine_foreach_supported_voices_cb; engine_callback.is_valid_voice = ttsengine_is_valid_voice_cb; engine_callback.set_pitch = ttsengine_set_pitch_cb; engine_callback.load_voice = ttsengine_load_voice_cb; engine_callback.unload_voice = ttsengine_unload_voice_cb; engine_callback.start_synth = ttsengine_start_synthesis_cb; engine_callback.cancel_synth = ttsengine_cancel_synthesis_cb; engine_callback.check_app_agreed = ttsengine_check_app_agreed_cb; engine_callback.need_app_credential = ttsengine_need_app_credential_cb; // 2. Run 'ttse_main()' if (0 != ttse_main(argc, argv, &engine_callback)) { return -1; } // Optional ttse_set_private_data_set_cb(ttsengine_private_data_set_cb); // 3. Set event callbacks for service app and Run 'service_app_main()' char ad[50] = { 0, }; service_app_lifecycle_callback_s event_callback; app_event_handler_h handlers[5] = { NULL, }; event_callback.create = service_app_create; event_callback.terminate = service_app_terminate; event_callback.app_control = service_app_control; service_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, service_app_low_battery, &ad); service_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, service_app_low_memory, &ad); service_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, service_app_lang_changed, &ad); service_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, service_app_region_changed, &ad); return service_app_main(argc, argv, &event_callback, ad); }
int ttse_send_error | ( | ttse_error_e | error, |
const char * | msg | ||
) |
Sends the error to the engine service user.
The following error codes can be delivered. TTSE_ERROR_NONE, TTSE_ERROR_OUT_OF_MEMORY, TTSE_ERROR_IO_ERROR, TTSE_ERROR_INVALID_PARAMETER, TTSE_ERROR_NETWORK_DOWN, TTSE_ERROR_PERMISSION_DENIED, TTSE_ERROR_INVALID_STATE, TTSE_ERROR_INVALID_VOICE, TTSE_ERROR_OPERATION_FAILED, TTSE_ERROR_NOT_SUPPORTED_FEATURE, TTSE_ERROR_NOT_SUPPORTED.
[in] | error | The error reason |
[in] | msg | The error message |
0
on success, otherwise a negative error value TTSE_ERROR_NONE | Successful |
TTSE_ERROR_INVALID_PARAMETER | Invalid parameter |
TTSE_ERROR_NOT_SUPPORTED | Not supported |
TTSE_ERROR_OPERATION_FAILED | Operation failure |
int ttse_send_result | ( | ttse_result_event_e | event, |
const void * | data, | ||
unsigned int | data_size, | ||
ttse_audio_type_e | audio_type, | ||
int | rate, | ||
void * | user_data | ||
) |
Sends the synthesized result to the engine service user.
[in] | event | The result event |
[in] | data | Result data |
[in] | data_size | Result data size |
[in] | audio_type | The audio type |
[in] | rate | The sample rate |
[in] | user_data | The user data passed from ttse_start_synthesis_cb() |
0
on success, otherwise a negative error value TTSE_ERROR_NONE | Successful |
TTSE_ERROR_INVALID_PARAMETER | Invalid parameter |
TTSE_ERROR_NOT_SUPPORTED | Not supported |
TTSE_ERROR_OPERATION_FAILED | Operation failure |
int ttse_set_private_data_requested_cb | ( | ttse_private_data_requested_cb | callback_func | ) |
Sets a callback function for requesting the private data.
[in] | callback_func | ttse_private_data_requested event callback function |
0
on success, otherwise a negative error value TTSE_ERROR_NONE | Successful |
TTSE_ERROR_INVALID_PARAMETER | Invalid parameter |
TTSE_ERROR_NOT_SUPPORTED | Not supported |
TTSE_ERROR_OPERATION_FAILED | Operation failure |
int ttse_set_private_data_set_cb | ( | ttse_private_data_set_cb | callback_func | ) |
Sets a callback function for setting the private data.
[in] | callback_func | ttse_private_data_set event callback function |
0
on success, otherwise a negative error value TTSE_ERROR_NONE | Successful |
TTSE_ERROR_INVALID_PARAMETER | Invalid parameter |
TTSE_ERROR_NOT_SUPPORTED | Not supported |
TTSE_ERROR_OPERATION_FAILED | Operation failure |