mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-21 09:08:02 +00:00
support dial translate
This commit is contained in:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user