From 3f642467ebdddce3293303be59f8566dca448315 Mon Sep 17 00:00:00 2001 From: Hoan Luu Huu <110280845+xquanluu@users.noreply.github.com> Date: Sun, 14 Apr 2024 20:13:54 +0700 Subject: [PATCH] add properties to tts span for mod_*_tts (#45) * add properties to tts span for mod_*_tts Signed-off-by: Hoan HL * support deepgram tts span Signed-off-by: Hoan HL * support tts span for playht Signed-off-by: Hoan HL * support rimelabs tts span Signed-off-by: Hoan HL --------- Signed-off-by: Hoan HL --- mod_deepgram_tts/deepgram_glue.cpp | 13 +++++++++++-- mod_deepgram_tts/mod_deepgram_tts.c | 8 ++++++-- mod_deepgram_tts/mod_deepgram_tts.h | 9 ++++++++- mod_playht_tts/mod_playht_tts.c | 2 -- mod_playht_tts/mod_playht_tts.h | 1 - mod_playht_tts/playht_glue.cpp | 6 +----- mod_rimelabs_tts/mod_rimelabs_tts.c | 4 ---- mod_rimelabs_tts/mod_rimelabs_tts.h | 2 -- mod_rimelabs_tts/rimelabs_glue.cpp | 7 ------- mod_whisper_tts/mod_whisper_tts.c | 8 ++++++++ mod_whisper_tts/mod_whisper_tts.h | 11 +++++++++++ mod_whisper_tts/whisper_glue.cpp | 16 ++++++++++++++++ 12 files changed, 61 insertions(+), 26 deletions(-) diff --git a/mod_deepgram_tts/deepgram_glue.cpp b/mod_deepgram_tts/deepgram_glue.cpp index 4a87e82..8595ef2 100644 --- a/mod_deepgram_tts/deepgram_glue.cpp +++ b/mod_deepgram_tts/deepgram_glue.cpp @@ -470,8 +470,14 @@ static size_t write_cb(void *ptr, size_t size, size_t nmemb, ConnInfo_t *conn) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "write_cb: firing playback-started\n"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Playback-File-Type", "tts_stream"); - if (d->reported_latency) { - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "variable_tts_deepgram_reported_latency_ms", d->reported_latency); + if (d->reported_model_name) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "variable_tts_deepgram_reported_model_name", d->reported_model_name); + } + if (d->reported_model_uuid) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "variable_tts_deepgram_reported_model_uuid", d->reported_model_uuid); + } + if (d->reported_char_count) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "variable_tts_deepgram_reported_char_count", d->reported_char_count); } if (d->request_id) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "variable_tts_deepgram_request_id", d->request_id); @@ -549,6 +555,9 @@ static size_t header_callback(char *buffer, size_t size, size_t nitems, ConnInfo if (parseHeader(input, header, value)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "recv header: %s with value %s\n", header.c_str(), value.c_str()); if (0 == header.compare("dg-request-id")) d->request_id = strdup(value.c_str()); + else if (0 == header.compare("dg-model-name")) d->reported_model_name = strdup(value.c_str()); + else if (0 == header.compare("dg-model-uuid")) d->reported_model_uuid = strdup(value.c_str()); + else if (0 == header.compare("dg-char-count")) d->reported_char_count = strdup(value.c_str()); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "header_callback: %s\n", input.c_str()); diff --git a/mod_deepgram_tts/mod_deepgram_tts.c b/mod_deepgram_tts/mod_deepgram_tts.c index 1819719..6e157b6 100644 --- a/mod_deepgram_tts/mod_deepgram_tts.c +++ b/mod_deepgram_tts/mod_deepgram_tts.c @@ -10,7 +10,9 @@ static void cleardeepgram(deepgram_t* d, int freeAll) { if (d->api_key) free(d->api_key); if (d->request_id) free(d->request_id); - if (d->reported_latency) free(d->reported_latency); + if (d->reported_model_name) free(d->reported_model_name); + if (d->reported_model_uuid) free(d->reported_model_uuid); + if (d->reported_char_count) free(d->reported_char_count); if (d->ct) free(d->ct); if (d->err_msg) free(d->err_msg); if (d->name_lookup_time_ms) free(d->name_lookup_time_ms); @@ -22,7 +24,9 @@ static void cleardeepgram(deepgram_t* d, int freeAll) { d->api_key = NULL; d->request_id = NULL; - d->reported_latency = NULL; + d->reported_model_name = NULL; + d->reported_model_uuid = NULL; + d->reported_char_count = NULL; d->ct = NULL; d->err_msg = NULL; d->name_lookup_time_ms = NULL; diff --git a/mod_deepgram_tts/mod_deepgram_tts.h b/mod_deepgram_tts/mod_deepgram_tts.h index 967d26c..3bb4218 100644 --- a/mod_deepgram_tts/mod_deepgram_tts.h +++ b/mod_deepgram_tts/mod_deepgram_tts.h @@ -11,7 +11,14 @@ typedef struct deepgram_data { /* result data */ long response_code; char *ct; - char *reported_latency; + // Deepgram hedaers + //dg-model-name + char *reported_model_name; + //dg-model-uuid + char *reported_model_uuid; + //dg-char-count + char *reported_char_count; + //dg-request-id char *request_id; char *name_lookup_time_ms; char *connect_time_ms; diff --git a/mod_playht_tts/mod_playht_tts.c b/mod_playht_tts/mod_playht_tts.c index 6345e68..d81ef98 100644 --- a/mod_playht_tts/mod_playht_tts.c +++ b/mod_playht_tts/mod_playht_tts.c @@ -21,7 +21,6 @@ static void clearPlayht(playht_t* p, int freeAll) { if (p->request_id) free(p->request_id); - if (p->reported_latency) free(p->reported_latency); if (p->ct) free(p->ct); if (p->err_msg) free(p->err_msg); if (p->name_lookup_time_ms) free(p->name_lookup_time_ms); @@ -43,7 +42,6 @@ static void clearPlayht(playht_t* p, int freeAll) { p->text_guidance = NULL; p->request_id = NULL; - p->reported_latency = NULL; p->ct = NULL; p->err_msg = NULL; p->name_lookup_time_ms = NULL; diff --git a/mod_playht_tts/mod_playht_tts.h b/mod_playht_tts/mod_playht_tts.h index 7f4e1bc..5c355ac 100644 --- a/mod_playht_tts/mod_playht_tts.h +++ b/mod_playht_tts/mod_playht_tts.h @@ -19,7 +19,6 @@ typedef struct playht_data { /* result data */ long response_code; char *ct; - char *reported_latency; char *request_id; char *name_lookup_time_ms; char *connect_time_ms; diff --git a/mod_playht_tts/playht_glue.cpp b/mod_playht_tts/playht_glue.cpp index a339c17..fdae82a 100644 --- a/mod_playht_tts/playht_glue.cpp +++ b/mod_playht_tts/playht_glue.cpp @@ -489,9 +489,6 @@ static size_t write_cb(void *ptr, size_t size, size_t nmemb, ConnInfo_t *conn) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "write_cb: firing playback-started\n"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Playback-File-Type", "tts_stream"); - if (p->reported_latency) { - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "variable_tts_playht_reported_latency_ms", p->reported_latency); - } if (p->request_id) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "variable_tts_playht_request_id", p->request_id); } @@ -567,8 +564,7 @@ static size_t header_callback(char *buffer, size_t size, size_t nitems, ConnInfo std::string input(buffer, bytes_received); if (parseHeader(input, header, value)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "recv header: %s with value %s\n", header.c_str(), value.c_str()); - if (0 == header.compare("openai-processing-ms")) p->reported_latency = strdup(value.c_str()); - else if (0 == header.compare("x-request-id")) p->request_id = strdup(value.c_str()); + if (0 == header.compare("x-job-ids")) p->request_id = strdup(value.c_str()); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "header_callback: %s\n", input.c_str()); diff --git a/mod_rimelabs_tts/mod_rimelabs_tts.c b/mod_rimelabs_tts/mod_rimelabs_tts.c index 0c854ff..63ffb04 100644 --- a/mod_rimelabs_tts/mod_rimelabs_tts.c +++ b/mod_rimelabs_tts/mod_rimelabs_tts.c @@ -12,8 +12,6 @@ static void clearrimelabs(rimelabs_t* d, int freeAll) { if (d->speed_alpha) free(d->speed_alpha); if (d->reduce_latency) free(d->reduce_latency); - if (d->request_id) free(d->request_id); - if (d->reported_latency) free(d->reported_latency); if (d->ct) free(d->ct); if (d->err_msg) free(d->err_msg); if (d->name_lookup_time_ms) free(d->name_lookup_time_ms); @@ -27,8 +25,6 @@ static void clearrimelabs(rimelabs_t* d, int freeAll) { d->speed_alpha = NULL; d->reduce_latency = NULL; - d->request_id = NULL; - d->reported_latency = NULL; d->ct = NULL; d->err_msg = NULL; d->name_lookup_time_ms = NULL; diff --git a/mod_rimelabs_tts/mod_rimelabs_tts.h b/mod_rimelabs_tts/mod_rimelabs_tts.h index 1190838..b930eb7 100644 --- a/mod_rimelabs_tts/mod_rimelabs_tts.h +++ b/mod_rimelabs_tts/mod_rimelabs_tts.h @@ -14,8 +14,6 @@ typedef struct rimelabs_data { /* result data */ long response_code; char *ct; - char *reported_latency; - char *request_id; char *name_lookup_time_ms; char *connect_time_ms; char *final_response_time_ms; diff --git a/mod_rimelabs_tts/rimelabs_glue.cpp b/mod_rimelabs_tts/rimelabs_glue.cpp index dade5d1..308ceac 100644 --- a/mod_rimelabs_tts/rimelabs_glue.cpp +++ b/mod_rimelabs_tts/rimelabs_glue.cpp @@ -471,12 +471,6 @@ static size_t write_cb(void *ptr, size_t size, size_t nmemb, ConnInfo_t *conn) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "write_cb: firing playback-started\n"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Playback-File-Type", "tts_stream"); - if (d->reported_latency) { - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "variable_tts_rimelabs_reported_latency_ms", d->reported_latency); - } - if (d->request_id) { - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "variable_tts_rimelabs_request_id", d->request_id); - } if (d->name_lookup_time_ms) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "variable_tts_rimelabs_name_lookup_time_ms", d->name_lookup_time_ms); } @@ -549,7 +543,6 @@ static size_t header_callback(char *buffer, size_t size, size_t nitems, ConnInfo std::string input(buffer, bytes_received); if (parseHeader(input, header, value)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "recv header: %s with value %s\n", header.c_str(), value.c_str()); - if (0 == header.compare("dg-request-id")) d->request_id = strdup(value.c_str()); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "header_callback: %s\n", input.c_str()); diff --git a/mod_whisper_tts/mod_whisper_tts.c b/mod_whisper_tts/mod_whisper_tts.c index 609a616..246d096 100644 --- a/mod_whisper_tts/mod_whisper_tts.c +++ b/mod_whisper_tts/mod_whisper_tts.c @@ -12,6 +12,10 @@ static void clearWhisper(whisper_t* w, int freeAll) { if (w->speed) free(w->speed); if (w->request_id) free(w->request_id); if (w->reported_latency) free(w->reported_latency); + if (w->reported_organization) free(w->reported_organization); + if (w->reported_ratelimit_requests) free(w->reported_ratelimit_requests); + if (w->reported_ratelimit_remaining_requests) free(w->reported_ratelimit_remaining_requests); + if (w->reported_ratelimit_reset_requests) free(w->reported_ratelimit_reset_requests); if (w->ct) free(w->ct); if (w->err_msg) free(w->err_msg); if (w->name_lookup_time_ms) free(w->name_lookup_time_ms); @@ -25,6 +29,10 @@ static void clearWhisper(whisper_t* w, int freeAll) { w->speed = NULL; w->request_id = NULL; w->reported_latency = NULL; + w->reported_organization = NULL; + w->reported_ratelimit_requests = NULL; + w->reported_ratelimit_remaining_requests = NULL; + w->reported_ratelimit_reset_requests = NULL; w->ct = NULL; w->err_msg = NULL; w->name_lookup_time_ms = NULL; diff --git a/mod_whisper_tts/mod_whisper_tts.h b/mod_whisper_tts/mod_whisper_tts.h index 2ebd1e5..0a0e4da 100644 --- a/mod_whisper_tts/mod_whisper_tts.h +++ b/mod_whisper_tts/mod_whisper_tts.h @@ -11,7 +11,18 @@ typedef struct whisper_data { /* result data */ long response_code; char *ct; + //whisper headers + //openai-organization + char *reported_organization; + //openai-processing-ms char *reported_latency; + //x-ratelimit-limit-requests + char *reported_ratelimit_requests; + //x-ratelimit-remaining-requests + char *reported_ratelimit_remaining_requests; + //x-ratelimit-reset-requests + char *reported_ratelimit_reset_requests; + //x-request-id char *request_id; char *name_lookup_time_ms; char *connect_time_ms; diff --git a/mod_whisper_tts/whisper_glue.cpp b/mod_whisper_tts/whisper_glue.cpp index 99170bb..f153889 100644 --- a/mod_whisper_tts/whisper_glue.cpp +++ b/mod_whisper_tts/whisper_glue.cpp @@ -495,6 +495,18 @@ static size_t write_cb(void *ptr, size_t size, size_t nmemb, ConnInfo_t *conn) { if (w->request_id) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "variable_tts_whisper_request_id", w->request_id); } + if (w->reported_organization) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "variable_tts_whisper_reported_organization", w->reported_latency); + } + if (w->reported_ratelimit_requests) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "variable_tts_whisper_reported_ratelimit_requests", w->reported_ratelimit_requests); + } + if (w->reported_ratelimit_remaining_requests) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "variable_tts_whisper_reported_ratelimit_remaining_requests", w->reported_ratelimit_remaining_requests); + } + if (w->reported_ratelimit_reset_requests) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "variable_tts_whisper_reported_ratelimit_reset_requests", w->reported_ratelimit_reset_requests); + } if (w->name_lookup_time_ms) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "variable_tts_whisper_name_lookup_time_ms", w->name_lookup_time_ms); } @@ -572,6 +584,10 @@ static size_t header_callback(char *buffer, size_t size, size_t nitems, ConnInfo switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "recv header: %s with value %s\n", header.c_str(), value.c_str()); if (0 == header.compare("openai-processing-ms")) w->reported_latency = strdup(value.c_str()); else if (0 == header.compare("x-request-id")) w->request_id = strdup(value.c_str()); + else if (0 == header.compare("openai-organization")) w->reported_organization = strdup(value.c_str()); + else if (0 == header.compare("x-ratelimit-limit-requests")) w->reported_ratelimit_requests = strdup(value.c_str()); + else if (0 == header.compare("x-ratelimit-remaining-requests")) w->reported_ratelimit_remaining_requests = strdup(value.c_str()); + else if (0 == header.compare("x-ratelimit-reset-requests")) w->reported_ratelimit_reset_requests = strdup(value.c_str()); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "header_callback: %s\n", input.c_str());