mirror of
https://github.com/jambonz/freeswitch-modules.git
synced 2026-01-25 02:08:27 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 33fee93ec7 | |||
| 41aebafd1c | |||
| bd69d476e7 | |||
| fea51d5ecf |
@@ -480,7 +480,7 @@ AudioPipe::AudioPipe(const char* uuid, const char* host, unsigned int port, cons
|
|||||||
}
|
}
|
||||||
AudioPipe::~AudioPipe() {
|
AudioPipe::~AudioPipe() {
|
||||||
if (m_audio_buffer) delete [] m_audio_buffer;
|
if (m_audio_buffer) delete [] m_audio_buffer;
|
||||||
if (m_recv_buf) delete [] m_recv_buf;
|
if (m_recv_buf) free(m_recv_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioPipe::connect(void) {
|
void AudioPipe::connect(void) {
|
||||||
|
|||||||
@@ -135,23 +135,12 @@ extern "C" {
|
|||||||
return SWITCH_STATUS_FALSE;
|
return SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a->session_id) {
|
if (a->rate != 8000 /*Hz*/) {
|
||||||
int err;
|
int err;
|
||||||
switch_codec_implementation_t read_impl;
|
a->resampler = speex_resampler_init(1, 8000, a->rate, SWITCH_RESAMPLE_QUALITY, &err);
|
||||||
|
if (0 != err) {
|
||||||
/* lock and unlock session */
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error initializing resampler: %s.\n", speex_resampler_strerror(err));
|
||||||
switch_core_session_t *psession = switch_core_session_locate(a->session_id);
|
return SWITCH_STATUS_FALSE;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,9 +265,7 @@ extern "C" {
|
|||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
// azure returned 8000hz 16 bit data, we have to take enough data based on call sample rate.
|
// azure returned 8000hz 16 bit data, we have to take enough data based on call sample rate.
|
||||||
size_t size = a->samples_rate ?
|
size_t size = std::min((*datalen/(2 * a->rate / 8000)), bufSize);
|
||||||
std::min((*datalen/(2 * a->samples_rate / 8000)), bufSize) :
|
|
||||||
std::min((*datalen/2), bufSize);
|
|
||||||
pcm_data.insert(pcm_data.end(), cBuffer->begin(), cBuffer->begin() + size);
|
pcm_data.insert(pcm_data.end(), cBuffer->begin(), cBuffer->begin() + size);
|
||||||
cBuffer->erase(cBuffer->begin(), cBuffer->begin() + size);
|
cBuffer->erase(cBuffer->begin(), cBuffer->begin() + size);
|
||||||
switch_mutex_unlock(a->mutex);
|
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->draining = 0;
|
||||||
a->reads = 0;
|
a->reads = 0;
|
||||||
a->flushed = 0;
|
a->flushed = 0;
|
||||||
a->samples_rate = 0;
|
|
||||||
|
|
||||||
return azure_speech_feed_tts(a, text, flags);
|
return azure_speech_feed_tts(a, text, flags);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ typedef struct azure_data {
|
|||||||
int reads;
|
int reads;
|
||||||
int cache_audio;
|
int cache_audio;
|
||||||
int flushed;
|
int flushed;
|
||||||
uint32_t samples_rate;
|
|
||||||
|
|
||||||
void *startTime;
|
void *startTime;
|
||||||
|
|
||||||
|
|||||||
@@ -764,7 +764,9 @@ extern "C" {
|
|||||||
conn->file = d->file;
|
conn->file = d->file;
|
||||||
conn->body = json;
|
conn->body = json;
|
||||||
conn->flushed = false;
|
conn->flushed = false;
|
||||||
|
conn->has_last_byte = false;
|
||||||
|
conn->last_byte = 0;
|
||||||
|
|
||||||
|
|
||||||
d->circularBuffer = (void *) new CircularBuffer_t(BUFFER_GROW_SIZE);
|
d->circularBuffer = (void *) new CircularBuffer_t(BUFFER_GROW_SIZE);
|
||||||
// Always use deepgram at rate 8000 for helping cache audio from jambonz.
|
// Always use deepgram at rate 8000 for helping cache audio from jambonz.
|
||||||
|
|||||||
@@ -841,7 +841,6 @@ extern "C" {
|
|||||||
CURL* easy = createEasyHandle();
|
CURL* easy = createEasyHandle();
|
||||||
|
|
||||||
el->conn = (void *) conn ;
|
el->conn = (void *) conn ;
|
||||||
el->sample_rate = 0;
|
|
||||||
conn->elevenlabs = el;
|
conn->elevenlabs = el;
|
||||||
conn->easy = easy;
|
conn->easy = easy;
|
||||||
conn->global = &global;
|
conn->global = &global;
|
||||||
@@ -852,20 +851,12 @@ extern "C" {
|
|||||||
|
|
||||||
el->circularBuffer = (void *) new CircularBuffer_t(8192);
|
el->circularBuffer = (void *) new CircularBuffer_t(8192);
|
||||||
|
|
||||||
if (el->session_id) {
|
if (el->rate != 8000 /*Hz*/) {
|
||||||
int err;
|
int err;
|
||||||
switch_codec_implementation_t read_impl;
|
el->resampler = speex_resampler_init(1, 8000, el->rate, SWITCH_RESAMPLE_QUALITY, &err);
|
||||||
switch_core_session_t *psession = switch_core_session_locate(el->session_id);
|
if (0 != err) {
|
||||||
switch_core_session_get_read_impl(psession, &read_impl);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error initializing resampler: %s.\n", speex_resampler_strerror(err));
|
||||||
uint32_t samples_per_second = !strcasecmp(read_impl.iananame, "g722") ? read_impl.actual_samples_per_second : read_impl.samples_per_second;
|
return SWITCH_STATUS_FALSE;
|
||||||
el->sample_rate = samples_per_second;
|
|
||||||
// elevenlabs output is PCMU 8000
|
|
||||||
if (samples_per_second != 8000 /*Hz*/) {
|
|
||||||
el->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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -939,9 +930,7 @@ extern "C" {
|
|||||||
switch_mutex_unlock(el->mutex);
|
switch_mutex_unlock(el->mutex);
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
size_t size = el->sample_rate ?
|
size_t size = std::min((*datalen/(2 * el->rate / 8000)), cBuffer->size());
|
||||||
std::min((*datalen/(2 * el->sample_rate / 8000)), cBuffer->size()) :
|
|
||||||
std::min((*datalen/2), cBuffer->size());
|
|
||||||
pcm_data.insert(pcm_data.end(), cBuffer->begin(), cBuffer->begin() + size);
|
pcm_data.insert(pcm_data.end(), cBuffer->begin(), cBuffer->begin() + size);
|
||||||
cBuffer->erase(cBuffer->begin(), cBuffer->begin() + size);
|
cBuffer->erase(cBuffer->begin(), cBuffer->begin() + size);
|
||||||
switch_mutex_unlock(el->mutex);
|
switch_mutex_unlock(el->mutex);
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ struct elevenlabs_data {
|
|||||||
char *cache_filename;
|
char *cache_filename;
|
||||||
|
|
||||||
int rate;
|
int rate;
|
||||||
uint32_t sample_rate;
|
|
||||||
|
|
||||||
void *conn;
|
void *conn;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
|||||||
@@ -236,6 +236,7 @@ static void *SWITCH_THREAD_FUNC grpc_read_thread(switch_thread_t *thread, void *
|
|||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "grpc_read_thread: error %s (%d)\n", status.message().c_str(), status.code()) ;
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "grpc_read_thread: error %s (%d)\n", status.message().c_str(), status.code()) ;
|
||||||
cJSON* json = cJSON_CreateObject();
|
cJSON* json = cJSON_CreateObject();
|
||||||
cJSON_AddStringToObject(json, "type", "error");
|
cJSON_AddStringToObject(json, "type", "error");
|
||||||
|
cJSON_AddStringToObject(json, "error_cause", "stream_response");
|
||||||
cJSON_AddStringToObject(json, "error", status.message().c_str());
|
cJSON_AddStringToObject(json, "error", status.message().c_str());
|
||||||
char* jsonString = cJSON_PrintUnformatted(json);
|
char* jsonString = cJSON_PrintUnformatted(json);
|
||||||
cb->responseHandler(session, jsonString, cb->bugname);
|
cb->responseHandler(session, jsonString, cb->bugname);
|
||||||
@@ -339,9 +340,10 @@ static void *SWITCH_THREAD_FUNC grpc_read_thread(switch_thread_t *thread, void *
|
|||||||
cb->responseHandler(session, "no_audio", cb->bugname);
|
cb->responseHandler(session, "no_audio", cb->bugname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else if (status.error_code() != 0) {
|
||||||
cJSON* json = cJSON_CreateObject();
|
cJSON* json = cJSON_CreateObject();
|
||||||
cJSON_AddStringToObject(json, "type", "error");
|
cJSON_AddStringToObject(json, "type", "error");
|
||||||
|
cJSON_AddStringToObject(json, "error_cause", "stream_close");
|
||||||
cJSON_AddItemToObject(json, "error_code", cJSON_CreateNumber(status.error_code()));
|
cJSON_AddItemToObject(json, "error_code", cJSON_CreateNumber(status.error_code()));
|
||||||
cJSON_AddStringToObject(json, "error_message", status.error_message().c_str());
|
cJSON_AddStringToObject(json, "error_message", status.error_message().c_str());
|
||||||
char* jsonString = cJSON_PrintUnformatted(json);
|
char* jsonString = cJSON_PrintUnformatted(json);
|
||||||
|
|||||||
@@ -349,6 +349,7 @@ static void *SWITCH_THREAD_FUNC grpc_read_thread(switch_thread_t *thread, void *
|
|||||||
else if (status.error_code() != 0) {
|
else if (status.error_code() != 0) {
|
||||||
cJSON* json = cJSON_CreateObject();
|
cJSON* json = cJSON_CreateObject();
|
||||||
cJSON_AddStringToObject(json, "type", "error");
|
cJSON_AddStringToObject(json, "type", "error");
|
||||||
|
cJSON_AddStringToObject(json, "error_cause", "stream_close");
|
||||||
cJSON_AddItemToObject(json, "error_code", cJSON_CreateNumber(status.error_code()));
|
cJSON_AddItemToObject(json, "error_code", cJSON_CreateNumber(status.error_code()));
|
||||||
cJSON_AddStringToObject(json, "error_message", status.error_message().c_str());
|
cJSON_AddStringToObject(json, "error_message", status.error_message().c_str());
|
||||||
char* jsonString = cJSON_PrintUnformatted(json);
|
char* jsonString = cJSON_PrintUnformatted(json);
|
||||||
|
|||||||
@@ -838,17 +838,9 @@ extern "C" {
|
|||||||
|
|
||||||
p->circularBuffer = (void *) new CircularBuffer_t(8192);
|
p->circularBuffer = (void *) new CircularBuffer_t(8192);
|
||||||
|
|
||||||
if (p->session_id) {
|
if (mpg123_param(mh, MPG123_FORCE_RATE, p->rate /*Hz*/, 0) != MPG123_OK) {
|
||||||
int err;
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error mpg123_param!\n");
|
||||||
switch_codec_implementation_t read_impl;
|
return SWITCH_STATUS_FALSE;
|
||||||
switch_core_session_t *psession = switch_core_session_locate(p->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;
|
|
||||||
if (mpg123_param(mh, MPG123_FORCE_RATE, samples_per_second /*Hz*/, 0) != MPG123_OK) {
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error mpg123_param!\n");
|
|
||||||
return SWITCH_STATUS_FALSE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostringstream api_key_stream;
|
std::ostringstream api_key_stream;
|
||||||
|
|||||||
@@ -394,6 +394,8 @@ static size_t write_cb(void *ptr, size_t size, size_t nmemb, ConnInfo_t *conn) {
|
|||||||
std::unique_ptr<uint8_t[]> combinedData;
|
std::unique_ptr<uint8_t[]> combinedData;
|
||||||
|
|
||||||
if (conn->has_last_byte) {
|
if (conn->has_last_byte) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "rimelabs write_cb: processing last byte from previous read\n");
|
||||||
|
|
||||||
conn->has_last_byte = false; // We'll handle the last_byte now, so toggle the flag off
|
conn->has_last_byte = false; // We'll handle the last_byte now, so toggle the flag off
|
||||||
|
|
||||||
// Allocate memory for the new data array
|
// Allocate memory for the new data array
|
||||||
@@ -415,6 +417,8 @@ static size_t write_cb(void *ptr, size_t size, size_t nmemb, ConnInfo_t *conn) {
|
|||||||
|
|
||||||
// If we now have an odd total, save the last byte for next time
|
// If we now have an odd total, save the last byte for next time
|
||||||
if ((total_bytes_to_process % sizeof(int16_t)) != 0) {
|
if ((total_bytes_to_process % sizeof(int16_t)) != 0) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "rimelabs write_cb: got odd number of bytes %d\n", total_bytes_to_process);
|
||||||
|
|
||||||
conn->last_byte = data[total_bytes_to_process - 1];
|
conn->last_byte = data[total_bytes_to_process - 1];
|
||||||
conn->has_last_byte = true;
|
conn->has_last_byte = true;
|
||||||
total_bytes_to_process--;
|
total_bytes_to_process--;
|
||||||
@@ -758,6 +762,8 @@ extern "C" {
|
|||||||
conn->file = d->file;
|
conn->file = d->file;
|
||||||
conn->body = json;
|
conn->body = json;
|
||||||
conn->flushed = false;
|
conn->flushed = false;
|
||||||
|
conn->has_last_byte = false;
|
||||||
|
conn->last_byte = 0;
|
||||||
|
|
||||||
|
|
||||||
d->circularBuffer = (void *) new CircularBuffer_t(BUFFER_GROW_SIZE);
|
d->circularBuffer = (void *) new CircularBuffer_t(BUFFER_GROW_SIZE);
|
||||||
|
|||||||
Reference in New Issue
Block a user