Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ffmpeg randomly/rarely giving this error \node_modules\fluent-ffmpeg\lib\processor.js:543 emitEnd(err, stdoutRing.get(), stderrRing.get()); #1316

Open
AnsHanif opened this issue Feb 25, 2025 · 0 comments

Comments

@AnsHanif
Copy link

const stream = require("stream");
const ffmpeg = require("fluent-ffmpeg");
const ffmpegPath = require("@ffmpeg-installer/ffmpeg").path;
ffmpeg.setFfmpegPath(ffmpegPath);

async function googleTextToWav(voiceName, text, speech_client) {
timeFunction("Text to wav Starting: ");
const request = {
input: { ssml: <speak>${text}</speak> },
voice: {
languageCode: voiceName.split("-").slice(0, 2).join("-"),
name: voiceName,
},
audioConfig: { audioEncoding: "MP3" },
};

try {
const [response] = await speech_client.synthesizeSpeech(request);
const audioContent = response.audioContent;
timeFunction("Text to wav ending: ");

new Promise((resolve, reject) => {
  const wavStream = new stream.PassThrough();
  wavStream.end(audioContent);

  const mulawStream = new stream.PassThrough();
  const chunks = [];

  mulawStream.on("data", (chunk) => {
    chunks.push(chunk);
  });

  mulawStream.on("end", () => {
    const buffer = Buffer.concat(chunks);
    const base64Audio = buffer.toString("base64");
    console.log(base64Audio?.length, "length of base64 audio");
  });

  mulawStream.on("error", (err) => {
    reject(err);
  });

  ffmpeg(wavStream)
    .audioFrequency(8000)
    .audioChannels(1)
    .audioCodec("pcm_mulaw")
    .format("mulaw")
    .on("error", (err) => reject(err))
    .pipe(mulawStream, { end: true });
});

return audioContent;

} catch (error) {
console.error("Error in Google TTS:", error);
}
}

this function normal working correctly but some times randomly giving this error
E:\Satesfy Tech\task15\gioconda-ai\server\node_modules\fluent-ffmpeg\lib\processor.js:543
emitEnd(err, stdoutRing.get(), stderrRing.get());
^

TypeError: Cannot read properties of undefined (reading 'get')
at endCB (E:\Satesfy Tech\task15\gioconda-ai\server\node_modules\fluent-ffmpeg\lib\processor.js:543:37)
at ChildProcess. (E:\Satesfy Tech\task15\gioconda-ai\server\node_modules\fluent-ffmpeg\lib\processor.js:157:9)
at ChildProcess.emit (node:events:518:28)
at ChildProcess.kill (node:internal/child_process:511:12)
at Timeout._onTimeout (E:\Satesfy Tech\task15\gioconda-ai\server\node_modules\fluent-ffmpeg\lib\processor.js:490:28)
at listOnTimeout (node:internal/timers:594:17)
at process.processTimers (node:internal/timers:529:7)

Node.js v22.11.0
[nodemon] app crashed - waiting for file changes before starting...

i failed to reproduce this error and failed to fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant