Add new function for a synthesis parameter 55/306955/4
authorSuyeon Hwang <stom.hwang@samsung.com>
Wed, 28 Feb 2024 07:11:48 +0000 (16:11 +0900)
committersungwook79.park <sungwook79.park@samsung.com>
Thu, 18 Apr 2024 01:42:50 +0000 (10:42 +0900)
- Requirements:
The app needs to play each utterance with different configuration such
as pitch, speed, volume, or background volume.

- Contents:
This patch adds new function for a synthesis parameter. The synthesis
parameter is newly introduced by this patch. Using current API, the
client can only change the speed value using fixed parameter of
tts_add_text() function. The synthesis parameter is a kind of handle, so
client can set various configuration value using provided setter
functions. The client can manages the synthesis parameter with related
functions and these functions will be expandable.
Thus, through this change, TTS framework will provides changable
configuration for each utterance.

Change-Id: I7c15d72e253e047b45ec03424e4a729d95007843
Signed-off-by: Suyeon Hwang <stom.hwang@samsung.com>
client/tts.c
client/tts_main.h
include/tts_internal.h

index c66b02dccc7a832d874c672e580ee6be62eae55c..f337ea62962816b0ddf6cd7787d79fcd51b0cbd3 100644 (file)
@@ -1417,4 +1417,143 @@ int tts_unset_synthesized_pcm_cb(tts_h tts)
 
        SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Unset synthesized pcm cb");
        return TTS_ERROR_NONE;
-}
\ No newline at end of file
+}
+
+
+int tts_synthesis_parameter_create(tts_synthesis_parameter_h *parameter)
+{
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Create TTS synthesis parameter handle");
+       RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
+
+       RETVM_IF(NULL == parameter, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input handle is null");
+
+       tts_synthesis_parameter_h new_parameter = (tts_synthesis_parameter_h)calloc(1, sizeof(struct tts_synthesis_parameter_s));
+       RETVM_IF(NULL == new_parameter, TTS_ERROR_OUT_OF_MEMORY, "[ERROR] Fail to allocate memory for a handle");
+
+       *parameter = new_parameter;
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Create a handle for a synthesis parameter");
+       return TTS_ERROR_NONE;
+}
+
+int tts_synthesis_parameter_destroy(tts_synthesis_parameter_h parameter)
+{
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Destroy TTS synthesis parameter handle");
+       RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
+
+       RETVM_IF(NULL == parameter, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input handle is null");
+
+       free(parameter->langauge);
+       parameter->langauge = NULL;
+       free(parameter->ptts_id);
+       parameter->ptts_id = NULL;
+
+       free(parameter);
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Destroy the handle for a synthesis parameter");
+       return TTS_ERROR_NONE;
+}
+
+int tts_synthesis_parameter_set_language(tts_synthesis_parameter_h parameter, const char *language)
+{
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Set language to a synthesis parameter");
+       RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
+
+       RETVM_IF(NULL == parameter || NULL == language, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input handle is null");
+
+       char *new_langauge = strdup(language);
+       RETVM_IF(NULL == new_langauge, TTS_ERROR_OUT_OF_MEMORY, "[ERROR] Fail to allocate memory for language");
+
+       free(parameter->langauge);
+       parameter->langauge = new_langauge;
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set language(%s) to a synthesis parameter", language);
+       return TTS_ERROR_NONE;
+}
+
+int tts_synthesis_parameter_set_voice_type(tts_synthesis_parameter_h parameter, int voice_type)
+{
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Set voice type to a synthesis parameter");
+       RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
+
+       RETVM_IF(NULL == parameter, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input handle is null");
+       RETVM_IF(voice_type < 0, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Voice type should not be negative(%d)", voice_type);
+
+       parameter->voice_type = voice_type;
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set voice type(%d) to a synthesis parameter", voice_type);
+       return TTS_ERROR_NONE;
+}
+
+int tts_synthesis_parameter_set_personal_voice(tts_synthesis_parameter_h parameter, const char *ptts_id)
+{
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Set personal voice id to a synthesis parameter");
+       RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
+
+       RETVM_IF(NULL == parameter || NULL == ptts_id, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input handle is null");
+
+       char *new_ptts_id = strdup(ptts_id);
+       RETVM_IF(NULL == new_ptts_id, TTS_ERROR_OUT_OF_MEMORY, "[ERROR] Fail to allocate memory for personal voice id");
+
+       free(parameter->ptts_id);
+       parameter->ptts_id = new_ptts_id;
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set personal voice id(%s) to a synthesis parameter", ptts_id);
+       return TTS_ERROR_NONE;
+}
+
+int tts_synthesis_parameter_set_speed(tts_synthesis_parameter_h parameter, int speed)
+{
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Set speed to a synthesis parameter");
+       RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
+
+       RETVM_IF(NULL == parameter, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input handle is null");
+       RETVM_IF(TTS_SPEED_AUTO > speed || TTS_SPEED_MAX < speed, TTS_ERROR_INVALID_PARAMETER, "[ERROR] speed value(%d) is invalid.", speed);
+
+       parameter->speed = speed;
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set speed(%d) to a synthesis parameter", speed);
+       return TTS_ERROR_NONE;
+}
+
+int tts_synthesis_parameter_set_pitch(tts_synthesis_parameter_h parameter, int pitch)
+{
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Set pitch to a synthesis parameter");
+       RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
+
+       RETVM_IF(NULL == parameter, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input handle is null");
+       RETVM_IF(TTS_PITCH_AUTO > pitch || TTS_PITCH_MAX < pitch, TTS_ERROR_INVALID_PARAMETER, "[ERROR] pitch value(%d) is invalid.", pitch);
+
+       parameter->pitch = pitch;
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set pitch(%d) to a synthesis parameter", pitch);
+       return TTS_ERROR_NONE;
+}
+
+int tts_synthesis_parameter_set_volume(tts_synthesis_parameter_h parameter, double volume)
+{
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Set volume to a synthesis parameter");
+       RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
+
+       RETVM_IF(NULL == parameter, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input handle is null");
+       RETVM_IF(0.0 > volume || 1.0 < volume, TTS_ERROR_INVALID_PARAMETER, "[ERROR] volume value(%f) is invalid.", volume);
+
+       parameter->volume = volume;
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set volume(%f) to a synthesis parameter", volume);
+       return TTS_ERROR_NONE;
+}
+
+int tts_synthesis_parameter_set_background_volume_ratio(tts_synthesis_parameter_h parameter, double background_volume_ratio)
+{
+       SLOG(LOG_INFO, TAG_TTSC, "@@@ Set background volume ratio to a synthesis parameter");
+       RETV_IF(TTS_ERROR_NONE != __tts_get_feature_enabled(), TTS_ERROR_NOT_SUPPORTED);
+
+       RETVM_IF(NULL == parameter, TTS_ERROR_INVALID_PARAMETER, "[ERROR] Input handle is null");
+       RETVM_IF(0.0 > background_volume_ratio || 1.0 < background_volume_ratio, TTS_ERROR_INVALID_PARAMETER, "[ERROR] background volume value ratio(%f) is invalid.", background_volume_ratio);
+
+       parameter->background_volume_ratio = background_volume_ratio;
+
+       SLOG(LOG_DEBUG, TAG_TTSC, "[SUCCESS] Set background volume ratio(%f) to a synthesis parameter", background_volume_ratio);
+       return TTS_ERROR_NONE;
+}
index 4fea211ea49494597f608a8ba84492828ecfa097..97553a671b17b6b2295f874561f687b2a5de08ec 100644 (file)
@@ -37,6 +37,20 @@ struct tts_s {
        unsigned int handle;
 };
 
+
+/**
+* @brief A structure of handle for synthesis paramter
+*/
+struct tts_synthesis_parameter_s {
+       char *langauge;
+       char *ptts_id;
+       int voice_type;
+       int speed;
+       int pitch;
+       double volume;
+       double background_volume_ratio;
+};
+
 #ifdef __cplusplus
 }
 #endif
index d92275e2b4a1fde964b04dbd569ed5fd13336a2e..859c22f374ede68d423aa73919d8049c0c7b5cf6 100644 (file)
@@ -33,6 +33,24 @@ extern "C"
  */
 #define TTS_MODE_INTERRUPT             3
 
+/**
+ * @brief Definition for automatic speaking pitch.
+ * @since_tizen 9.0
+*/
+#define TTS_PITCH_AUTO         0
+
+/**
+ * @brief Definition for personal voice type.
+ * @since_tizen 9.0
+*/
+#define TTS_VOICE_TYPE_PERSONAL  4
+
+/**
+ * @brief The TTS synthesis parameter handle.
+ * @since_tizen 9.0
+*/
+typedef struct tts_synthesis_parameter_s *tts_synthesis_parameter_h;
+
 
 /**
  * @brief Sets server tts.
@@ -122,6 +140,192 @@ int tts_play_pcm(tts_h tts);
 */
 int tts_stop_pcm(tts_h tts);
 
+/**
+ * @brief Creates a handle for TTS synthesis paramter.
+ * @since_tizen 9.0
+ * @remarks If the function succeeds, @a paramter handle must be released with tts_synthesis_parameter_destroy().
+ * @param[out] parameter The TTS synthesis parameter handle
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #TTS_ERROR_NONE Successful
+ * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
+ * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TTS_ERROR_OUT_OF_MEMORY Out of memory
+ * @see tts_synthesis_parameter_destroy()
+*/
+int tts_synthesis_parameter_create(tts_synthesis_parameter_h *parameter);
+
+/**
+ * @brief Destroys the TTS synthesis paramter handle.
+ * @since_tizen 9.0
+ * @param[in] parameter The TTS synthesis parameter handle
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #TTS_ERROR_NONE Successful
+ * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
+ * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see tts_synthesis_parameter_create()
+*/
+int tts_synthesis_parameter_destroy(tts_synthesis_parameter_h parameter);
+
+/**
+ * @brief Sets the language.
+ * @since_tizen 9.0
+ * @param[in] parameter The TTS synthesis parameter handle
+ * @param[in] language The language selected from the tts_foreach_supported_voices() (e.g. 'NULL'(Automatic), 'en_US')
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #TTS_ERROR_NONE Successful
+ * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
+ * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
+ * @retval #TTS_ERROR_OUT_OF_MEMORY Out of memory
+*/
+int tts_synthesis_parameter_set_language(tts_synthesis_parameter_h parameter, const char *language);
+
+/**
+ * @brief Sets the voice type.
+ * @since_tizen 9.0
+ * @param[in] parameter The TTS synthesis parameter handle
+ * @param[in] voice_type The voice type selected from the tts_foreach_supported_voices() (e.g. #TTS_VOICE_TYPE_AUTO, #TTS_VOICE_TYPE_FEMALE)
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #TTS_ERROR_NONE Successful
+ * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
+ * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
+*/
+int tts_synthesis_parameter_set_voice_type(tts_synthesis_parameter_h parameter, int voice_type);
+
+/**
+ * @brief Sets the id for personal voice data.
+ * @since_tizen 9.0
+ * @param[in] parameter The TTS synthesis parameter handle
+ * @param[in] ptts_id The id for personal voice data
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #TTS_ERROR_NONE Successful
+ * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
+ * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TTS_ERROR_OUT_OF_MEMORY Out of memory
+*/
+int tts_synthesis_parameter_set_personal_voice(tts_synthesis_parameter_h parameter, const char *ptts_id);
+
+/**
+ * @brief Sets the speed.
+ * @since_tizen 9.0
+ * @param[in] parameter The TTS synthesis parameter handle
+ * @param[in] speed A speaking speed (e.g. #TTS_SPEED_AUTO or the value from tts_get_speed_range())
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #TTS_ERROR_NONE Successful
+ * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
+ * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see tts_get_speed_range()
+*/
+int tts_synthesis_parameter_set_speed(tts_synthesis_parameter_h parameter, int speed);
+
+/**
+ * @brief Sets the pitch.
+ * @since_tizen 9.0
+ * @param[in] parameter The TTS synthesis parameter handle
+ * @param[in] pitch A speaking pitch (e.g. #TTS_PITCH_AUTO or the value from tts_get_pitch_range())
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #TTS_ERROR_NONE Successful
+ * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
+ * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see tts_get_pitch_range()
+*/
+int tts_synthesis_parameter_set_pitch(tts_synthesis_parameter_h parameter, int pitch);
+
+/**
+ * @brief Sets the volume.
+ * @since_tizen 9.0
+ * @param[in] parameter The TTS synthesis parameter handle
+ * @param[in] volume A speaking volume ratio (e.g. #TTS_VOLUME_AUTO or the value from tts_get_volume_range())
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #TTS_ERROR_NONE Successful
+ * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
+ * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see tts_get_volume_range()
+*/
+int tts_synthesis_parameter_set_volume(tts_synthesis_parameter_h parameter, double volume);
+
+/**
+ * @brief Sets the background volume ratio.
+ * @since_tizen 9.0
+ * @param[in] parameter The TTS synthesis parameter handle
+ * @param[in] background_volume_ratio A background volume ratio ratio (Range 0.0 ~ 1.0)
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #TTS_ERROR_NONE Successful
+ * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
+ * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
+*/
+int tts_synthesis_parameter_set_background_volume_ratio(tts_synthesis_parameter_h parameter, double background_volume_ratio);
+
+/**
+ * @brief Gets the pitch range.
+ * @since_tizen 9.0
+ * @param[in] tts The TTS handle
+ * @param[out] min The minimum pitch value
+ * @param[out] normal The normal pitch value
+ * @param[out] max The maximum pitch value
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #TTS_ERROR_NONE Successful
+ * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
+ * @retval #TTS_ERROR_NOT_SUPPORTED_FEATURE Not supported feature.
+ * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TTS_ERROR_INVALID_STATE Invalid state
+ * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
+ * @pre The state should be #TTS_STATE_READY.
+ * @see tts_synthesis_parameter_set_pitch()
+*/
+int tts_get_pitch_range(tts_h tts, int* min, int* normal, int* max);
+
+/**
+ * @brief Gets the volume range.
+ * @since_tizen 9.0
+ * @param[in] tts The TTS handle
+ * @param[out] min The minimum volume value
+ * @param[out] max The maximum volume value
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #TTS_ERROR_NONE Successful
+ * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
+ * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TTS_ERROR_INVALID_STATE Invalid state
+ * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
+ * @pre The state should be #TTS_STATE_READY.
+ * @see tts_synthesis_parameter_set_volume()
+*/
+int tts_get_volume_range(tts_h tts, int* min, int* max);
+
+/**
+ * @brief Adds a text to the queue with synthesis parameter.
+ * @since_tizen 9.0
+ * @remarks Locale(e.g. setlocale()) MUST be set for utf8 text validation check.
+ * @param[in] tts The TTS handle
+ * @param[in] text An input text based utf8
+ * @param[in] parameter The TTS synthesis parameter handle
+ * @param[out] utt_id The utterance ID passed to the callback function
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #TTS_ERROR_NONE Successful
+ * @retval #TTS_ERROR_NOT_SUPPORTED TTS NOT supported
+ * @retval #TTS_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #TTS_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #TTS_ERROR_INVALID_STATE Invalid state
+ * @retval #TTS_ERROR_INVALID_VOICE Invalid voice about language, voice type
+ * @retval #TTS_ERROR_OPERATION_FAILED Operation failure
+ * @retval #TTS_ERROR_SCREEN_READER_OFF Screen reader is turned off
+ * @pre The state should be #TTS_STATE_READY, #TTS_STATE_PLAYING or #TTS_STATE_PAUSED.
+ * @see tts_get_max_text_size()
+ * @see tts_set_credential()
+*/
+int tts_add_text_with_synthesis_parameter(tts_h tts, const char* text, tts_synthesis_parameter_h parameter, int* utt_id);
 
 #ifdef __cplusplus
 }