Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audio gets cut at the end #58

Open
reidtan opened this issue Jan 5, 2021 · 2 comments
Open

Audio gets cut at the end #58

reidtan opened this issue Jan 5, 2021 · 2 comments

Comments

@reidtan
Copy link

reidtan commented Jan 5, 2021

Hello all,

I'm facing this issue where the audio gets cut (~1 sec) at the end and can't figure out why it's happening. I hope someone can help me out here please!

Here's the code snippet (it's really just the sample code):

var ao = new portAudio.AudioIO({
  outOptions: {
    channelCount: 2,
    sampleFormat: portAudio.SampleFormat16Bit,
    sampleRate: 22000,
    maxQueue: 1,
    closeOnError: true
  }
});

var rs = fs.createReadStream('./audio/output.wav');
rs.pipe(ao);
ao.start();

Troubleshooting 1:
I've tried to debug and step through the code, however during debugging, the full audio gets played fine and I don't see anything amiss throughout code stepping.

Troubleshooting 2:
I've also played the same file via VLC media player and the audio file was complete (no cut at the end).
Using a different audio file also results in audio getting cut at the end too.

Troubleshooting 3:
To narrow down the issue more, I did the following:

var rs = fs.createReadStream('./audio/output.wav');
var ws = fs.createWriteStream('./audio/output-write.wav');

rs.on('data', (chunk) => {
  console.log(chunk);
  ws.write(chunk);
});

and the file write out complete without audio cut when played via VLC media player.

However when I change it to:
ao.write(chunk);
the output audio gets trimmed at the end.

Troubleshooting 4:
I realized that changing the outOptions.maxQueue affects how much audio is being cut at the end. Setting to 1 and I get the longest audio play, setting it to 2 and it gets shortened more, 3 even more and so on. Setting it to 0 and no audio was played.

Troubleshooting 5:
I've also logged out the close event from the readstream and finish event from ao write stream,
it seems that the close event gets called, then the finish event and that's when the audio gets cut. It does not seem to wait for the audio to finish playing.

I hope someone can help me out with this! Thanks for your time!

@scriptorian
Copy link

Please try again with the latest version.

@scriptorian
Copy link

The last output buffer (by default 16384 bytes) was not getting sent to the output. This should be fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants