Answer the question
In order to leave comments, you need to log in
Why does "ffmpeg exited with code 1: concat:file0.mp3: Invalid argument" error occur?
Hello! I'm making a telegram bot that converts text to speech using ffmpeg. When I send him the second text for conversion, he breaks down, the first time he works fine. Tell me, please, what could be the problem?
The code:
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)
Answer the question
In order to leave comments, you need to log in
Corrected the code (added a couple of timeouts) and now everything works!
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);
});
}
setTimeout(() => {
let songs = [];
for (let i = 0; i < url.length; i++){
songs.push("./file" + i + ".mp3");
}
// console.log(songs);
audioconcat(songs)
.concat('merged.mp3')
}, 3000);
setTimeout(() => {
msg.replyWithAudio({ source: "./merged.mp3" });
songs = [];
}, 4000);
})
bot.launch();
process.on('uncaughtException', function (err) {
console.log(err);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question