Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function tellText(msg, text, language, speed) {
- var chatId = msg.chat.id;
- if (text.length > 200) {
- bot.sendMessage(chatId, "Розмір тексту не повинен перевищувати 200 символів. (" + text.length + ")");
- return;
- }
- bot.sendChatAction(chatId, "record_audio");
- googleTTS(text, language, speed) // speed normal = 1 (default), slow = 0.24
- .then(function(url) {
- /*bot.sendAudio(chatId, url);
- return;*/
- var prefix = __dirname + "/temp/";
- var input = "file_" + fileId + ".mp3";
- var output = "ogg_" + fileId + ".ogg";
- var surl = URL.parse(url);
- var options = {
- host: surl.host,
- path: surl.path,
- "rejectUnauthorized": false
- };
- try {
- fs.unlinkSync(prefix + input);
- fs.unlinkSync(prefix + output);
- } catch(error) {};
- var file = fs.createWriteStream(prefix + input);
- var request = https.get(options, function(response) {
- response.pipe(file);
- response.on('end', function() {
- var exec = require('child_process').exec;
- exec('avconv -y -acodec mp3float -i ' + input + ' -codec:a opus ' + output, {
- cwd: prefix
- }, function(error, stdout, stderr) {
- if (error instanceof Error) {
- logger.error(error);
- bot.sendMessage(chatId, "Сталася помилка!");
- }
- bot.sendVoice(chatId, prefix + output, {
- caption: text
- });
- info(msg, "Озвучує: " + msg.text + " | Посилання: " + url);
- if(chatId<0) {
- bot.deleteMessage(chatId, msg.id);
- }
- setTimeout(function() {
- try {
- fs.unlinkSync(prefix + input);
- fs.unlinkSync(prefix + output);
- } catch (err) {
- logger.error(error.stack);
- }
- }, 10000);
- fileId++;
- });
- });
- });
- /*bot.sendAudio(chatId, url, {title: text, performer : "playcraft", reply_to_message_id: msg.message_id});*/
- }).catch(function(err) {
- logger.error(err.stack);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement