Add Eleven Labs TTS

master
guilevi 2023-03-08 13:14:48 +00:00
parent 9d25ed6e7b
commit 136173f4de
1 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,46 @@
const BaseEngine = require('../BaseEngine');
const fetch = require('node-fetch');
const querystring = require('querystring');
module.exports = class extends BaseEngine {
constructor() {
super('eleven',"Eleven Labs TTS", "mp3");
this.voices = {};
this.populateVoiceList();
}
async populateVoiceList() {
const url = "https://api.elevenlabs.io/v1/voices";
const authorization = process.env.XI_API_KEY;
const opts = {
method: "get",
headers: {
'xi-api-key': authorization
},
}
const res = await fetch(url, opts);
const voices = await res.json();
voices.voices.forEach((i) => {
let voiceName = i.name.toLowerCase();
this.voices[voiceName] = i.voice_id;
});
}
getDefaultVoice() {
return 'Guillem';
}
async getSpeech(text, voice = this.getSpeechVoice(), params = {}) {
const url = "https://api.elevenlabs.io/v1/text-to-speech/" + this.getInternalVoiceName(voice);
const authorization = process.env.XI_API_KEY;
const opts = {
method: "post",
headers: {
'Content-Type': 'application/json',
'voice_id': this.getInternalVoiceName(voice),
'xi-api-key': authorization
},
body: JSON.stringify({
text: text
})
};
return fetch(url, opts);
}
};