From 80a7e0eb98c8de58f725a12a6f0a510a455f4d67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Bersier?= Date: Sat, 18 May 2019 03:20:26 +0200 Subject: [PATCH] Allow to change speed and pitch --- commands/fun/tts/sam.js | 32 ++++++++++++++++++++++++++++++-- commands/fun/tts/samvc.js | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/commands/fun/tts/sam.js b/commands/fun/tts/sam.js index 94948db..6bec45a 100644 --- a/commands/fun/tts/sam.js +++ b/commands/fun/tts/sam.js @@ -15,7 +15,7 @@ class samCommand extends Command { } ], description: { - content: 'Send a mp3 of what you wrote in Microsoft Sam tts', + content: 'Send a mp3 of what you wrote in Microsoft Sam tts, can change speed and pitch with [speed:a number] and [pitch:a]', usage: '[text]', examples: ['Here comes the roflcopter soisoisoisoisoi'] } @@ -23,12 +23,40 @@ class samCommand extends Command { } async exec(message, args) { + let pitch = ''; + if (args.samMessage.includes('[pitch:')) { + pitch = args.samMessage.split(/(\[pitch:.*?])/); + for (let i = 0, l = pitch.length; i < l; i++) { + if (pitch[i].includes('[pitch:')) { + pitch = pitch[i].replace('[pitch:', '').slice(0, -1); + args.samMessage = args.samMessage.replace(/(\[pitch:.*?])/g, ''); + i = pitch.length; + } + } + } else { + pitch = 100; + } + + let speed = ''; + if (args.samMessage.includes('[speed:')) { + speed = args.samMessage.split(/(\[speed:.*?])/); + for (let i = 0, l = speed.length; i < l; i++) { + if (speed[i].includes('[speed:')) { + speed = speed[i].replace('[speed:', '').slice(0, -1); + args.samMessage = args.samMessage.replace(/(\[speed:.*?])/g, ''); + i = speed.length; + } + } + } else { + speed = 100; + } + args.samMessage = args.samMessage.replace('\n', ' '); args.samMessage = encodeURI(args.samMessage); return axios.request({ responseType: 'arraybuffer', - url: `https://tetyys.com/SAPI4/SAPI4?text=${args.samMessage}&voice=Sam&pitch=100&speed=100`, + url: `https://tetyys.com/SAPI4/SAPI4?text=${args.samMessage}&voice=Sam&pitch=${pitch}&speed=${speed}`, method: 'get', headers: { 'Content-Type': 'audio/mpeg', diff --git a/commands/fun/tts/samvc.js b/commands/fun/tts/samvc.js index 8decad9..ba028f3 100644 --- a/commands/fun/tts/samvc.js +++ b/commands/fun/tts/samvc.js @@ -15,7 +15,7 @@ class samvcCommand extends Command { } ], description: { - content: 'Repeat what you said in voice chat with Microsoft Sam tts', + content: 'Repeat what you said in voice chat with Microsoft Sam tts, can change speed and pitch with [speed:a number] and [pitch:a]', usage: '[text]', examples: ['Here comes the roflcopter soisoisoisoisoi'] } @@ -23,12 +23,40 @@ class samvcCommand extends Command { } async exec(message, args) { + let pitch = ''; + if (args.samMessage.includes('[pitch:')) { + pitch = args.samMessage.split(/(\[pitch:.*?])/); + for (let i = 0, l = pitch.length; i < l; i++) { + if (pitch[i].includes('[pitch:')) { + pitch = pitch[i].replace('[pitch:', '').slice(0, -1); + args.samMessage = args.samMessage.replace(/(\[pitch:.*?])/g, ''); + i = pitch.length; + } + } + } else { + pitch = 100; + } + + let speed = ''; + if (args.samMessage.includes('[speed:')) { + speed = args.samMessage.split(/(\[speed:.*?])/); + for (let i = 0, l = speed.length; i < l; i++) { + if (speed[i].includes('[speed:')) { + speed = speed[i].replace('[speed:', '').slice(0, -1); + args.samMessage = args.samMessage.replace(/(\[speed:.*?])/g, ''); + i = speed.length; + } + } + } else { + speed = 100; + } + args.samMessage = args.samMessage.replace('\n', ' '); args.samMessage = encodeURI(args.samMessage); return axios.request({ responseType: 'arraybuffer', - url: `https://tetyys.com/SAPI4/SAPI4?text=${args.samMessage}&voice=Sam&pitch=100&speed=100`, + url: `https://tetyys.com/SAPI4/SAPI4?text=${args.samMessage}&voice=Sam&pitch=${pitch}&speed=${speed}`, method: 'get', headers: { 'Content-Type': 'audio/mpeg',