This commit is contained in:
2021-04-06 02:16:09 +02:00
parent b444508fb8
commit 110b78c762
11 changed files with 88 additions and 22 deletions

BIN
tts/.DS_Store vendored Normal file

Binary file not shown.

16
tts/BaseEngine/index.js Normal file
View File

@@ -0,0 +1,16 @@
const fs=require('fs');
module.exports=class {
constructor(longName, fileExtension, supportedParameters=[]) {
this.longName=longName;
this.fileExtension=fileExtension;
}
async getSpeech(text, voice, params) {}
async getSpeechFile(text, filepath, voice, params) {
const data = await this.getSpeech(text, voice, params);
const contents = await data.arrayBuffer();
const buf = Buffer.from(contents);
fs.writeFileSync(filepath, buf);
return filepath;
}
}

11
tts/espeak/index.js Normal file
View File

@@ -0,0 +1,11 @@
const BaseEngine=require('../BaseEngine')
const {spawn} = require('child_process')
module.exports=class extends BaseEngine {
constructor() {
super('ESpeak','wav')
}
async getSpeechFile(text, filepath, voice='en', params={}) {
await spawn('espeak', ['-v', voice, '-w',filepath, text]);
}
}

13
tts/gtranslate/index.js Normal file
View File

@@ -0,0 +1,13 @@
const BaseEngine=require('../BaseEngine');
const fetch = require('node-fetch');
const tts = require('google-tts-api');
module.exports= class extends BaseEngine {
constructor() {
super("Google Translate TTS","mp3");
}
async getSpeech(text, voice='en-us', params={}) {
const url = tts.getAudioUrl(text, {lang: voice});
return fetch(url);
}
};

26
tts/watson/index.js Normal file
View File

@@ -0,0 +1,26 @@
const BaseEngine=require('../BaseEngine');
const fetch = require('node-fetch');
const querystring = require('querystring');
module.exports= class extends BaseEngine {
constructor() {
super("IBM Watson TTS","ogg");
}
async getSpeech(text, voice='en-us', params={}) {
const url = process.env.watsonURL+"/v1/synthesize";
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
},
body: {
text: text
}
};
return fetch(url);
}
};