Hey there,
Disclaimer: Please note this is the first time I am using Streams and Pipes, so it may not be Sox related.
I am trying to implement on-the-fly transcoding using Sox in NodeJS, but the code is crashing with:
Error: spawn sox ENOENT at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19) at onErrorNT (internal/child_process.js:469:16) at processTicksAndRejections (internal/process/task_queues.js:84:21) { errno: 'ENOENT', code: 'ENOENT', syscall: 'spawn sox', path: 'sox', spawnargs: [ '/tmp/981152e3-6091-4a32-a7e6-81f1b9157b90', '--type', 'flac', '-' ] }
The issue can be run directly from here : https://repl.it/@VianneyLejeune/Sox.
For your convenience, here is the code:
var sox = require('sox-stream'); // https://npm.io/package/sox-stream
var stream = require("stream");
function TranscodeAudioFromURL(url, callback) {
var request = require('request');
return new Promise((resolve, reject) => {
request({
url: url,
encoding: null
}, function(err, res, body) {
if (!err && res.statusCode == 200) {
const src = new stream.Readable(); // Stream for input
const dest = new stream.Writable(); // Stream for output
src.push(body); //push of the input audio file to the stream
src.push(null); // ending the stream
src // Piping the output stream to the transcoder
.pipe(sox({
output: {
type: 'flac'
}
}))
.pipe(dest);
return resolve(dest); // return converted audio file as stream
} else
reject(err);
});
});
};
// Calling the transcoder
TranscodeAudioFromURL('https://s3.amazonaws.com/appforest_uf/f1611567418463x165993112458673100/ttsMP3.com_VoiceText_2021-1-25_10_25_1.mp3').then((outputStream) => {
// "Success!"
console.log("Transcoded binary"+JSON.stringify(outputStream))
}, reason => {
// failure
console.log(reason);
});
Am I missing something?