support playht3.0 (#119)

* support playht3.0

* update language

* wip

* update top_p and repetition_penalty

---------

Co-authored-by: root <root@af6633a5cfe8>
This commit is contained in:
Hoan Luu Huu
2024-10-09 23:12:59 +07:00
committed by GitHub
parent ffde303446
commit 30f2189986
3 changed files with 39 additions and 6 deletions

View File

@@ -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);

View File

@@ -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;

View File

@@ -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);