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

master
guilevi 2021-04-10 23:45:02 +02:00
parent 40e50b6546
commit f0c71d75dc
10 changed files with 927 additions and 11 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ voice_tmp
.env
*.db
.DS_Store
gkey.json

BIN
modules/.DS_Store vendored

Binary file not shown.

View File

@ -23,8 +23,8 @@ module.exports = async (bot, api) => {
}
if (api.ttsEngines[args[1]]) {
userEngine = args[1];
if (api.ttsEngines[userEngine].validateVoice(args[2])) {
userVoice = args[2];
if (api.ttsEngines[userEngine].validateVoice(args[2].toLowerCase())) {
userVoice = args[2].toLowerCase();
api.respond(message, "Your voice is now " + userVoice + " from " + api.ttsEngines[userEngine].longName);
} else {
userVoice = api.ttsEngines[userEngine].getDefaultVoice();

View File

@ -8,6 +8,6 @@ module.exports = function (bot, api) {
await api.joinChannel(channel);
let conn=api.getConnectionForVoiceChannel(channel);
api.queue=new AudioQueue(conn);
api.speak(channel, `Hey buddies! How does it feel like to be a buddy? Are you proud of being a buddy? Well that's great!'`);
api.speak(channel, `Running`);
})
}

888
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -10,6 +10,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@google-cloud/text-to-speech": "^3.1.3",
"discord.js": "^12.5.3",
"dotenv": "^8.2.0",
"google-tts-api": "^2.0.2",

BIN
tts/.DS_Store vendored

Binary file not shown.

View File

@ -10,7 +10,7 @@ module.exports = class AzureTTS extends BaseEngine {
}
getDefaultVoice() {
return "";
return "Aria";
}
getSpeechFile(text, filepath, voice = this.getDefaultVoice(), params = {}) {
@ -48,7 +48,7 @@ module.exports = class AzureTTS extends BaseEngine {
json.forEach((voice) => {
if (this.voices[voice.DisplayName]) {
if (voice.Name.includes('Neural')) {
this.voices[voice.DisplayName] = voice.ShortName;
this.voices[voice.DisplayName.toLowerCase()] = voice.ShortName;
}
} else {
this.voices[voice.DisplayName] = voice.ShortName;

View File

@ -0,0 +1,36 @@
const BaseEngine = require('../BaseEngine')
const sdk = require('@google-cloud/text-to-speech');
const fs = require('fs');
const util = require('util');
module.exports = class GoogleCloudTTS extends BaseEngine {
constructor() {
super('google', 'Google Cloud TTS', 'wav');
this.client = new sdk.TextToSpeechClient();
this.client.initialize();
this.voices = {};
this.populateVoiceList();
}
async populateVoiceList() {
const [result] = await this.client.listVoices({});
const voiceList = result.voices;
voiceList.forEach((voice) => {
console.log(voice)
this.voices[voice.name.toLowerCase()] = { name: voice.name, lang: voice.languageCodes[0] };
});
}
getDefaultVoice() {
return 'en-US-Wavenet-A';
}
async getSpeechFile(text, filepath, voice = this.getDefaultVoice(), params = {}) {
const request = {
input: { text: text },
voice: { name: this.voices[voice].name, languageCode: this.voices[voice].lang },
audioConfig: { audioEncoding: 'OGG_OPUS', effectsProfileId: ['medium-bluetooth-speaker-class-device'] },
};
let [response] = await this.client.synthesizeSpeech(request);
const writeFile = util.promisify(fs.writeFile);
await writeFile(filepath, response.audioContent, 'binary');
return filepath;
}
}