tardis-bot/tts/watson/index.js

34 lines
905 B
JavaScript
Raw Normal View History

2021-04-06 00:16:09 +00:00
const BaseEngine=require('../BaseEngine');
const fetch = require('node-fetch');
const querystring = require('querystring');
module.exports= class extends BaseEngine {
constructor() {
super("IBM Watson TTS","ogg");
this.voices={
'Michael': 'en-US_MichaelV3Voice',
'Allison': 'en-US_AllisonV3Voice',
'Kevin': 'en-US_KevinV3Voice',
};
}
getDefaultVoice() {
return 'Michael';
2021-04-06 00:16:09 +00:00
}
async getSpeech(text, voice=this.getSpeechVoice(), params={}) {
const url = process.env.watsonURL+"/v1/synthesize?voice="+this.getInternalVoiceName(voice);
2021-04-06 00:16:09 +00:00
let buff=new Buffer('apikey:'+process.env.watsonAPIKey);
let b64auth=buff.toString('base64');
const authorization='Basic '+b64auth;
const opts={
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-06 00:56:23 +00:00
return fetch(url,opts);
2021-04-06 00:16:09 +00:00
}
};