Skip to content

Instantly share code, notes, and snippets.

@ErickWendel
Created February 24, 2022 14:22
Show Gist options
  • Save ErickWendel/b22e3da8a6ff559ee2c973e697218df8 to your computer and use it in GitHub Desktop.
Save ErickWendel/b22e3da8a6ff559ee2c973e697218df8 to your computer and use it in GitHub Desktop.
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