@pefbruteq
Здравствуйте! Делаю телеграм бота, который конвертирует текст в речь с помощью ffmpeg. Когда отправляю ему второй текст для конвертации он ломается, в первый раз он работает нормально. Подскажите, пожалуйста, в чём может быть проблема?
Код:
Код:
const googleTTS = require('google-tts-api'); // CommonJS
const https = require('https');
const fs = require('fs');
const { Telegraf } = require('telegraf');
const bot = new Telegraf('Token')
const audioconcat = require('audioconcat');
bot.command("audio", (ctx) => {
return ctx.replyWithAudio({ source: "./file.mp3" });
});
bot.on('message', (msg) => {
const url = googleTTS.getAllAudioUrls(msg.update.message.text, {
lang: 'ru',
slow: false,
host: 'https://translate.google.com',
splitPunct: ',.?'
});
for (let i = 0; i < url.length; i++){
const file = fs.createWriteStream("file" + i + ".mp3");
const request = https.get(url[i].url, function(response) {
response.pipe(file);
});
}
let songs = [];
for (let i = 0; i < url.length; i++){
songs.push("file" + i + ".mp3");
}
audioconcat(songs)
.concat('merged.mp3')
songs = [];
setTimeout(() => {
msg.replyWithAudio({ source: "./merged.mp3" });
songs = [];
}, 2000);
})
bot.launch();
process.on('uncaughtException', function (err) {
console.log(err);
});
Ошибка:
events.js:291
throw er; // Unhandled 'error' event
^
Error: ffmpeg exited with code 1: concat:file0.mp3: Invalid argument
at ChildProcess.<anonymous> (/home/pefbrute/Desktop/Offline-syntheser/node_modules/fluent-ffmpeg/lib/processor.js:182:22)
at ChildProcess.emit (events.js:314:20)
at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
Emitted 'error' event on FfmpegCommand instance at:
at emitEnd (/home/pefbrute/Desktop/Offline-syntheser/node_modules/fluent-ffmpeg/lib/processor.js:424:16)
at endCB (/home/pefbrute/Desktop/Offline-syntheser/node_modules/fluent-ffmpeg/lib/processor.js:544:13)
at handleExit (/home/pefbrute/Desktop/Offline-syntheser/node_modules/fluent-ffmpeg/lib/processor.js:170:11)
at Socket.<anonymous> (/home/pefbrute/Desktop/Offline-syntheser/node_modules/fluent-ffmpeg/lib/processor.js:197:11)
at Socket.emit (events.js:326:22)
at Pipe.<anonymous> (net.js:676:12)
Решения вопроса 0
Ответы на вопрос 0