Added Google TTS, lowercase voices so that people don't have to remember ridiculous case
parent
40e50b6546
commit
f0c71d75dc
|
@ -3,3 +3,4 @@ voice_tmp
|
||||||
.env
|
.env
|
||||||
*.db
|
*.db
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
gkey.json
|
Binary file not shown.
|
@ -23,8 +23,8 @@ module.exports = async (bot, api) => {
|
||||||
}
|
}
|
||||||
if (api.ttsEngines[args[1]]) {
|
if (api.ttsEngines[args[1]]) {
|
||||||
userEngine = args[1];
|
userEngine = args[1];
|
||||||
if (api.ttsEngines[userEngine].validateVoice(args[2])) {
|
if (api.ttsEngines[userEngine].validateVoice(args[2].toLowerCase())) {
|
||||||
userVoice = args[2];
|
userVoice = args[2].toLowerCase();
|
||||||
api.respond(message, "Your voice is now " + userVoice + " from " + api.ttsEngines[userEngine].longName);
|
api.respond(message, "Your voice is now " + userVoice + " from " + api.ttsEngines[userEngine].longName);
|
||||||
} else {
|
} else {
|
||||||
userVoice = api.ttsEngines[userEngine].getDefaultVoice();
|
userVoice = api.ttsEngines[userEngine].getDefaultVoice();
|
||||||
|
|
|
@ -8,6 +8,6 @@ module.exports = function (bot, api) {
|
||||||
await api.joinChannel(channel);
|
await api.joinChannel(channel);
|
||||||
let conn=api.getConnectionForVoiceChannel(channel);
|
let conn=api.getConnectionForVoiceChannel(channel);
|
||||||
api.queue=new AudioQueue(conn);
|
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`);
|
||||||
})
|
})
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -10,6 +10,7 @@
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@google-cloud/text-to-speech": "^3.1.3",
|
||||||
"discord.js": "^12.5.3",
|
"discord.js": "^12.5.3",
|
||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
"google-tts-api": "^2.0.2",
|
"google-tts-api": "^2.0.2",
|
||||||
|
|
Binary file not shown.
|
@ -10,7 +10,7 @@ module.exports = class AzureTTS extends BaseEngine {
|
||||||
}
|
}
|
||||||
|
|
||||||
getDefaultVoice() {
|
getDefaultVoice() {
|
||||||
return "";
|
return "Aria";
|
||||||
}
|
}
|
||||||
|
|
||||||
getSpeechFile(text, filepath, voice = this.getDefaultVoice(), params = {}) {
|
getSpeechFile(text, filepath, voice = this.getDefaultVoice(), params = {}) {
|
||||||
|
@ -48,7 +48,7 @@ module.exports = class AzureTTS extends BaseEngine {
|
||||||
json.forEach((voice) => {
|
json.forEach((voice) => {
|
||||||
if (this.voices[voice.DisplayName]) {
|
if (this.voices[voice.DisplayName]) {
|
||||||
if (voice.Name.includes('Neural')) {
|
if (voice.Name.includes('Neural')) {
|
||||||
this.voices[voice.DisplayName] = voice.ShortName;
|
this.voices[voice.DisplayName.toLowerCase()] = voice.ShortName;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.voices[voice.DisplayName] = voice.ShortName;
|
this.voices[voice.DisplayName] = voice.ShortName;
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue