Fix formatting

This commit is contained in:
2021-04-07 01:36:35 +02:00
parent 158ed0372f
commit 12a9f8fc53
8 changed files with 78 additions and 78 deletions

View File

@@ -1,21 +1,21 @@
const fs=require('fs');
const fs = require('fs');
module.exports=class {
constructor(longName, fileExtension, supportedParameters=[]) {
this.longName=longName;
this.fileExtension=fileExtension;
module.exports = class {
constructor(longName, fileExtension, supportedParameters = []) {
this.longName = longName;
this.fileExtension = fileExtension;
}
getInternalVoiceName(str) {
return this.voices?this.voices[str]:str;
return this.voices ? this.voices[str] : str;
}
getDefaultVoice() {}
validateVoice(voice) {return this.voices ? this.voices[voice] : true;}
async getSpeech(text, voice=this.getDefaultVoice(), params) {}
getDefaultVoice() { }
validateVoice(voice) { return this.voices ? this.voices[voice] : true; }
async getSpeech(text, voice = this.getDefaultVoice(), 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);
const contents = await data.arrayBuffer();
const buf = Buffer.from(contents);
fs.writeFileSync(filepath, buf);
return filepath;
}
}

View File

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

View File

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

View File

@@ -1,11 +1,11 @@
const BaseEngine=require('../BaseEngine');
const BaseEngine = require('../BaseEngine');
const fetch = require('node-fetch');
const querystring = require('querystring');
module.exports= class extends BaseEngine {
module.exports = class extends BaseEngine {
constructor() {
super("IBM Watson TTS","ogg");
this.voices={
super("IBM Watson TTS", "ogg");
this.voices = {
'Michael': 'en-US_MichaelV3Voice',
'Allison': 'en-US_AllisonV3Voice',
'Kevin': 'en-US_KevinV3Voice',
@@ -14,12 +14,12 @@ module.exports= class extends BaseEngine {
getDefaultVoice() {
return 'Michael';
}
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;
const opts={
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;
const opts = {
method: "post",
headers: {
'Content-Type': 'application/json',
@@ -29,6 +29,6 @@ module.exports= class extends BaseEngine {
text: text
})
};
return fetch(url,opts);
return fetch(url, opts);
}
};