Reputation: 229
I need something simple: play an audio file from my node.js file. I've tried all sorts of things and cannot find anything that works. I'm currently trying "play-sound", from this link: https://www.npmjs.com/package/play-sound
I made sure to install play-sound, and then I have just the following as my code:
var player = require('play-sound')(opts = {})
player.play('chime.wav', function(err){
if (err) throw err
});
I get nothing. I can play the sound just fine from the command line with:
aplay chime.wav
Any ideas would be appreciated.
Update: I figured it out. "node-aplay" worked for me: https://www.npmjs.com/package/node-aplay
I didn't need the USB audio configuration part. I just installed node-aplay and alsa according to the instructions. My code was just the first two lines in the example:
var Sound = require('node-aplay');
// fire and forget:
new Sound('/path/to/the/file/filename.wav').play();
Upvotes: 3
Views: 13104
Reputation: 3602
You could see what was happening by checking stdout
or stderr
:
var player = require('play-sound')(opts = {})
player.play('chime.wav', function(err, stdout, stderr) {
if (err) throw err
console.log(stdout)
console.log(stderr)
});
Upvotes: 0
Reputation: 4149
Try sound-play
instead, it supports both .wav
and .mp3
:
const sound = require('sound-play')
sound.play('/path/music.wav')
Upvotes: 1
Reputation: 229
Update: I figured it out. "node-aplay" worked for me: https://www.npmjs.com/package/node-aplay
I didn't need the USB audio configuration part. I just installed node-aplay and alsa according to the instructions. My code was just the first two lines in the example:
var Sound = require('node-aplay');
// fire and forget:
new Sound('/path/to/the/file/filename.wav').play();
Upvotes: 1