Compare commits

...

4 Commits

Author SHA1 Message Date
Dave Horton e4a27ae133 minor logging
Signed-off-by: Dave Horton <daveh@beachdognet.com>
2024-05-14 06:59:11 -04:00
Hoan Luu Huu 19f20bf0e7 Fix/azure white noise (#63)
* azure return odd bytes audio, that azure tts mode generate white noise

* wip

Signed-off-by: Hoan HL <quan.luuhoang8@gmail.com>

---------

Signed-off-by: Hoan HL <quan.luuhoang8@gmail.com>
2024-05-14 06:55:44 -04:00
Hoan Luu Huu b019a634bd Fix playht timeout while downloading audio (#61)
Signed-off-by: Quan HL <quan.luuhoang8@gmail.com>
2024-05-10 12:18:32 -04:00
Dave Horton f0b304b8a1 session mutex not properly unlocked causing stuck channels (#60)
Signed-off-by: Dave Horton <daveh@beachdognet.com>
2024-05-02 10:35:54 -04:00
7 changed files with 48 additions and 9 deletions
@@ -304,7 +304,7 @@ public:
void finish() {
if (m_finished) return;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "GStreamer::finish - calling StopContinuousRecognitionAsync (%p)\n", this);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "GStreamer::finish - calling StopContinuousRecognitionAsync (%p)\n", this);
m_finished = true;
m_recognizer->StopContinuousRecognitionAsync().get();
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "GStreamer::finish - recognition has completed (%p)\n", this);
+37 -5
View File
@@ -179,23 +179,55 @@ extern "C" {
if (a->flushed) return;
bool fireEvent = false;
CircularBuffer_t *cBuffer = (CircularBuffer_t *) a->circularBuffer;
size_t total_bytes_to_process;
auto audioData = e.Result->GetAudioData();
auto bytes_received = audioData->size();
// Buffer to hold combined data if there is unprocessed byte from the last call.
std::unique_ptr<uint8_t[]> combinedData;
if (a->has_last_byte) {
a->has_last_byte = false; // We'll handle the last_byte now, so toggle the flag off
// Allocate memory for the new data array
combinedData.reset(new uint8_t[bytes_received + 1]);
// Prepend the last byte from previous call
combinedData[0] = a->last_byte;
// Copy the new data following the prepended byte
memcpy(combinedData.get() + 1, audioData->data(), bytes_received);
total_bytes_to_process = bytes_received + 1;
} else {
// Allocate memory for the new data array
combinedData.reset(new uint8_t[bytes_received]);
memcpy(combinedData.get(), audioData->data(), bytes_received);
total_bytes_to_process = bytes_received;
}
// If we now have an odd total, save the last byte for next time
auto data = combinedData.get();
if ((total_bytes_to_process % sizeof(int16_t)) != 0) {
a->last_byte = data[total_bytes_to_process - 1];
a->has_last_byte = true;
total_bytes_to_process--;
}
if (a->file) {
fwrite(audioData->data(), 1, audioData->size(), a->file);
fwrite(data, 1, total_bytes_to_process, a->file);
}
/**
* this sort of reinterpretation can be dangerous as a general rule, but in this case we know that the data
* is 16-bit PCM, so it's safe to do this and its much faster than copying the data byte by byte
*/
const uint16_t* begin = reinterpret_cast<const uint16_t*>(audioData->data());
const uint16_t* end = reinterpret_cast<const uint16_t*>(audioData->data() + audioData->size());
const uint16_t* begin = reinterpret_cast<const uint16_t*>(data);
const uint16_t* end = reinterpret_cast<const uint16_t*>(data + total_bytes_to_process);
/* lock as briefly as possible */
switch_mutex_lock(a->mutex);
if (cBuffer->capacity() - cBuffer->size() < audioData->size()) {
cBuffer->set_capacity(cBuffer->size() + std::max( audioData->size(), (size_t)BUFFER_SIZE));
if (cBuffer->capacity() - cBuffer->size() < total_bytes_to_process) {
cBuffer->set_capacity(cBuffer->size() + std::max( total_bytes_to_process, (size_t)BUFFER_SIZE));
}
cBuffer->insert(cBuffer->end(), begin, end);
switch_mutex_unlock(a->mutex);
+1
View File
@@ -84,6 +84,7 @@ static switch_status_t a_speech_feed_tts(switch_speech_handle_t *sh, char *text,
a->flushed = 0;
a->response_code = 0;
a->err_msg = NULL;
a->has_last_byte = 0;
return azure_speech_feed_tts(a, text, flags);
}
+3
View File
@@ -32,6 +32,9 @@ typedef struct azure_data {
SpeexResamplerState *resampler;
void *circularBuffer;
switch_mutex_t *mutex;
int has_last_byte;
uint8_t last_byte;
} azure_t;
#endif
@@ -404,12 +404,14 @@ extern "C" {
jambonz::AudioPipe *pAudioPipe = static_cast<jambonz::AudioPipe *>(tech_pvt->pAudioPipe);
if (pAudioPipe) reaper(tech_pvt);
destroy_tech_pvt(tech_pvt);
switch_mutex_unlock(tech_pvt->mutex);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "(%u) jb_transcribe_session_stop, bug removed\n", id);
return SWITCH_STATUS_SUCCESS;
}
else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "jb_transcribe_session_stop: race condition, previous close completed\n");
}
switch_mutex_unlock(tech_pvt->mutex);
}
return SWITCH_STATUS_FALSE;
}
@@ -100,7 +100,7 @@ static switch_status_t start_capture(switch_core_session_t *session, switch_medi
return status;
}
switch_channel_set_private(channel, bugname, bug);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "added media bug for jb transcribe\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "added media bug for jb transcribe: %s\n", bugname);
return SWITCH_STATUS_SUCCESS;
}
@@ -146,7 +146,7 @@ SWITCH_STANDARD_API(jb_transcribe_function)
if ((lsession = switch_core_session_locate(argv[0]))) {
if (!strcasecmp(argv[1], "stop")) {
char *bugname = argc > 2 ? argv[2] : MY_BUG_NAME;
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "stop transcribing\n");
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "stop transcribing %s\n", bugname);
status = do_stop(lsession, bugname);
} else if (!strcasecmp(argv[1], "start")) {
char* lang = argv[2];
+2 -1
View File
@@ -76,7 +76,8 @@ static CURL* createEasyHandle(void) {
// set connect timeout to 3 seconds and total timeout to 109 seconds
curl_easy_setopt(easy, CURLOPT_CONNECTTIMEOUT_MS, 3000L);
curl_easy_setopt(easy, CURLOPT_TIMEOUT, 10L);
//For long text, PlayHT took more than 20 seconds to complete the download.
curl_easy_setopt(easy, CURLOPT_TIMEOUT, 60L);
return easy ;
}