Discussions

Ask a Question
Back to all

Create a Talk using Elevenlabs voiceId

I am trying to use an elevenlabs cloned voice, but I can´t figure it out where is the error. I am using 'x-api-key-external' on headers but there is no response and no particular error from d-id, this is the code I´m using:

const api = axios.create({
baseURL: 'https://api.d-id.com',
headers: { authorization: Basic ${didApiKey},
'x-api-key-external': {"elevenlabs": "${elevenlabsKey}"}
}
});

async function generateAvatarVideo({ source_image_url, voice_id, text }) {
if (!source_image_url || !voice_id || !text) {
throw new Error('Faltan parámetros requeridos para generar el video');
}

try {
const response = await api.post('/talks', {
source_url: source_image_url,
script: {
type: 'text',
input: text,
subtitles: false,
provider: { type: 'elevenlabs', voice_id: voice_id }
},
config: {
fluent: false
}
});

return response.data; // Este objeto contiene el `id` (talkId) y otros campos como `status_url`

} catch (error) {
let errorMessage = 'Error desconocido';
if (error.response && error.response.data) {
try {
errorMessage = JSON.stringify(error.response.data, null, 2);
} catch (err) {
errorMessage = '[No se pudo serializar error.response.data]';
}
} else {
errorMessage = error.message || 'Sin mensaje de error';
}

console.error('❌ Error en generateAvatarVideo:\n', errorMessage);
throw new Error('Error al generar video con D-ID');

}
}