Add unreal tts

master
Talon 2023-11-12 23:59:03 +01:00
parent 0ed2b4d091
commit f709282ca1
1 changed files with 47 additions and 0 deletions
tts/unreal

View File

@ -0,0 +1,47 @@
const BaseEngine = require('../BaseEngine');
const fetch = require('node-fetch');
const querystring = require('querystring');
const fs = require("fs");
module.exports = class extends BaseEngine {
constructor() {
super('unreal', "Unreal Speech TTS", "mp3");
this.voices = {
scarlett: 'Scarlett',
liv: 'Liv',
dan: 'Dan',
will: 'Will',
amy: 'Amy'
};
}
getDefaultVoice() {
return 'Liv';
}
async getSpeechFile(text, filepath, voice = this.getDefaultVoice(), params = {}) {
const url = "https://api.v6.unrealspeech.com/speech";
const authorization = process.env.UNREAL_API_KEY;
const opts = {
method: "post",
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${authorization}`
},
body: JSON.stringify({
Bitrate: "320k",
Temperature: 0.1,
VoiceId: this.getInternalVoiceName(voice),
Text: text,
AudioFormat: "mp3"
})
};
const res = await fetch(url, opts);
const json = await res.json();
const data = await fetch(json.OutputUri);
const contents = await data.arrayBuffer();
const buf = Buffer.from(contents);
fs.writeFileSync(filepath, buf);
return filepath;
}
};