Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js stop playing audio

var fs = require('fs');
var lame = require('lame');
var Speaker = require('speaker');

var $stream = fs.createReadStream('sounds/test.mp3').pipe(new lame.Decoder).pipe(new Speaker);

setTimeout(function() {
    $stream.close();
}, 5000);

setTimeout(function() {
    console.log('It worked!');
}, 10000);

This produces the following output. (Not 'It worked!' as expected.) Is there any way to stop the playing of a audio file?

node: pcm.c:1951: snd_pcm_bytes_to_frames: Assertion `pcm' failed.
Abgebrochen (Speicherabzug geschrieben)
like image 648
MeinAccount Avatar asked Mar 23 '26 22:03

MeinAccount


1 Answers

Seems to work with .end, so maybe you aren't supposed to use close. Otherwise perhaps there is a bug in the library.

$stream.end();
like image 65
loganfsmyth Avatar answered Mar 25 '26 13:03

loganfsmyth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!