mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2026-02-14 18:30:59 +00:00
fix config and stt task for altLanguages (#575)
* fix config and stt task for altLanguages * clear freeswitch channel var when altLanguages is empty list
This commit is contained in:
@@ -116,14 +116,6 @@ class TaskGather extends SttTask {
|
|||||||
this.logger.debug({hints: this.data.recognizer.hints, hintsBoost: this.data.recognizer.hintsBoost},
|
this.logger.debug({hints: this.data.recognizer.hints, hintsBoost: this.data.recognizer.hintsBoost},
|
||||||
'Gather:exec - applying global sttHints');
|
'Gather:exec - applying global sttHints');
|
||||||
}
|
}
|
||||||
if (cs.hasAltLanguages) {
|
|
||||||
this.data.recognizer.altLanguages = this.data.recognizer.altLanguages.concat(cs.altLanguages);
|
|
||||||
this.logger.debug({altLanguages: this.data.recognizer?.altLanguages},
|
|
||||||
'Gather:exec - applying altLanguages');
|
|
||||||
}
|
|
||||||
if (cs.hasGlobalSttPunctuation && !this.data.recognizer.punctuation) {
|
|
||||||
this.data.recognizer.punctuation = cs.globalSttPunctuation;
|
|
||||||
}
|
|
||||||
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;
|
||||||
|
|||||||
@@ -91,19 +91,19 @@ class SttTask extends Task {
|
|||||||
|
|
||||||
if (cs.recognizer) {
|
if (cs.recognizer) {
|
||||||
for (const k in cs.recognizer) {
|
for (const k in cs.recognizer) {
|
||||||
if (typeof this.data.recognizer[k] === 'object' ||
|
if (Array.isArray(this.data.recognizer[k]) ||
|
||||||
|
Array.isArray(cs.recognizer[k])) {
|
||||||
|
this.data.recognizer[k] = [
|
||||||
|
...this.data.recognizer[k],
|
||||||
|
...cs.recognizer[k]
|
||||||
|
];
|
||||||
|
} else if (typeof this.data.recognizer[k] === 'object' ||
|
||||||
typeof cs.recognizer[k] === 'object'
|
typeof cs.recognizer[k] === 'object'
|
||||||
) {
|
) {
|
||||||
this.data.recognizer[k] = {
|
this.data.recognizer[k] = {
|
||||||
...this.data.recognizer[k],
|
...this.data.recognizer[k],
|
||||||
...cs.recognizer[k]
|
...cs.recognizer[k]
|
||||||
};
|
};
|
||||||
} else if (Array.isArray(this.data.recognizer[k]) ||
|
|
||||||
Array.isArray(cs.recognizer[k])) {
|
|
||||||
this.data.recognizer[k] = [
|
|
||||||
...this.data.recognizer[k],
|
|
||||||
...cs.recognizer[k]
|
|
||||||
];
|
|
||||||
} else {
|
} else {
|
||||||
this.data.recognizer[k] = cs.recognizer[k] || this.data.recognizer[k];
|
this.data.recognizer[k] = cs.recognizer[k] || this.data.recognizer[k];
|
||||||
}
|
}
|
||||||
@@ -127,6 +127,15 @@ class SttTask extends Task {
|
|||||||
this.notifyError({ msg: 'ASR error', details:'Cobalt requires a model to be specified'});
|
this.notifyError({ msg: 'ASR error', details:'Cobalt requires a model to be specified'});
|
||||||
throw new Error('Cobalt requires a model to be specified');
|
throw new Error('Cobalt requires a model to be specified');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cs.hasAltLanguages) {
|
||||||
|
this.data.recognizer.altLanguages = this.data.recognizer.altLanguages.concat(cs.altLanguages);
|
||||||
|
this.logger.debug({altLanguages: this.altLanguages},
|
||||||
|
'STT:exec - applying altLanguages');
|
||||||
|
}
|
||||||
|
if (cs.hasGlobalSttPunctuation && !this.data.recognizer.punctuation) {
|
||||||
|
this.data.recognizer.punctuation = cs.globalSttPunctuation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async _initSpeechCredentials(cs, vendor, label) {
|
async _initSpeechCredentials(cs, vendor, label) {
|
||||||
|
|||||||
@@ -64,14 +64,7 @@ class TaskTranscribe extends SttTask {
|
|||||||
this.logger.debug({hints: this.data.recognizer.hints, hintsBoost: this.data.recognizer.hintsBoost},
|
this.logger.debug({hints: this.data.recognizer.hints, hintsBoost: this.data.recognizer.hintsBoost},
|
||||||
'Transcribe:exec - applying global sttHints');
|
'Transcribe:exec - applying global sttHints');
|
||||||
}
|
}
|
||||||
if (cs.hasAltLanguages) {
|
|
||||||
this.data.recognizer.altLanguages = this.data.recognizer.altLanguages.concat(cs.altLanguages);
|
|
||||||
this.logger.debug({altLanguages: this.altLanguages},
|
|
||||||
'Transcribe:exec - applying altLanguages');
|
|
||||||
}
|
|
||||||
if (cs.hasGlobalSttPunctuation && !this.data.recognizer.punctuation) {
|
|
||||||
this.data.recognizer.punctuation = cs.globalSttPunctuation;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
await this._startTranscribing(cs, ep, 1);
|
await this._startTranscribing(cs, ep, 1);
|
||||||
if (this.separateRecognitionPerChannel && ep2) {
|
if (this.separateRecognitionPerChannel && ep2) {
|
||||||
|
|||||||
@@ -474,7 +474,8 @@ module.exports = (logger) => {
|
|||||||
...(rOpts.hints?.length > 0 && typeof rOpts.hints[0] === 'object' &&
|
...(rOpts.hints?.length > 0 && typeof rOpts.hints[0] === 'object' &&
|
||||||
{GOOGLE_SPEECH_HINTS: JSON.stringify(rOpts.hints)}),
|
{GOOGLE_SPEECH_HINTS: JSON.stringify(rOpts.hints)}),
|
||||||
...(typeof rOpts.hintsBoost === 'number' && {GOOGLE_SPEECH_HINTS_BOOST: rOpts.hintsBoost}),
|
...(typeof rOpts.hintsBoost === 'number' && {GOOGLE_SPEECH_HINTS_BOOST: rOpts.hintsBoost}),
|
||||||
...(rOpts.altLanguages?.length > 0 &&
|
// When altLanguages is emptylist, we have to send value to freeswitch to clear the previous settings
|
||||||
|
...(rOpts.altLanguages &&
|
||||||
{GOOGLE_SPEECH_ALTERNATIVE_LANGUAGE_CODES: [...new Set(rOpts.altLanguages)].join(',')}),
|
{GOOGLE_SPEECH_ALTERNATIVE_LANGUAGE_CODES: [...new Set(rOpts.altLanguages)].join(',')}),
|
||||||
...(rOpts.interactionType &&
|
...(rOpts.interactionType &&
|
||||||
{GOOGLE_SPEECH_METADATA_INTERACTION_TYPE: rOpts.interactionType}),
|
{GOOGLE_SPEECH_METADATA_INTERACTION_TYPE: rOpts.interactionType}),
|
||||||
@@ -504,7 +505,8 @@ module.exports = (logger) => {
|
|||||||
{AZURE_SPEECH_HINTS: rOpts.hints.map((h) => h.trim()).join(',')}),
|
{AZURE_SPEECH_HINTS: rOpts.hints.map((h) => h.trim()).join(',')}),
|
||||||
...(rOpts.hints?.length > 0 && typeof rOpts.hints[0] === 'object' &&
|
...(rOpts.hints?.length > 0 && typeof rOpts.hints[0] === 'object' &&
|
||||||
{AZURE_SPEECH_HINTS: rOpts.hints.map((h) => h.phrase).join(',')}),
|
{AZURE_SPEECH_HINTS: rOpts.hints.map((h) => h.phrase).join(',')}),
|
||||||
...(rOpts.altLanguages && rOpts.altLanguages.length > 0 &&
|
// When altLanguages is emptylist, we have to send value to freeswitch to clear the previous settings
|
||||||
|
...(rOpts.altLanguages &&
|
||||||
{AZURE_SPEECH_ALTERNATIVE_LANGUAGE_CODES: [...new Set(rOpts.altLanguages)].join(',')}),
|
{AZURE_SPEECH_ALTERNATIVE_LANGUAGE_CODES: [...new Set(rOpts.altLanguages)].join(',')}),
|
||||||
...(rOpts.requestSnr && {AZURE_REQUEST_SNR: 1}),
|
...(rOpts.requestSnr && {AZURE_REQUEST_SNR: 1}),
|
||||||
...(rOpts.profanityOption && {AZURE_PROFANITY_OPTION: rOpts.profanityOption}),
|
...(rOpts.profanityOption && {AZURE_PROFANITY_OPTION: rOpts.profanityOption}),
|
||||||
|
|||||||
@@ -312,6 +312,127 @@ test('\'transcribe\' test - google with asrTimeout', async(t) => {
|
|||||||
t.ok(obj.body.speech.alternatives[0].transcript.toLowerCase().startsWith('i\'d like to speak to customer support'),
|
t.ok(obj.body.speech.alternatives[0].transcript.toLowerCase().startsWith('i\'d like to speak to customer support'),
|
||||||
'transcribe: succeeds when using google credentials');
|
'transcribe: succeeds when using google credentials');
|
||||||
|
|
||||||
|
disconnect();
|
||||||
|
} catch (err) {
|
||||||
|
console.log(`error received: ${err}`);
|
||||||
|
disconnect();
|
||||||
|
t.error(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('\'transcribe\' test - deepgram config options altLanguages', async(t) => {
|
||||||
|
if (!DEEPGRAM_API_KEY ) {
|
||||||
|
t.pass('skipping deepgram tests');
|
||||||
|
return t.end();
|
||||||
|
}
|
||||||
|
clearModule.all();
|
||||||
|
const {srf, disconnect} = require('../app');
|
||||||
|
|
||||||
|
try {
|
||||||
|
await connect(srf);
|
||||||
|
// GIVEN
|
||||||
|
let verbs = [
|
||||||
|
{
|
||||||
|
"verb": "config",
|
||||||
|
"recognizer": {
|
||||||
|
"vendor": "deepgram",
|
||||||
|
"language": "en-US",
|
||||||
|
"altLanguages": [
|
||||||
|
"en-US"
|
||||||
|
],
|
||||||
|
"deepgramOptions": {
|
||||||
|
"model": "2-ea",
|
||||||
|
"tier": "nova",
|
||||||
|
"numerals": true,
|
||||||
|
"ner": true,
|
||||||
|
"vadTurnoff": 10,
|
||||||
|
"keywords": [
|
||||||
|
"CPT"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"verb": "transcribe",
|
||||||
|
"transcriptionHook": "/transcriptionHook",
|
||||||
|
"recognizer": {
|
||||||
|
"vendor": "deepgram",
|
||||||
|
"hints": ["customer support", "sales", "human resources", "HR"],
|
||||||
|
"deepgramOptions": {
|
||||||
|
"apiKey": DEEPGRAM_API_KEY,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
let from = "gather_success_no_altLanguages";
|
||||||
|
await provisionCallHook(from, verbs);
|
||||||
|
// THEN
|
||||||
|
await sippUac('uac-gather-account-creds-success.xml', '172.38.0.10', from);
|
||||||
|
let obj = await getJSON(`http://127.0.0.1:3100/lastRequest/${from}_actionHook`);
|
||||||
|
t.ok(obj.body.speech.alternatives[0].transcript.toLowerCase().includes('like to speak to customer support'),
|
||||||
|
'transcribe: succeeds when using deepgram credentials');
|
||||||
|
|
||||||
|
disconnect();
|
||||||
|
} catch (err) {
|
||||||
|
console.log(`error received: ${err}`);
|
||||||
|
disconnect();
|
||||||
|
t.error(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('\'transcribe\' test - deepgram config options altLanguages', async(t) => {
|
||||||
|
if (!DEEPGRAM_API_KEY ) {
|
||||||
|
t.pass('skipping deepgram tests');
|
||||||
|
return t.end();
|
||||||
|
}
|
||||||
|
clearModule.all();
|
||||||
|
const {srf, disconnect} = require('../app');
|
||||||
|
|
||||||
|
try {
|
||||||
|
await connect(srf);
|
||||||
|
// GIVEN
|
||||||
|
let verbs = [
|
||||||
|
{
|
||||||
|
"verb": "config",
|
||||||
|
"recognizer": {
|
||||||
|
"vendor": "deepgram",
|
||||||
|
"language": "en-US",
|
||||||
|
"altLanguages": [
|
||||||
|
"en-US"
|
||||||
|
],
|
||||||
|
"deepgramOptions": {
|
||||||
|
"model": "2-ea",
|
||||||
|
"tier": "nova",
|
||||||
|
"numerals": true,
|
||||||
|
"ner": true,
|
||||||
|
"vadTurnoff": 10,
|
||||||
|
"keywords": [
|
||||||
|
"CPT"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"verb": "transcribe",
|
||||||
|
"transcriptionHook": "/transcriptionHook",
|
||||||
|
"recognizer": {
|
||||||
|
"vendor": "deepgram",
|
||||||
|
"hints": ["customer support", "sales", "human resources", "HR"],
|
||||||
|
"altLanguages": [],
|
||||||
|
"deepgramOptions": {
|
||||||
|
"apiKey": DEEPGRAM_API_KEY,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
let from = "gather_success_has_altLanguages";
|
||||||
|
await provisionCallHook(from, verbs);
|
||||||
|
// THEN
|
||||||
|
await sippUac('uac-gather-account-creds-success.xml', '172.38.0.10', from);
|
||||||
|
let obj = await getJSON(`http://127.0.0.1:3100/lastRequest/${from}_actionHook`);
|
||||||
|
t.ok(obj.body.speech.alternatives[0].transcript.toLowerCase().includes('like to speak to customer support'),
|
||||||
|
'transcribe: succeeds when using deepgram credentials');
|
||||||
|
|
||||||
disconnect();
|
disconnect();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(`error received: ${err}`);
|
console.log(`error received: ${err}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user