Skip to content

Instantly share code, notes, and snippets.

@TechplexEngineer
Created September 8, 2024 20:48
Show Gist options
  • Save TechplexEngineer/29dbcd06b6679ab9998f4d2f1a9f90ae to your computer and use it in GitHub Desktop.
Save TechplexEngineer/29dbcd06b6679ab9998f4d2f1a9f90ae to your computer and use it in GitHub Desktop.
Nodejs play sound on raspberry pi with child proces
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