i'm trying to play raw pcm data, which came from socket.io (using nodejs) with alsa. Recently i used node-speaker that solved my problem, but i can't install it to my target device. Now i'm trying to do it with nodejs "fs" module:
...
var pcm = fs.createWriteStream("audio.pcm");
socket.on('stream', function(data) {
console.log(data);
pcm.write(data);
});
....
Afterwards i'm trying to run aplay command immediately:
aplay -t raw -c 1 -r 48000 -f S16_LE audio.pcm
I able to listen my data with delay (2-3 seconds. It depends of how quickly I ran above command), but it crashes after 5-10 seconds without any messages. I guess it is not a right way to play live pcm. What is the best way to do that?