Created
September 8, 2024 20:48
-
-
Save TechplexEngineer/29dbcd06b6679ab9998f4d2f1a9f90ae to your computer and use it in GitHub Desktop.
Nodejs play sound on raspberry pi with child proces
This file contains 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
import { spawn } from 'child_process'; | |
const process = spawn('mpg321', ["-q", "/home/pi/r2_control/sounds/HUM__014.mp3", '-g', "50"]); | |
let stdOut = []; | |
let stdErr = []; | |
process.stdout.on('data', (data) => { | |
stdOut.push(data); | |
}); | |
process.stderr.on('data', (data) => { | |
stdErr.push(data); | |
}); | |
process.on('close', (code) => { | |
if (code !== 0) { | |
console.log(`child process exited with code ${code}`); | |
console.log(stdOut.join('\n')); | |
console.error(stdErr.join('\n')); | |
} | |
// console.log(`child process exited with code ${code}`); | |
}); | |
console.log('sound.js started'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment