mirror of
https://github.com/jambonz/freeswitch-modules.git
synced 2025-12-19 08:27:44 +00:00
fix eleevnlabs callsession stuck (#55)
* fix eleevnlabs callsession stuck Signed-off-by: Hoan HL <quan.luuhoang8@gmail.com> * fix read sample rate from session is not needed Signed-off-by: Hoan HL <quan.luuhoang8@gmail.com> --------- Signed-off-by: Hoan HL <quan.luuhoang8@gmail.com>
This commit is contained in:
@@ -135,23 +135,12 @@ extern "C" {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
if (a->session_id) {
|
||||
if (a->rate != 8000 /*Hz*/) {
|
||||
int err;
|
||||
switch_codec_implementation_t read_impl;
|
||||
|
||||
/* lock and unlock session */
|
||||
switch_core_session_t *psession = switch_core_session_locate(a->session_id);
|
||||
switch_core_session_get_read_impl(psession, &read_impl);
|
||||
switch_core_session_rwunlock(psession);
|
||||
|
||||
uint32_t samples_per_second = !strcasecmp(read_impl.iananame, "g722") ? read_impl.actual_samples_per_second : read_impl.samples_per_second;
|
||||
a->samples_rate = samples_per_second;
|
||||
if (samples_per_second != 8000 /*Hz*/) {
|
||||
a->resampler = speex_resampler_init(1, 8000, samples_per_second, SWITCH_RESAMPLE_QUALITY, &err);
|
||||
if (0 != err) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error initializing resampler: %s.\n", speex_resampler_strerror(err));
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
a->resampler = speex_resampler_init(1, 8000, a->rate, SWITCH_RESAMPLE_QUALITY, &err);
|
||||
if (0 != err) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error initializing resampler: %s.\n", speex_resampler_strerror(err));
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,9 +265,7 @@ extern "C" {
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
// azure returned 8000hz 16 bit data, we have to take enough data based on call sample rate.
|
||||
size_t size = a->samples_rate ?
|
||||
std::min((*datalen/(2 * a->samples_rate / 8000)), bufSize) :
|
||||
std::min((*datalen/2), bufSize);
|
||||
size_t size = std::min((*datalen/(2 * a->rate / 8000)), bufSize);
|
||||
pcm_data.insert(pcm_data.end(), cBuffer->begin(), cBuffer->begin() + size);
|
||||
cBuffer->erase(cBuffer->begin(), cBuffer->begin() + size);
|
||||
switch_mutex_unlock(a->mutex);
|
||||
|
||||
@@ -82,7 +82,6 @@ static switch_status_t a_speech_feed_tts(switch_speech_handle_t *sh, char *text,
|
||||
a->draining = 0;
|
||||
a->reads = 0;
|
||||
a->flushed = 0;
|
||||
a->samples_rate = 0;
|
||||
|
||||
return azure_speech_feed_tts(a, text, flags);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ typedef struct azure_data {
|
||||
int reads;
|
||||
int cache_audio;
|
||||
int flushed;
|
||||
uint32_t samples_rate;
|
||||
|
||||
void *startTime;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user