diff --git a/mod_custom_tts/custom_glue.cpp b/mod_custom_tts/custom_glue.cpp index e8f2c53..ab5948c 100644 --- a/mod_custom_tts/custom_glue.cpp +++ b/mod_custom_tts/custom_glue.cpp @@ -451,12 +451,12 @@ static size_t write_cb(void *ptr, size_t size, size_t nmemb, ConnInfo_t *conn) { return 0; } - /* cache file will stay in the mp3 format for size (smaller) and simplicity */ - if (conn->file) fwrite(data, sizeof(uint8_t), bytes_received, conn->file); - pcm_data = convert_mp3_to_linear(conn, data, bytes_received); size_t bytesResampled = pcm_data.size() * sizeof(uint16_t); + /* cache same data to avoid streaming and cached audio quality is different*/ + if (conn->file) fwrite(pcm_data.data(), sizeof(uint8_t), bytesResampled, conn->file); + // Resize the buffer if necessary if (cBuffer->capacity() - cBuffer->size() < (bytesResampled / sizeof(uint16_t))) { //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "write_cb growing buffer\n"); diff --git a/mod_playht_tts/playht_glue.cpp b/mod_playht_tts/playht_glue.cpp index c5cad47..32ef79e 100644 --- a/mod_playht_tts/playht_glue.cpp +++ b/mod_playht_tts/playht_glue.cpp @@ -452,12 +452,12 @@ static size_t write_cb(void *ptr, size_t size, size_t nmemb, ConnInfo_t *conn) { return 0; } - /* cache file will stay in the mp3 format for size (smaller) and simplicity */ - if (conn->file) fwrite(data, sizeof(uint8_t), bytes_received, conn->file); - pcm_data = convert_mp3_to_linear(conn, data, bytes_received); size_t bytesResampled = pcm_data.size() * sizeof(uint16_t); + /* cache same data to avoid streaming and cached audio quality is different*/ + if (conn->file) fwrite(pcm_data.data(), sizeof(uint8_t), bytesResampled, conn->file); + // Resize the buffer if necessary if (cBuffer->capacity() - cBuffer->size() < (bytesResampled / sizeof(uint16_t))) { //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "write_cb growing buffer\n");