diff --git a/tts/openai/index.js b/tts/openai/index.js new file mode 100644 index 0000000..cc7f6ca --- /dev/null +++ b/tts/openai/index.js @@ -0,0 +1,37 @@ +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); + } +}; \ No newline at end of file