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 09:29:05 -04:00
committed by GitHub
parent d1d0f5dd77
commit 45ecf151c3
18 changed files with 78 additions and 60 deletions
+1
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");
+1
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;
+12 -11
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");
@@ -931,7 +932,7 @@ extern "C" {
switch_status_t playht_speech_flush_tts(playht_t* p) {
bool download_complete = p->response_code == 200;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "playht_speech_flush_tts, download complete? %s\n", download_complete ? "yes" : "no") ;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "playht_speech_flush_tts, download complete? %s\n", download_complete ? "yes" : "no") ;
ConnInfo_t *conn = (ConnInfo_t *) p->conn;
CircularBuffer_t *cBuffer = (CircularBuffer_t *) p->circularBuffer;
delete cBuffer;
@@ -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) {