TooTallNate/node-speaker

Stop Audio Instantly

akashbudhia opened this issue · 7 comments

I pipe a local mp3 file stream via node-lame decoder to the node-speaker instance to play a local mp3 file. What would be the correct way to instantly stop the audio from playing?

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

fs.createReadStream('audio.mp3').pipe(lame.Decoder()).pipe(new Speaker());

+Bump

+Bump

Did you get the solution?

any solution

Open for suggestions on how an API for this would look!

Did you get the solution?

My suggestion would be to write a custom throughput stream which accepts the piped data and processes them in a small buffered loop which you can stop via a custom control command. (true instant stop is not possible because the audio card uses an internal buffer. But with a size of 1024 samples and 44100 samples per second this is relatively short).