Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.
This repository was archived by the owner on May 22, 2025. It is now read-only.

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

@AnsHanif

Description

@AnsHanif

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions