TooTallNate / node-speaker

Output PCM audio data to the speakers
648 stars 145 forks source link

Pipe PCMData from variable? #146

Open ughstudios opened 4 years ago

ughstudios commented 4 years ago

In your example you are using stdin to pipe the data, is there a way to do it from a variable, or an outputStream() which I have access to? Please provide working examples if possible! :)

// PCM data from stdin gets piped into the speaker
process.stdin.pipe(speaker);
ughstudios commented 4 years ago

So I got my audio out but it's sounding realllly bad and robotic.

Xeonzinc commented 4 years ago

You may need to cork your pipe initially to allow enough of a buffer to build up, before outputting to the speaker. I would also recommend ensuring you are sending a large chunk of data at once to ensure the speaker isn't running out of data intermittently when your application is busy elsewhere, I transmit in 1024 sample chunks to my speakers, enough ms in advance of when I want it to be played.