tardis-bot/tts/openai/index.js

37 lines
1.0 KiB
JavaScript

const BaseEngine = require('../BaseEngine');
const fetch = require('node-fetch');
const tts = require('google-tts-api');
module.exports = class extends BaseEngine {
constructor() {
super('openai', "OpenAI TTS", "mp3");
this.voices = {
alloy: "alloy",
echo: "echo",
fable: "fable",
onyx: "onyx",
nova: "nova",
shimmer: "shimmer"
}
}
getDefaultVoice() {
return 'Alloy';
}
async getSpeech(text, voice = this.getDefaultVoice(), params = {}) {
const url = `https://api.openai.com/v1/audio/speech`;
const opts = {
method: "post",
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${process.env["OPENAI_API_KEY"]}`
},
body: JSON.stringify({
model: "tts-1-hd",
input: text,
voice: voice,
})
}
console.log(opts);
return fetch(url, opts);
}
};