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

@@ -2,6 +2,7 @@ const Task = require('../../task');
const TaskName = 'Llm_Elevenlabs_s2s';
const {LlmEvents_Elevenlabs} = require('../../../utils/constants');
const {request} = require('undici');
const { parseDecibels } = require('drachtio-fsmrf/lib/utils');
const ClientEvent = 'client.event';
const SessionDelete = 'session.delete';
@@ -73,6 +74,28 @@ class TaskLlmElevenlabs_S2S extends Task {
get name() { return TaskName; }
configureDialTranslate(opts) {
const {language, gain} = opts;
const {naturalVoice, translatedVoice} = gain;
this.replace_read = true;
this.audio_in_gain = parseDecibels(naturalVoice);
this.audio_injection_gain = parseDecibels(translatedVoice);
// override the agent prompt to ask for a translation
this.conversation_initiation_client_data = {
...(this.conversation_initiation_client_data || {}),
conversation_config_override: {
...(this.conversation_initiation_client_data?.conversation_config_override || {}),
agent: {
prompt: {
prompt: `Please translate the text to ${language}.
Your response should only include the ${language} translation, without any additional words:\n\n`
}
}
}
};
}
async getSignedUrl() {
if (!this.api_key) {
return {
@@ -164,7 +187,8 @@ class TaskLlmElevenlabs_S2S extends Task {
try {
const {host, path} = await this.getSignedUrl();
const args = [ep.uuid, 'session.create', this.input_sample_rate, this.output_sample_rate, host, path];
const args = [ep.uuid, 'session.create', this.input_sample_rate, this.output_sample_rate, host, path,
...(this.replace_read ? ['replace_read', this.audio_in_gain, this.audio_injection_gain] : [])];
await this._api(ep, args);
} catch (err) {
this.logger.error({err}, 'TaskLlmElevenlabs_S2S:_startListening');