Created
February 24, 2022 14:22
-
-
Save ErickWendel/b22e3da8a6ff559ee2c973e697218df8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const { | |
spawn | |
} = require('child_process') | |
const soxStream = require('sox-stream') | |
const songPath = './audio/songs/Modern Attempt - TrackTribe.mp3' | |
const fxPath = './audio/fx/Boo! Sound Effect (128 kbps).mp3' | |
const output = 'output.mp3' | |
const inputStream = fs.createReadStream(songPath) | |
const outputStream = fs.createWriteStream(output) | |
const main = inputStream | |
.pipe(soxStream({ | |
input: { | |
type: 'mp3', | |
// volume: 0.8 | |
}, | |
output: { | |
type: 'mp3' | |
} | |
})) | |
const args = [ | |
'-t', 'mp3', | |
'-m', '-', | |
'-t', 'mp3', | |
fxPath, | |
'-t', 'mp3', | |
'-' | |
] | |
const { | |
stderr, | |
stdout, | |
stdin | |
} = spawn('sox', args) | |
stdout.pipe(outputStream) | |
stderr.on('data', msg => console.log('error', msg.toString())) | |
main.pipe(stdin) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment