support dial translate

This commit is contained in:
Quan HL
2025-02-03 22:29:05 +07:00
parent 7105453d81
commit 1e9dd31f67
3 changed files with 68 additions and 1 deletions

View File

@@ -110,6 +110,7 @@ class TaskDial extends Task {
this.tag = this.data.tag;
this.boostAudioSignal = this.data.boostAudioSignal;
this._mediaPath = MediaPath.FullMedia;
this.translate = this.data.translate;
if (this.dtmfHook) {
const {parentDtmfCollector, childDtmfCollector} = parseDtmfOptions(logger, this.data.dtmfCapture || {});
@@ -158,6 +159,7 @@ class TaskDial extends Task {
get canReleaseMedia() {
const keepAnchor = this.data.anchorMedia ||
this.data.translate ||
this.cs.isBackGroundListen ||
this.cs.onHoldMusic ||
ANCHOR_MEDIA_ALWAYS ||
@@ -291,6 +293,17 @@ class TaskDial extends Task {
this.transcribeTask.span.end();
this.transcribeTask = null;
}
if (this.llmTask) {
await this.llmTask.kill(cs);
this.llmTask.span.end();
this.llmTask = null;
}
if (this.sdLlmTask) {
await this.sdLlmTask.kill(cs);
this.sdLlmTask.span.end();
this.sdLlmTask = null;
}
this.notifyTaskDone();
}
@@ -758,6 +771,30 @@ class TaskDial extends Task {
this._killOutdials(); // NB: order is important
}
async _startTranslate(cs, sd) {
if (this.translate) {
const {callerLanguage, calleeLanguage, gain} = this.translate;
assert(this.translate.llm, 'Dial:_startTranslate - missing llm in translate');
this.logger.debug('Dial:_startTranslate start llm services');
// setup caller LLM task
this.llmTask = makeTask(this.logger, {'llm': this.translate.llm});
this.llmTask.configureDialTranslate({
language: callerLanguage,
gain,
});
// setup callee LLM task
this.sdLlmTask = makeTask(this.logger, {'llm': this.translate.llm});
this.sdLlmTask.configureDialTranslate({
language: calleeLanguage,
gain,
});
this.llmTask.exec(cs, {ep: this.ep});
this.sdLlmTask.exec(cs, {ep: sd.ep});
}
}
async _onReinvite(req, res) {
try {
let isHandled = false;