Added Google TTS, lowercase voices so that people don't have to remember ridiculous case

This commit is contained in:
2021-04-10 23:45:02 +02:00
parent 40e50b6546
commit f0c71d75dc
10 changed files with 927 additions and 11 deletions

View File

@@ -1,50 +0,0 @@
const BaseEngine = require('../BaseEngine');
const fetch = require('node-fetch');
const querystring = require('querystring');
module.exports = class extends BaseEngine {
constructor() {
super('watson',"IBM Watson TTS", "ogg");
this.voices = {};
this.populateVoiceList();
}
async populateVoiceList() {
const url = process.env.watsonURL + "/v1/voices";
const authorization = this.IBMAuthString();
const opts = {
method: "get",
headers: {
'Authorization': authorization
},
}
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';
}
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();
const opts = {
method: "post",
headers: {
'Content-Type': 'application/json',
'Authorization': authorization
},
body: JSON.stringify({
text: text
})
};
return fetch(url, opts);
}
};