Monday, 3 August 2020

Gapless looping playback of a WAV file

Hello!As the title states, I'm trying to loop a WAV file endlessly with no gaps in node.js. I'm using naudiodon. I can get the WAV file to play once, and was trying to see if there was an event emitted at the end of playback so I could start it from the beginning.However, the "end" event is emitted almost immediately, while the audio is still playing (see code). I suspect that's because it has finished reading the WAV file much faster than it plays it. So I may be barking up the wrong tree here with this strategy.Any suggestions on how to achieve this?const fs = require("fs"); const wav = require("wav"); const portAudio = require("naudiodon"); const ao = new portAudio.AudioIO({ outOptions: { channelCount: 2, sampleFormat: portAudio.SampleFormat16Bit, sampleRate: 44100, deviceId: -1, closeOnError: true } }); const file = fs.createReadStream('looptest1.wav'); const reader = new wav.Reader(); ao.start(); reader.on("data",chunk => ao.write(chunk)); file.pipe(reader); reader.on('end', () => { console.log('End of WAV file'); // This happens right away, before playback ends }); process.on("SIGINT", ao.quit);

Submitted August 03, 2020 at 01:32PM by even_rats

No comments:

Post a Comment