From f709282ca199e566c37efade6291373565f80328 Mon Sep 17 00:00:00 2001 From: Talon Date: Sun, 12 Nov 2023 23:59:03 +0100 Subject: [PATCH] Add unreal tts --- tts/unreal/index.js | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tts/unreal/index.js diff --git a/tts/unreal/index.js b/tts/unreal/index.js new file mode 100644 index 0000000..ab0be87 --- /dev/null +++ b/tts/unreal/index.js @@ -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; + } +}; \ No newline at end of file