TooTallNate / node-speaker

Output PCM audio data to the speakers
655 stars 147 forks source link

Don't panic if a write doesn't fully complete #170

Open thenickdude opened 2 years ago

thenickdude commented 2 years ago

On my Raspberry Pi 3B+, after about 5-10 mins of piping different files to the speaker, I get an error like:

Error: write() failed: 3192

But it's perfectly reasonable for a write() to write fewer bytes than requested (e.g. if the audio device's buffer fills up), so this PR fixes the code so it doesn't panic in this situation and just retries the write of the remaining bytes.

Now my Pi plays flawlessly.