mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
session-level speech hints, strip trailing punctuation on continuous asr (#151)
This commit is contained in:
@@ -261,6 +261,19 @@ class CallSession extends Emitter {
|
|||||||
|
|
||||||
get recordState() { return this._recordState; }
|
get recordState() { return this._recordState; }
|
||||||
|
|
||||||
|
set globalSttHints({hints, hintsBoost}) {
|
||||||
|
this._globalSttHints = {hints, hintsBoost};
|
||||||
|
}
|
||||||
|
|
||||||
|
get hasGlobalSttHints() {
|
||||||
|
const {hints = []} = this._globalSttHints || {};
|
||||||
|
return hints.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
get globalSttHints() {
|
||||||
|
return this._globalSttHints;
|
||||||
|
}
|
||||||
|
|
||||||
async notifyRecordOptions(opts) {
|
async notifyRecordOptions(opts) {
|
||||||
const {action} = opts;
|
const {action} = opts;
|
||||||
this.logger.debug({opts}, 'CallSession:notifyRecordOptions');
|
this.logger.debug({opts}, 'CallSession:notifyRecordOptions');
|
||||||
|
|||||||
@@ -87,6 +87,13 @@ class TaskConfig extends Task {
|
|||||||
cs.asrTimeout = this.recognizer.asrTimeout;
|
cs.asrTimeout = this.recognizer.asrTimeout;
|
||||||
cs.asrDtmfTerminationDigit = this.recognizer.asrDtmfTerminationDigit;
|
cs.asrDtmfTerminationDigit = this.recognizer.asrDtmfTerminationDigit;
|
||||||
}
|
}
|
||||||
|
if (Array.isArray(this.recognizer.hints)) {
|
||||||
|
const obj = {hints: this.recognizer.hints};
|
||||||
|
if (typeof this.recognizer.hintsBoost === 'number') {
|
||||||
|
obj.hintsBoost = this.recognizer.hintsBoost;
|
||||||
|
}
|
||||||
|
cs.globalSttHints = obj;
|
||||||
|
}
|
||||||
this.logger.info({
|
this.logger.info({
|
||||||
recognizer: this.recognizer,
|
recognizer: this.recognizer,
|
||||||
isContinuousAsr: cs.isContinuousAsr
|
isContinuousAsr: cs.isContinuousAsr
|
||||||
|
|||||||
@@ -121,6 +121,13 @@ class TaskGather extends Task {
|
|||||||
await super.exec(cs);
|
await super.exec(cs);
|
||||||
const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, cs.srf);
|
const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, cs.srf);
|
||||||
|
|
||||||
|
if (cs.hasGlobalSttHints) {
|
||||||
|
const {hints, hintsBoost} = cs.globalSttHints;
|
||||||
|
this.hints = this.hints.concat(hints);
|
||||||
|
if (!this.hintsBoost && hintsBoost) this.hintsBoost = hintsBoost;
|
||||||
|
this.logger.debug({hints: this.hints, hintsBoost: this.hintsBoost},
|
||||||
|
'Gather:exec - applying global sttHints');
|
||||||
|
}
|
||||||
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;
|
||||||
@@ -286,7 +293,7 @@ class TaskGather extends Task {
|
|||||||
].forEach((arr) => {
|
].forEach((arr) => {
|
||||||
if (this[arr[0]]) opts[arr[1]] = true;
|
if (this[arr[0]]) opts[arr[1]] = true;
|
||||||
});
|
});
|
||||||
if (this.hints.length > 1) {
|
if (this.hints.length > 0) {
|
||||||
opts.GOOGLE_SPEECH_HINTS = this.hints.join(',');
|
opts.GOOGLE_SPEECH_HINTS = this.hints.join(',');
|
||||||
if (typeof this.hintsBoost === 'number') {
|
if (typeof this.hintsBoost === 'number') {
|
||||||
opts.GOOGLE_SPEECH_HINTS_BOOST = this.hintsBoost;
|
opts.GOOGLE_SPEECH_HINTS_BOOST = this.hintsBoost;
|
||||||
@@ -333,7 +340,7 @@ class TaskGather extends Task {
|
|||||||
'AZURE_REGION': this.sttCredentials.region
|
'AZURE_REGION': this.sttCredentials.region
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (this.hints && this.hints.length > 1) {
|
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 && this.altLanguages.length > 0) {
|
if (this.altLanguages && this.altLanguages.length > 0) {
|
||||||
@@ -487,6 +494,15 @@ class TaskGather extends Task {
|
|||||||
}
|
}
|
||||||
if (this.isContinuousAsr) {
|
if (this.isContinuousAsr) {
|
||||||
/* append the transcript and start listening again for asrTimeout */
|
/* append the transcript and start listening again for asrTimeout */
|
||||||
|
const t = evt.alternatives[0].transcript;
|
||||||
|
if (t) {
|
||||||
|
/* remove trailing punctuation */
|
||||||
|
if (/[,;:\.!\?]$/.test(t)) {
|
||||||
|
this.logger.debug('TaskGather:_onTranscription - removing trailing punctuation');
|
||||||
|
evt.alternatives[0].transcript = t.slice(0, -1);
|
||||||
|
}
|
||||||
|
else this.logger.debug({t}, 'TaskGather:_onTranscription - no trailing punctuation');
|
||||||
|
}
|
||||||
this.logger.info({evt}, 'TaskGather:_onTranscription - got transcript during continous asr');
|
this.logger.info({evt}, 'TaskGather:_onTranscription - got transcript during continous asr');
|
||||||
this._bufferedTranscripts.push(evt);
|
this._bufferedTranscripts.push(evt);
|
||||||
this._clearTimer();
|
this._clearTimer();
|
||||||
|
|||||||
@@ -62,6 +62,14 @@ class TaskTranscribe extends Task {
|
|||||||
super.exec(cs);
|
super.exec(cs);
|
||||||
const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, cs.srf);
|
const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, cs.srf);
|
||||||
|
|
||||||
|
if (cs.hasGlobalSttHints) {
|
||||||
|
const {hints, hintsBoost} = cs.globalSttHints;
|
||||||
|
this.hints = this.hints.concat(hints);
|
||||||
|
if (!this.hintsBoost && hintsBoost) this.hintsBoost = hintsBoost;
|
||||||
|
this.logger.debug({hints: this.hints, hintsBoost: this.hintsBoost},
|
||||||
|
'Transcribe:exec - applying global `sttHints');
|
||||||
|
}
|
||||||
|
|
||||||
this.ep = ep;
|
this.ep = ep;
|
||||||
this.ep2 = ep2;
|
this.ep2 = ep2;
|
||||||
if ('default' === this.vendor || !this.vendor) this.vendor = cs.speechRecognizerVendor;
|
if ('default' === this.vendor || !this.vendor) this.vendor = cs.speechRecognizerVendor;
|
||||||
@@ -158,7 +166,7 @@ class TaskTranscribe extends Task {
|
|||||||
].forEach((arr) => {
|
].forEach((arr) => {
|
||||||
if (this[arr[0]]) opts[arr[1]] = true;
|
if (this[arr[0]]) opts[arr[1]] = true;
|
||||||
});
|
});
|
||||||
if (this.hints.length > 1) {
|
if (this.hints.length > 0) {
|
||||||
opts.GOOGLE_SPEECH_HINTS = this.hints.join(',');
|
opts.GOOGLE_SPEECH_HINTS = this.hints.join(',');
|
||||||
if (typeof this.hintsBoost === 'number') {
|
if (typeof this.hintsBoost === 'number') {
|
||||||
opts.GOOGLE_SPEECH_HINTS_BOOST = this.hintsBoost;
|
opts.GOOGLE_SPEECH_HINTS_BOOST = this.hintsBoost;
|
||||||
@@ -218,7 +226,7 @@ class TaskTranscribe extends Task {
|
|||||||
'AZURE_SUBSCRIPTION_KEY': this.sttCredentials.api_key,
|
'AZURE_SUBSCRIPTION_KEY': this.sttCredentials.api_key,
|
||||||
'AZURE_REGION': this.sttCredentials.region
|
'AZURE_REGION': this.sttCredentials.region
|
||||||
});
|
});
|
||||||
if (this.hints && this.hints.length > 1) {
|
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 > 1) opts.AZURE_SPEECH_ALTERNATIVE_LANGUAGE_CODES = this.altLanguages.join(',');
|
||||||
|
|||||||
Reference in New Issue
Block a user