I am trying to convert a WAV file to Opus, using Node's fs.readFile and passing that buffer to @Discord/opus converter. I get neither the result or a error thrown with a explanation of what is wrong. This is basically the example you have in the docs... right?
Bug? By design? or me missing something? I would expect the try/catch to be called but somehow the error is "absorbed" and the script just exits silently.
Online example: https://codesandbox.io/s/funny-jones-d7sls?file=/src/index.js
const audioBuffer = await fs
.readFile(file)
.catch(err => console.log("Error reading input file:", err));
console.log("LENGTH:", audioBuffer.length); // all good so far...const encoder = new OpusEncoder(41000, 2);
let encoded = null;
try {
console.log("Trying to encode..."); // log runs
encoded = encoder.encode(audioBuffer);
console.log("Encoded!"); // log doesn't run :(
} catch (err) {
console.log("Encoding failed:", err); // no error thrown... :'(
}
return encoded;
Further details:
@discordjs/opus version: ^0.3.2
Node.js version: v14.2.0
Operating system: Mac Mojave (10.14.6)
Related issue in repo: https://github.com/discordjs/opus/issues/26
This could be due to a number of reasons, such as a bug in the @discordjs/opus library or a problem with the input data.
One thing you could try is wrapping the OpusEncoder.encode method in a try-catch block and adding some additional error handling. For example, you could add some code to check the return value of the encode method to see if it is null or undefined, which could indicate an error. You could also try logging the value of encoder.getLastError() to see if it provides any additional information about the problem.
You might also want to try using a different version of the @discordjs/opus library to see if the issue is resolved. If the problem persists, you may want to consider reaching out to the library maintainers or filing an issue in the repository to see if they can provide any additional help or insights.