Fix formatting
parent
158ed0372f
commit
0b2b443efe
|
@ -1,25 +1,41 @@
|
||||||
const BaseEngine=require('../BaseEngine');
|
const BaseEngine = require('../BaseEngine');
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const querystring = require('querystring');
|
const querystring = require('querystring');
|
||||||
|
|
||||||
module.exports= class extends BaseEngine {
|
module.exports = class extends BaseEngine {
|
||||||
constructor() {
|
constructor() {
|
||||||
super("IBM Watson TTS","ogg");
|
super("IBM Watson TTS", "ogg");
|
||||||
this.voices={
|
this.voices = {};
|
||||||
'Michael': 'en-US_MichaelV3Voice',
|
this.populateVoiceList();
|
||||||
'Allison': 'en-US_AllisonV3Voice',
|
}
|
||||||
'Kevin': 'en-US_KevinV3Voice',
|
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() {
|
getDefaultVoice() {
|
||||||
return 'Michael';
|
return 'Michael';
|
||||||
}
|
}
|
||||||
async getSpeech(text, voice=this.getSpeechVoice(), params={}) {
|
IBMAuthString() {
|
||||||
const url = process.env.watsonURL+"/v1/synthesize?voice="+this.getInternalVoiceName(voice);
|
let buff = new Buffer('apikey:' + process.env.watsonAPIKey);
|
||||||
let buff=new Buffer('apikey:'+process.env.watsonAPIKey);
|
let b64auth = buff.toString('base64');
|
||||||
let b64auth=buff.toString('base64');
|
return 'Basic ' + b64auth;
|
||||||
const authorization='Basic '+b64auth;
|
}
|
||||||
const opts={
|
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",
|
method: "post",
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
@ -29,6 +45,6 @@ module.exports= class extends BaseEngine {
|
||||||
text: text
|
text: text
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
return fetch(url,opts);
|
return fetch(url, opts);
|
||||||
}
|
}
|
||||||
};
|
};
|
Loading…
Reference in New Issue