Delete tts tmp file if playback_start event has not been sent (#68)

* Delete tts tmp file if playback_start event has not been sent

Signed-off-by: Hoan HL <quan.luuhoang8@gmail.com>

* Delete tts tmp file if playback_start event has not been sent

Signed-off-by: Hoan HL <quan.luuhoang8@gmail.com>

* wip

Signed-off-by: Hoan HL <quan.luuhoang8@gmail.com>

---------

Signed-off-by: Hoan HL <quan.luuhoang8@gmail.com>
This commit is contained in:
Hoan Luu Huu
2024-05-26 20:29:05 +07:00
committed by GitHub
parent d1d0f5dd77
commit 45ecf151c3
18 changed files with 78 additions and 60 deletions

View File

@@ -255,6 +255,7 @@ extern "C" {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "variable_tts_cache_filename", a->cache_filename);
}
switch_event_fire(&event);
a->playback_start_sent = 1;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "speechSynthesizer->Synthesizing: failed to create event\n");
}
@@ -347,16 +348,16 @@ extern "C" {
}
a->file = nullptr ;
}
if (a->cache_filename) {
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "removing audio cache file %s because download was interrupted\n", a->cache_filename);
if (unlink(a->cache_filename) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cleanupConn: error removing audio cache file %s: %d:%s\n",
a->cache_filename, errno, strerror(errno));
}
free(a->cache_filename);
a->cache_filename = nullptr ;
}
// If playback_start has not been sent, delete the file
if (a->cache_filename && !a->playback_start_sent) {
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "removing audio cache file %s because download was interrupted\n", a->cache_filename);
if (unlink(a->cache_filename) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cleanupConn: error removing audio cache file %s: %d:%s\n",
a->cache_filename, errno, strerror(errno));
}
free(a->cache_filename);
a->cache_filename = nullptr ;
}
if (a->session_id) {
switch_core_session_t* session = switch_core_session_locate(a->session_id);

View File

@@ -85,6 +85,7 @@ static switch_status_t a_speech_feed_tts(switch_speech_handle_t *sh, char *text,
a->response_code = 0;
a->err_msg = NULL;
a->has_last_byte = 0;
a->playback_start_sent = 0;
return azure_speech_feed_tts(a, text, flags);
}

View File

@@ -25,6 +25,7 @@ typedef struct azure_data {
int reads;
int cache_audio;
int flushed;
int playback_start_sent;
void *startTime;

View File

@@ -500,6 +500,7 @@ static size_t write_cb(void *ptr, size_t size, size_t nmemb, ConnInfo_t *conn) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "variable_tts_time_to_first_byte_ms", time_to_first_byte_ms.c_str());
switch_event_fire(&event);
d->playback_start_sent = 1;
}
else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "write_cb: failed to create event\n");
@@ -904,18 +905,18 @@ extern "C" {
}
conn->file = nullptr ;
}
if (d->cache_filename) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "removing audio cache file %s because download was interrupted\n", d->cache_filename);
if (unlink(d->cache_filename) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cleanupConn: error removing audio cache file %s: %d:%s\n",
d->cache_filename, errno, strerror(errno));
}
free(d->cache_filename);
d->cache_filename = nullptr ;
}
}
}
// If playback_start has not been sent, delete the file
if (d->cache_filename && !d->playback_start_sent) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "removing audio cache file %s because download was interrupted\n", d->cache_filename);
if (unlink(d->cache_filename) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cleanupConn: error removing audio cache file %s: %d:%s\n",
d->cache_filename, errno, strerror(errno));
}
free(d->cache_filename);
d->cache_filename = nullptr ;
}
if (d->session_id) {
switch_core_session_t* session = switch_core_session_locate(d->session_id);
if (session) {

View File

@@ -86,6 +86,7 @@ static switch_status_t d_speech_feed_tts(switch_speech_handle_t *sh, char *text,
d->reads = 0;
d->response_code = 0;
d->err_msg = NULL;
d->playback_start_sent = 0;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "d_speech_feed_tts\n");

View File

@@ -31,6 +31,7 @@ typedef struct deepgram_data {
int draining;
int reads;
int cache_audio;
int playback_start_sent;
void *conn;
void *circularBuffer;

View File

@@ -532,6 +532,7 @@ static size_t write_cb(void *ptr, size_t size, size_t nmemb, ConnInfo_t *conn) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "variable_tts_time_to_first_byte_ms", time_to_first_byte_ms.c_str());
switch_event_fire(&event);
el->playback_start_sent = 1;
}
else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "write_cb: failed to create event\n");
@@ -987,18 +988,18 @@ extern "C" {
}
conn->file = nullptr ;
}
if (el->cache_filename) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "removing audio cache file %s because download was interrupted\n", el->cache_filename);
if (unlink(el->cache_filename) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cleanupConn: error removing audio cache file %s: %d:%s\n",
el->cache_filename, errno, strerror(errno));
}
free(el->cache_filename);
el->cache_filename = nullptr ;
}
}
}
// If playback_start has not been sent, delete the file
if (el->cache_filename && !el->playback_start_sent) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "removing audio cache file %s because download was interrupted\n", el->cache_filename);
if (unlink(el->cache_filename) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cleanupConn: error removing audio cache file %s: %d:%s\n",
el->cache_filename, errno, strerror(errno));
}
free(el->cache_filename);
el->cache_filename = nullptr ;
}
if (el->session_id) {
switch_core_session_t* session = switch_core_session_locate(el->session_id);
if (session) {

View File

@@ -108,6 +108,7 @@ static switch_status_t ell_speech_feed_tts(switch_speech_handle_t *sh, char *tex
el->reads = 0;
el->response_code = 0;
el->err_msg = NULL;
el->playback_start_sent = 0;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "ell_speech_feed_tts\n");

View File

@@ -39,6 +39,7 @@ struct elevenlabs_data {
int draining;
int reads;
int cache_audio;
int playback_start_sent;
SpeexResamplerState *resampler;
};

View File

@@ -101,6 +101,7 @@ static switch_status_t p_speech_feed_tts(switch_speech_handle_t *sh, char *text,
p->reads = 0;
p->response_code = 0;
p->err_msg = NULL;
p->playback_start_sent = 0;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "p_speech_feed_tts\n");

View File

@@ -31,6 +31,7 @@ typedef struct playht_data {
int draining;
int reads;
int cache_audio;
int playback_start_sent;
void *conn;
void *circularBuffer;

View File

@@ -511,6 +511,7 @@ static size_t write_cb(void *ptr, size_t size, size_t nmemb, ConnInfo_t *conn) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "variable_tts_time_to_first_byte_ms", time_to_first_byte_ms.c_str());
switch_event_fire(&event);
p->playback_start_sent = 1;
}
else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "write_cb: failed to create event\n");
@@ -947,18 +948,18 @@ extern "C" {
}
conn->file = nullptr ;
}
if (p->cache_filename) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "removing audio cache file %s because download was interrupted\n", p->cache_filename);
if (unlink(p->cache_filename) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cleanupConn: error removing audio cache file %s: %d:%s\n",
p->cache_filename, errno, strerror(errno));
}
free(p->cache_filename);
p->cache_filename = nullptr ;
}
}
}
// if playback event has not been sent, delete the file.
if (p->cache_filename && !p->playback_start_sent) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "removing audio cache file %s because download was interrupted\n", p->cache_filename);
if (unlink(p->cache_filename) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cleanupConn: error removing audio cache file %s: %d:%s\n",
p->cache_filename, errno, strerror(errno));
}
free(p->cache_filename);
p->cache_filename = nullptr ;
}
if (p->session_id) {
switch_core_session_t* session = switch_core_session_locate(p->session_id);
if (session) {

View File

@@ -84,6 +84,7 @@ static switch_status_t d_speech_feed_tts(switch_speech_handle_t *sh, char *text,
d->reads = 0;
d->response_code = 0;
d->err_msg = NULL;
d->playback_start_sent = 0;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "d_speech_feed_tts\n");

View File

@@ -25,6 +25,7 @@ typedef struct rimelabs_data {
int draining;
int reads;
int cache_audio;
int playback_start_sent;
void *conn;
void *circularBuffer;

View File

@@ -493,6 +493,7 @@ static size_t write_cb(void *ptr, size_t size, size_t nmemb, ConnInfo_t *conn) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "variable_tts_time_to_first_byte_ms", time_to_first_byte_ms.c_str());
switch_event_fire(&event);
d->playback_start_sent = 1;
}
else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "write_cb: failed to create event\n");
@@ -903,18 +904,18 @@ extern "C" {
}
conn->file = nullptr ;
}
if (d->cache_filename) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "removing audio cache file %s because download was interrupted\n", d->cache_filename);
if (unlink(d->cache_filename) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cleanupConn: error removing audio cache file %s: %d:%s\n",
d->cache_filename, errno, strerror(errno));
}
free(d->cache_filename);
d->cache_filename = nullptr ;
}
}
}
// if playback_start event has not been sent, delete the file
if (d->cache_filename && !d->playback_start_sent) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "removing audio cache file %s because download was interrupted\n", d->cache_filename);
if (unlink(d->cache_filename) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cleanupConn: error removing audio cache file %s: %d:%s\n",
d->cache_filename, errno, strerror(errno));
}
free(d->cache_filename);
d->cache_filename = nullptr ;
}
if (d->session_id) {
switch_core_session_t* session = switch_core_session_locate(d->session_id);
if (session) {

View File

@@ -92,6 +92,7 @@ static switch_status_t w_speech_feed_tts(switch_speech_handle_t *sh, char *text,
w->reads = 0;
w->response_code = 0;
w->err_msg = NULL;
w->playback_start_sent = 0;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "w_speech_feed_tts\n");

View File

@@ -35,6 +35,7 @@ typedef struct whisper_data {
int draining;
int reads;
int cache_audio;
int playback_start_sent;
void *conn;
void *circularBuffer;

View File

@@ -528,6 +528,7 @@ static size_t write_cb(void *ptr, size_t size, size_t nmemb, ConnInfo_t *conn) {
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "variable_tts_time_to_first_byte_ms", time_to_first_byte_ms.c_str());
switch_event_fire(&event);
w->playback_start_sent = 1;
}
else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "write_cb: failed to create event\n");
@@ -949,18 +950,18 @@ extern "C" {
}
conn->file = nullptr ;
}
if (w->cache_filename) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "removing audio cache file %s because download was interrupted\n", w->cache_filename);
if (unlink(w->cache_filename) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cleanupConn: error removing audio cache file %s: %d:%s\n",
w->cache_filename, errno, strerror(errno));
}
free(w->cache_filename);
w->cache_filename = nullptr ;
}
}
}
// if playback_start event has not been sent, delete the file
if (w->cache_filename && !w->playback_start_sent) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "removing audio cache file %s because download was interrupted\n", w->cache_filename);
if (unlink(w->cache_filename) != 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "cleanupConn: error removing audio cache file %s: %d:%s\n",
w->cache_filename, errno, strerror(errno));
}
free(w->cache_filename);
w->cache_filename = nullptr ;
}
if (w->session_id) {
switch_core_session_t* session = switch_core_session_locate(w->session_id);
if (session) {