tardis-bot/tts/watson/index.js

65 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-04-07 09:13:21 +00:00
const BaseEngine = require('../BaseEngine');
2021-04-06 00:16:09 +00:00
const fetch = require('node-fetch');
const querystring = require('querystring');
2021-04-07 09:13:21 +00:00
module.exports = class extends BaseEngine {
2021-04-06 00:16:09 +00:00
constructor() {
2021-04-07 09:13:21 +00:00
super("IBM Watson TTS", "ogg");
<<<<<<< HEAD
2021-04-07 09:13:21 +00:00
this.voices = {};
this.populateVoiceList();
}
async populateVoiceList() {
const url = process.env.watsonURL + "/v1/voices";
const authorization = this.IBMAuthString();
const opts = {
method: "get",
headers: {
'Authorization': authorization
},
=======
2021-04-06 23:36:35 +00:00
this.voices = {
'Michael': 'en-US_MichaelV3Voice',
'Allison': 'en-US_AllisonV3Voice',
'Kevin': 'en-US_KevinV3Voice',
>>>>>>> 12a9f8fc5374d912e595cea204998daa4d7220ba
};
2021-04-07 09:13:21 +00:00
const res = await fetch(url, opts);
const voices = await res.json();
voices.voices.forEach((i) => {
let voiceName = i.description.substring(0, i.description.indexOf(':'));
this.voices[voiceName] = i.name;
});
}
getDefaultVoice() {
return 'Michael';
2021-04-06 00:16:09 +00:00
}
<<<<<<< HEAD
2021-04-07 09:13:21 +00:00
IBMAuthString() {
let buff = new Buffer('apikey:' + process.env.watsonAPIKey);
let b64auth = buff.toString('base64');
return 'Basic ' + b64auth;
}
async getSpeech(text, voice = this.getSpeechVoice(), params = {}) {
const url = process.env.watsonURL + "/v1/synthesize?voice=" + this.getInternalVoiceName(voice);
const authorization = this.IBMAuthString();
=======
2021-04-06 23:36:35 +00:00
async getSpeech(text, voice = this.getSpeechVoice(), params = {}) {
const url = process.env.watsonURL + "/v1/synthesize?voice=" + this.getInternalVoiceName(voice);
let buff = new Buffer('apikey:' + process.env.watsonAPIKey);
let b64auth = buff.toString('base64');
const authorization = 'Basic ' + b64auth;
>>>>>>> 12a9f8fc5374d912e595cea204998daa4d7220ba
2021-04-07 09:13:21 +00:00
const opts = {
2021-04-06 00:16:09 +00:00
method: "post",
headers: {
'Content-Type': 'application/json',
'Authorization': authorization
},
2021-04-06 00:56:23 +00:00
body: JSON.stringify({
2021-04-06 00:16:09 +00:00
text: text
2021-04-06 00:56:23 +00:00
})
2021-04-06 00:16:09 +00:00
};
2021-04-07 09:13:21 +00:00
return fetch(url, opts);
2021-04-06 00:16:09 +00:00
}
};