mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
handle altLanguages set at the session level via config verb; fix azure stt race condition with final transcripts from stopped recognition
This commit is contained in:
@@ -274,6 +274,18 @@ class CallSession extends Emitter {
|
|||||||
return this._globalSttHints;
|
return this._globalSttHints;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
set altLanguages(langs) {
|
||||||
|
this._globalAltLanguages = langs;
|
||||||
|
}
|
||||||
|
|
||||||
|
get hasAltLanguages() {
|
||||||
|
return Array.isArray(this._globalAltLanguages);
|
||||||
|
}
|
||||||
|
|
||||||
|
get altLanguages() {
|
||||||
|
return this._globalAltLanguages;
|
||||||
|
}
|
||||||
|
|
||||||
async notifyRecordOptions(opts) {
|
async notifyRecordOptions(opts) {
|
||||||
const {action} = opts;
|
const {action} = opts;
|
||||||
this.logger.debug({opts}, 'CallSession:notifyRecordOptions');
|
this.logger.debug({opts}, 'CallSession:notifyRecordOptions');
|
||||||
@@ -1112,7 +1124,6 @@ class CallSession extends Emitter {
|
|||||||
* @param {Task} task - task to be executed
|
* @param {Task} task - task to be executed
|
||||||
*/
|
*/
|
||||||
async _evalEndpointPrecondition(task) {
|
async _evalEndpointPrecondition(task) {
|
||||||
this.logger.debug('CallSession:_evalEndpointPrecondition');
|
|
||||||
if (this.callGone) new Error(`${BADPRECONDITIONS}: call gone`);
|
if (this.callGone) new Error(`${BADPRECONDITIONS}: call gone`);
|
||||||
|
|
||||||
if (this.ep) {
|
if (this.ep) {
|
||||||
|
|||||||
@@ -94,6 +94,10 @@ class TaskConfig extends Task {
|
|||||||
}
|
}
|
||||||
cs.globalSttHints = obj;
|
cs.globalSttHints = obj;
|
||||||
}
|
}
|
||||||
|
if (Array.isArray(this.recognizer.altLanguages)) {
|
||||||
|
this.logger.info({altLanguages: this.recognizer.altLanguages}, 'Config: updated altLanguages');
|
||||||
|
cs.altLanguages = this.recognizer.altLanguages;
|
||||||
|
}
|
||||||
this.logger.info({
|
this.logger.info({
|
||||||
recognizer: this.recognizer,
|
recognizer: this.recognizer,
|
||||||
isContinuousAsr: cs.isContinuousAsr
|
isContinuousAsr: cs.isContinuousAsr
|
||||||
|
|||||||
@@ -141,6 +141,11 @@ class TaskGather extends Task {
|
|||||||
this.logger.debug({hints: this.hints, hintsBoost: this.hintsBoost},
|
this.logger.debug({hints: this.hints, hintsBoost: this.hintsBoost},
|
||||||
'Gather:exec - applying global sttHints');
|
'Gather:exec - applying global sttHints');
|
||||||
}
|
}
|
||||||
|
if (cs.hasAltLanguages) {
|
||||||
|
this.altLanguages = this.altLanguages.concat(cs.altLanguages);
|
||||||
|
this.logger.debug({altLanguages: this.altLanguages},
|
||||||
|
'Gather:exec - applying altLanguages');
|
||||||
|
}
|
||||||
if (!this.isContinuousAsr && cs.isContinuousAsr) {
|
if (!this.isContinuousAsr && cs.isContinuousAsr) {
|
||||||
this.isContinuousAsr = true;
|
this.isContinuousAsr = true;
|
||||||
this.asrTimeout = cs.asrTimeout * 1000;
|
this.asrTimeout = cs.asrTimeout * 1000;
|
||||||
@@ -312,7 +317,8 @@ class TaskGather extends Task {
|
|||||||
opts.GOOGLE_SPEECH_HINTS_BOOST = this.hintsBoost;
|
opts.GOOGLE_SPEECH_HINTS_BOOST = this.hintsBoost;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.altLanguages.length > 1) opts.GOOGLE_SPEECH_ALTERNATIVE_LANGUAGE_CODES = this.altLanguages.join(',');
|
if (this.altLanguages.length > 0) opts.GOOGLE_SPEECH_ALTERNATIVE_LANGUAGE_CODES = this.altLanguages.join(',');
|
||||||
|
else opts.GOOGLE_SPEECH_ALTERNATIVE_LANGUAGE_CODES = '';
|
||||||
if ('unspecified' !== this.interactionType) {
|
if ('unspecified' !== this.interactionType) {
|
||||||
opts.GOOGLE_SPEECH_METADATA_INTERACTION_TYPE = this.interactionType;
|
opts.GOOGLE_SPEECH_METADATA_INTERACTION_TYPE = this.interactionType;
|
||||||
}
|
}
|
||||||
@@ -359,6 +365,9 @@ class TaskGather extends Task {
|
|||||||
if (this.altLanguages && this.altLanguages.length > 0) {
|
if (this.altLanguages && this.altLanguages.length > 0) {
|
||||||
opts.AZURE_SPEECH_ALTERNATIVE_LANGUAGE_CODES = this.altLanguages.join(',');
|
opts.AZURE_SPEECH_ALTERNATIVE_LANGUAGE_CODES = this.altLanguages.join(',');
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
opts.AZURE_SPEECH_ALTERNATIVE_LANGUAGE_CODES = '';
|
||||||
|
}
|
||||||
if (this.requestSnr) opts.AZURE_REQUEST_SNR = 1;
|
if (this.requestSnr) opts.AZURE_REQUEST_SNR = 1;
|
||||||
if (this.profanityOption && this.profanityOption !== 'raw') opts.AZURE_PROFANITY_OPTION = this.profanityOption;
|
if (this.profanityOption && this.profanityOption !== 'raw') opts.AZURE_PROFANITY_OPTION = this.profanityOption;
|
||||||
if (this.azureServiceEndpoint) opts.AZURE_SERVICE_ENDPOINT = this.azureServiceEndpoint;
|
if (this.azureServiceEndpoint) opts.AZURE_SERVICE_ENDPOINT = this.azureServiceEndpoint;
|
||||||
@@ -468,6 +477,7 @@ class TaskGather extends Task {
|
|||||||
_onTranscription(cs, ep, evt, fsEvent) {
|
_onTranscription(cs, ep, evt, fsEvent) {
|
||||||
// make sure this is not a transcript from answering machine detection
|
// make sure this is not a transcript from answering machine detection
|
||||||
const bugname = fsEvent.getHeader('media-bugname');
|
const bugname = fsEvent.getHeader('media-bugname');
|
||||||
|
const finished = fsEvent.getHeader('transcription-session-finished');
|
||||||
if (bugname && this.bugname !== bugname) return;
|
if (bugname && this.bugname !== bugname) return;
|
||||||
|
|
||||||
if ('aws' === this.vendor && Array.isArray(evt) && evt.length > 0) evt = evt[0];
|
if ('aws' === this.vendor && Array.isArray(evt) && evt.length > 0) evt = evt[0];
|
||||||
@@ -509,8 +519,14 @@ class TaskGather extends Task {
|
|||||||
|
|
||||||
if (evt.is_final) {
|
if (evt.is_final) {
|
||||||
if (evt.alternatives[0].transcript === '' && !this.callSession.callGone && !this.killed) {
|
if (evt.alternatives[0].transcript === '' && !this.callSession.callGone && !this.killed) {
|
||||||
|
if ('microsoft' === this.vendor && finished === 'true') {
|
||||||
|
this.logger.debug({evt}, 'TaskGather:_onTranscription - got empty transcript from old gather, disregarding');
|
||||||
|
}
|
||||||
|
else {
|
||||||
this.logger.info({evt}, 'TaskGather:_onTranscription - got empty transcript, listen again');
|
this.logger.info({evt}, 'TaskGather:_onTranscription - got empty transcript, listen again');
|
||||||
return this._startTranscribing(ep);
|
this._startTranscribing(ep);
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (this.isContinuousAsr) {
|
if (this.isContinuousAsr) {
|
||||||
/* append the transcript and start listening again for asrTimeout */
|
/* append the transcript and start listening again for asrTimeout */
|
||||||
@@ -586,10 +602,17 @@ class TaskGather extends Task {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onNoSpeechDetected(cs, ep) {
|
_onNoSpeechDetected(cs, ep, evt, fsEvent) {
|
||||||
if (!this.callSession.callGone && !this.killed) {
|
if (!this.callSession.callGone && !this.killed) {
|
||||||
|
const finished = fsEvent.getHeader('transcription-session-finished');
|
||||||
|
if (this.vendor === 'microsoft' && finished === 'true') {
|
||||||
|
this.logger.debug('TaskGather:_onNoSpeechDetected for old gather, ignoring');
|
||||||
|
}
|
||||||
|
else {
|
||||||
this.logger.debug('TaskGather:_onNoSpeechDetected - listen again');
|
this.logger.debug('TaskGather:_onNoSpeechDetected - listen again');
|
||||||
return this._startTranscribing(ep);
|
this._startTranscribing(ep);
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,11 @@ class TaskTranscribe extends Task {
|
|||||||
this.logger.debug({hints: this.hints, hintsBoost: this.hintsBoost},
|
this.logger.debug({hints: this.hints, hintsBoost: this.hintsBoost},
|
||||||
'Transcribe:exec - applying global `sttHints');
|
'Transcribe:exec - applying global `sttHints');
|
||||||
}
|
}
|
||||||
|
if (cs.hasAltLanguages) {
|
||||||
|
this.altLanguages = this.altLanguages.concat(cs.altLanguages);
|
||||||
|
this.logger.debug({altLanguages: this.altLanguages},
|
||||||
|
'Gather:exec - applying altLanguages');
|
||||||
|
}
|
||||||
|
|
||||||
this.ep = ep;
|
this.ep = ep;
|
||||||
this.ep2 = ep2;
|
this.ep2 = ep2;
|
||||||
@@ -172,7 +177,8 @@ class TaskTranscribe extends Task {
|
|||||||
opts.GOOGLE_SPEECH_HINTS_BOOST = this.hintsBoost;
|
opts.GOOGLE_SPEECH_HINTS_BOOST = this.hintsBoost;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.altLanguages.length > 1) opts.GOOGLE_SPEECH_ALTERNATIVE_LANGUAGE_CODES = this.altLanguages.join(',');
|
if (this.altLanguages.length > 0) opts.GOOGLE_SPEECH_ALTERNATIVE_LANGUAGE_CODES = this.altLanguages.join(',');
|
||||||
|
else opts.GOOGLE_SPEECH_ALTERNATIVE_LANGUAGE_CODES = '';
|
||||||
if ('unspecified' !== this.interactionType) {
|
if ('unspecified' !== this.interactionType) {
|
||||||
opts.GOOGLE_SPEECH_METADATA_INTERACTION_TYPE = this.interactionType;
|
opts.GOOGLE_SPEECH_METADATA_INTERACTION_TYPE = this.interactionType;
|
||||||
}
|
}
|
||||||
@@ -229,7 +235,8 @@ class TaskTranscribe extends Task {
|
|||||||
if (this.hints && this.hints.length > 0) {
|
if (this.hints && this.hints.length > 0) {
|
||||||
opts.AZURE_SPEECH_HINTS = this.hints.map((h) => h.trim()).join(',');
|
opts.AZURE_SPEECH_HINTS = this.hints.map((h) => h.trim()).join(',');
|
||||||
}
|
}
|
||||||
if (this.altLanguages.length > 1) opts.AZURE_SPEECH_ALTERNATIVE_LANGUAGE_CODES = this.altLanguages.join(',');
|
if (this.altLanguages.length > 0) opts.AZURE_SPEECH_ALTERNATIVE_LANGUAGE_CODES = this.altLanguages.join(',');
|
||||||
|
else opts.AZURE_SPEECH_ALTERNATIVE_LANGUAGE_CODES = '';
|
||||||
if (this.requestSnr) opts.AZURE_REQUEST_SNR = 1;
|
if (this.requestSnr) opts.AZURE_REQUEST_SNR = 1;
|
||||||
if (this.profanityOption !== 'raw') opts.AZURE_PROFANITY_OPTION = this.profanityOption;
|
if (this.profanityOption !== 'raw') opts.AZURE_PROFANITY_OPTION = this.profanityOption;
|
||||||
if (this.initialSpeechTimeoutMs > 0) opts.AZURE_INITIAL_SPEECH_TIMEOUT_MS = this.initialSpeechTimeoutMs;
|
if (this.initialSpeechTimeoutMs > 0) opts.AZURE_INITIAL_SPEECH_TIMEOUT_MS = this.initialSpeechTimeoutMs;
|
||||||
|
|||||||
Reference in New Issue
Block a user