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);
这会产生以下输出。 (不是预期的“它起作用了!”。)有什么方法可以停止播放音频文件吗?
node: pcm.c:1951: snd_pcm_bytes_to_frames: Assertion `pcm' failed.
Abgebrochen (Speicherabzug geschrieben)
最佳答案
似乎与 .end
一起工作,所以也许您不应该使用 close
。否则,库中可能存在错误。
$stream.end();
关于javascript - Node.js 停止播放音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16067130/