Compare commits

..

1 Commits

Author SHA1 Message Date
Dave Horton 4a7ce3fdf8 fix path syntax 2024-05-10 14:14:20 -04:00
5 changed files with 9 additions and 45 deletions
@@ -304,7 +304,7 @@ public:
void finish() { void finish() {
if (m_finished) return; if (m_finished) return;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "GStreamer::finish - calling StopContinuousRecognitionAsync (%p)\n", this); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "GStreamer::finish - calling StopContinuousRecognitionAsync (%p)\n", this);
m_finished = true; m_finished = true;
m_recognizer->StopContinuousRecognitionAsync().get(); m_recognizer->StopContinuousRecognitionAsync().get();
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "GStreamer::finish - recognition has completed (%p)\n", this); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "GStreamer::finish - recognition has completed (%p)\n", this);
+5 -37
View File
@@ -179,55 +179,23 @@ extern "C" {
if (a->flushed) return; if (a->flushed) return;
bool fireEvent = false; bool fireEvent = false;
CircularBuffer_t *cBuffer = (CircularBuffer_t *) a->circularBuffer; CircularBuffer_t *cBuffer = (CircularBuffer_t *) a->circularBuffer;
size_t total_bytes_to_process;
auto audioData = e.Result->GetAudioData(); 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) { if (a->file) {
fwrite(data, 1, total_bytes_to_process, a->file); fwrite(audioData->data(), 1, audioData->size(), a->file);
} }
/** /**
* this sort of reinterpretation can be dangerous as a general rule, but in this case we know that the data * 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 * 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*>(data); const uint16_t* begin = reinterpret_cast<const uint16_t*>(audioData->data());
const uint16_t* end = reinterpret_cast<const uint16_t*>(data + total_bytes_to_process); const uint16_t* end = reinterpret_cast<const uint16_t*>(audioData->data() + audioData->size());
/* lock as briefly as possible */ /* lock as briefly as possible */
switch_mutex_lock(a->mutex); switch_mutex_lock(a->mutex);
if (cBuffer->capacity() - cBuffer->size() < total_bytes_to_process) { if (cBuffer->capacity() - cBuffer->size() < audioData->size()) {
cBuffer->set_capacity(cBuffer->size() + std::max( total_bytes_to_process, (size_t)BUFFER_SIZE)); cBuffer->set_capacity(cBuffer->size() + std::max( audioData->size(), (size_t)BUFFER_SIZE));
} }
cBuffer->insert(cBuffer->end(), begin, end); cBuffer->insert(cBuffer->end(), begin, end);
switch_mutex_unlock(a->mutex); switch_mutex_unlock(a->mutex);
-1
View File
@@ -84,7 +84,6 @@ static switch_status_t a_speech_feed_tts(switch_speech_handle_t *sh, char *text,
a->flushed = 0; a->flushed = 0;
a->response_code = 0; a->response_code = 0;
a->err_msg = NULL; a->err_msg = NULL;
a->has_last_byte = 0;
return azure_speech_feed_tts(a, text, flags); return azure_speech_feed_tts(a, text, flags);
} }
-3
View File
@@ -32,9 +32,6 @@ typedef struct azure_data {
SpeexResamplerState *resampler; SpeexResamplerState *resampler;
void *circularBuffer; void *circularBuffer;
switch_mutex_t *mutex; switch_mutex_t *mutex;
int has_last_byte;
uint8_t last_byte;
} azure_t; } azure_t;
#endif #endif
@@ -162,14 +162,14 @@ namespace {
if (!model && !customModel) { if (!model && !customModel) {
std::string defaultModel; std::string defaultModel;
if (getLanguageInfo(language, defaultModel)) { if (getLanguageInfo(language, defaultModel)) {
oss << "&model=" << defaultModel; oss << "model=" << defaultModel;
} }
else { else {
oss << "model=base"; // most widely supported, though not ideal oss << "model=base"; // most widely supported, though not ideal
} }
} }
else if (model) oss << "&model=" << model; else if (model) oss << "model=" << model;
else if (customModel) oss << "&model=" << customModel; else if (customModel) oss << "model=" << customModel;
if (var = switch_channel_get_variable(channel, "DEEPGRAM_SPEECH_MODEL_VERSION")) { if (var = switch_channel_get_variable(channel, "DEEPGRAM_SPEECH_MODEL_VERSION")) {
oss << "&version"; oss << "&version";