Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const JAMBONES_GATHER_EARLY_HINTS_MATCH = process.env.JAMBONES_GATHER_EARLY_HINT
const JAMBONZ_GATHER_EARLY_HINTS_MATCH = process.env.JAMBONZ_GATHER_EARLY_HINTS_MATCH;
const JAMBONES_GATHER_CLEAR_GLOBAL_HINTS_ON_EMPTY_HINTS = process.env.JAMBONES_GATHER_CLEAR_GLOBAL_HINTS_ON_EMPTY_HINTS;

/* tts streaming */
const JAMBONES_TTS_STREAM_AUTO_FLUSH = process.env.JAMBONES_TTS_STREAM_AUTO_FLUSH === 'true';

const SMPP_URL = process.env.SMPP_URL;

/* drachtio */
Expand Down Expand Up @@ -164,6 +167,7 @@ module.exports = {
JAMBONES_GATHER_EARLY_HINTS_MATCH,
JAMBONZ_GATHER_EARLY_HINTS_MATCH,
JAMBONES_GATHER_CLEAR_GLOBAL_HINTS_ON_EMPTY_HINTS,
JAMBONES_TTS_STREAM_AUTO_FLUSH,
JAMBONES_FREESWITCH,
SMPP_URL,
JAMBONES_NETWORK_CIDR,
Expand Down
12 changes: 11 additions & 1 deletion lib/utils/tts-streaming-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {
TtsStreamingEvents,
TtsStreamingConnectionStatus
} = require('../utils/constants');
const { JAMBONES_TTS_STREAM_AUTO_FLUSH } = require('../config');

const MAX_CHUNK_SIZE = 1800;
const HIGH_WATER_BUFFER_SIZE = 1000;
Expand Down Expand Up @@ -259,8 +260,12 @@ class TtsStreamingBuffer extends Emitter {
}

const limit = Math.min(MAX_CHUNK_SIZE, combinedText.length);
let isSentenceBoundaryChunk = false;
let chunkEnd = findSentenceBoundary(combinedText, limit);
if (chunkEnd <= 0) {
if (chunkEnd > 0) {
isSentenceBoundaryChunk = true;
}
else {
if (handlingTimeout) {
chunkEnd = findWordBoundary(combinedText, limit);
if (chunkEnd <= 0) {
Expand Down Expand Up @@ -321,6 +326,11 @@ class TtsStreamingBuffer extends Emitter {
this.logger.info({ err, chunk }, 'TtsStreamingBuffer:_feedQueue Error sending TTS chunk');
}

// Optionally flush on sentence boundaries if the feature flag is enabled.
if (JAMBONES_TTS_STREAM_AUTO_FLUSH && isSentenceBoundaryChunk) {
await this._doFlush();
}

if (this._isFull && this.bufferedLength <= LOW_WATER_BUFFER_SIZE) {
this.logger.info('TtsStreamingBuffer throttling: buffer is no longer full - resuming');
this._isFull = false;
Expand Down