Reputation: 33
I know it's possible to change the playback rate of a audio tag (or audio js object) but I'd like to know if it's possible to change the playback rate and THEN get the AudioBuffer, or manually do the change on the array itself? (I know the audio object does some magic so it doesn't change pitch or sound distorted - how?!)
Upvotes: 0
Views: 697
Reputation: 6056
If by "get the AudioBuffer" you mean you want the result of playing the AudioBuffer at a different playback rate, then yes you can, but not directly.
One way: Create an OfflineAudioContext, create the appropriate AudioBufferSource and AudioBuffer. Connect the source to the offline context and play the source at the desired playback rate. The offline context will have the audio buffer of the original source played back at the desired rate.
Note that the playbackRate attribute for an AudioBufferSource does not preserve pitch. If you want the pitch preserved, you have to do something else.
Upvotes: 1