-
-
Notifications
You must be signed in to change notification settings - Fork 444
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
v3: Add RawAudio class #682
base: v3
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! Just some questions/suggestions.
I also think we should split this into a .save()
and "convert to wave" function, in case the user wants to convert to WAV without having to save the file immediately.
Co-authored-by: Joshua Lochner <[email protected]>
Thank you @xenova for the review. Here's the changes I have made :
|
Thanks! 🤗 Would you mind benchmarking/comparing your code with https://www.npmjs.com/package/audiobuffer-to-wav, which I used in a demo a few months ago. Also, at the moment, we only support 1-channel audios, but their code supports 2-channel + interleaving (see here), and might be good to include. Other than that, I like the abstractions you introduced for the |
I have added support for 2 channels audio + interleave.
Below a quick benchmark, comparing with function benchmark(){
let i, input, output
console.time('encodeWAV')
for(i=0; i<20000; i++){
input = new Float32Array(i).fill(i)
output = encodeWAV(input)
output = new Blob([output])
}
console.timeEnd('encodeWAV')
console.time('RawAudio')
for(i=0; i<20000; i++){
input = new Float32Array(i).fill(i)
output = new RawAudio(input, 16000)
output = output.toBlob()
}
console.timeEnd('RawAudio')
}
/*
encodeWAV: 3216.6669921875 ms
RawAudio: 2702.23291015625 ms
---
encodeWAV: 3296.2138671875 ms
RawAudio: 2768.235107421875 ms
*/
for (let i = 0; i < samples.length; ++i, offset += 4) {
view.setFloat32(offset, samples[i], true)
} unit test for interleave let audio = new RawAudio([new Float32Array([1,2,3,4,5]), new Float32Array([1,2,3,4,5])], 16000)
console.log(audio.interleave(true)[0].toString() == '1,1,2,2,3') |
Thanks again! Just letting you know this PR is marked for the next release :) |
I have merged branch v3 #545 into this PR |
Following messages from #680
The 'save to wav' is my own simple implementation, using file specs, and hex viewer of a generated wav file.
Below the changes :
RawAudio
class, with.save(path)
(support browser, webworker and nodejs)RawAudio
objectisBrowserEnv
andisWebworkerEnv
to envExample use :