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

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