Allow to change speed and pitch

This commit is contained in:
Loïc Bersier 2019-05-18 03:20:26 +02:00
parent a7f32e5930
commit 80a7e0eb98
2 changed files with 60 additions and 4 deletions

View file

@ -15,7 +15,7 @@ class samCommand extends Command {
} }
], ],
description: { 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]', usage: '[text]',
examples: ['Here comes the roflcopter soisoisoisoisoi'] examples: ['Here comes the roflcopter soisoisoisoisoi']
} }
@ -23,12 +23,40 @@ class samCommand extends Command {
} }
async exec(message, args) { 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 = args.samMessage.replace('\n', ' ');
args.samMessage = encodeURI(args.samMessage); args.samMessage = encodeURI(args.samMessage);
return axios.request({ return axios.request({
responseType: 'arraybuffer', 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', method: 'get',
headers: { headers: {
'Content-Type': 'audio/mpeg', 'Content-Type': 'audio/mpeg',

View file

@ -15,7 +15,7 @@ class samvcCommand extends Command {
} }
], ],
description: { 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]', usage: '[text]',
examples: ['Here comes the roflcopter soisoisoisoisoi'] examples: ['Here comes the roflcopter soisoisoisoisoi']
} }
@ -23,12 +23,40 @@ class samvcCommand extends Command {
} }
async exec(message, args) { 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 = args.samMessage.replace('\n', ' ');
args.samMessage = encodeURI(args.samMessage); args.samMessage = encodeURI(args.samMessage);
return axios.request({ return axios.request({
responseType: 'arraybuffer', 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', method: 'get',
headers: { headers: {
'Content-Type': 'audio/mpeg', 'Content-Type': 'audio/mpeg',