diff --git a/mod_playht_tts/mod_playht_tts.c b/mod_playht_tts/mod_playht_tts.c index 8d4bb23..3c71998 100644 --- a/mod_playht_tts/mod_playht_tts.c +++ b/mod_playht_tts/mod_playht_tts.c @@ -14,6 +14,10 @@ static void clearPlayht(playht_t* p, int freeAll) { if (p->seed) free(p->seed); if (p->temperature) free(p->temperature); if (p->voice_engine) free(p->voice_engine); + if (p->synthesize_url) free(p->synthesize_url); + if (p->language) free(p->language); + if (p->top_p) free(p->top_p); + if (p->repetition_penalty) free(p->repetition_penalty); if (p->emotion) free(p->emotion); if (p->voice_guidance) free(p->voice_guidance); if (p->style_guidance) free(p->style_guidance); @@ -36,6 +40,10 @@ static void clearPlayht(playht_t* p, int freeAll) { p->seed = NULL; p->temperature = NULL; p->voice_engine = NULL; + p->synthesize_url = NULL; + p->language = NULL; + p->top_p = NULL; + p->repetition_penalty = NULL; p->emotion = NULL; p->voice_guidance = NULL; p->style_guidance = NULL; @@ -154,6 +162,18 @@ static void p_text_param_tts(switch_speech_handle_t *sh, char *param, const char } else if (0 == strcmp(param, "voice_engine")) { if (p->voice_engine) free(p->voice_engine); p->voice_engine = strdup(val); + } else if (0 == strcmp(param, "synthesize_url")) { + if (p->synthesize_url) free(p->synthesize_url); + p->synthesize_url = strdup(val); + } else if (0 == strcmp(param, "language")) { + if (p->language) free(p->language); + p->language = strdup(val); + } else if (0 == strcmp(param, "top_p")) { + if (p->top_p) free(p->top_p); + p->top_p = strdup(val); + } else if (0 == strcmp(param, "repetition_penalty")) { + if (p->repetition_penalty) free(p->repetition_penalty); + p->repetition_penalty = strdup(val); } else if (0 == strcmp(param, "emotion")) { if (p->emotion) free(p->emotion); p->emotion = strdup(val); diff --git a/mod_playht_tts/mod_playht_tts.h b/mod_playht_tts/mod_playht_tts.h index 5d44cb1..1f1bfcd 100644 --- a/mod_playht_tts/mod_playht_tts.h +++ b/mod_playht_tts/mod_playht_tts.h @@ -11,10 +11,14 @@ typedef struct playht_data { char *seed; char *temperature; char *voice_engine; + char *synthesize_url; + char *language; char *emotion; char *voice_guidance; char *style_guidance; char *text_guidance; + char *top_p; + char *repetition_penalty; /* result data */ long response_code; diff --git a/mod_playht_tts/playht_glue.cpp b/mod_playht_tts/playht_glue.cpp index 01e468f..42d163d 100644 --- a/mod_playht_tts/playht_glue.cpp +++ b/mod_playht_tts/playht_glue.cpp @@ -780,7 +780,7 @@ extern "C" { } /* format url*/ - std::string url = "https://api.play.ht/api/v2/tts/stream"; + std::string url = p->synthesize_url; /* create the JSON body */ cJSON * jResult = cJSON_CreateObject(); @@ -800,9 +800,6 @@ extern "C" { cJSON_AddNumberToObject(jResult, "speed", val); } } - if (p->seed) { - cJSON_AddNumberToObject(jResult, "seed", atoi(p->seed)); - } if (p->temperature) { cJSON_AddNumberToObject(jResult, "temperature", std::strtof(p->temperature, nullptr)); } @@ -818,6 +815,15 @@ extern "C" { if (p->text_guidance) { cJSON_AddNumberToObject(jResult, "text_guidance", atoi(p->text_guidance)); } + if (strcmp(p->voice_engine, "Play3.0") == 0 && p->language) { + cJSON_AddStringToObject(jResult, "language", p->language); + } + if (p->repetition_penalty) { + cJSON_AddNumberToObject(jResult, "repetition_penalty", std::strtof(p->repetition_penalty, nullptr)); + } + if (p->top_p) { + cJSON_AddNumberToObject(jResult, "top_p", std::strtof(p->top_p, nullptr)); + } char *json = cJSON_PrintUnformatted(jResult); cJSON_Delete(jResult); @@ -889,9 +895,12 @@ extern "C" { /* call this function to close a socket */ curl_easy_setopt(easy, CURLOPT_CLOSESOCKETFUNCTION, close_socket); + // Play3.0 voice engine doesn't need authorization + if (strcmp(p->voice_engine, "Play3.0") != 0) { + conn->hdr_list = curl_slist_append(conn->hdr_list, api_key_stream.str().c_str()); + conn->hdr_list = curl_slist_append(conn->hdr_list, user_id_stream.str().c_str()); + } - conn->hdr_list = curl_slist_append(conn->hdr_list, api_key_stream.str().c_str()); - conn->hdr_list = curl_slist_append(conn->hdr_list, user_id_stream.str().c_str()); conn->hdr_list = curl_slist_append(conn->hdr_list, "Accept: audio/mpeg"); conn->hdr_list = curl_slist_append(conn->hdr_list, "Content-Type: application/json"); curl_easy_setopt(easy, CURLOPT_HTTPHEADER, conn->hdr_list);