How to create an AudioClip from WAV data in memory?

I’d like to load an AudioClip from data I’ve extracted into a byte[ ] from a zip file. But the only way I can find to load WAV data at runtime is UnityWebRequestMultimedia.GetAudioClip, which won’t work here since I don’t have a URL.

Is there any way to do this, short of looking up the WAV format and decoding it myself?

Thanks,

  • Joe

The first idea that comes into my mind is implementing OnAudioFilterRead in a behavior script (docs with example: Unity - Scripting API: MonoBehaviour.OnAudioFilterRead(float[], int)). You just write your bytes into the float array (scale it to -1.0 to 1.0 first) and this should work. Note that this requires an AudioSource component to be present, so you probably need a small sound that is constantly played and overwritten with your audio.

Actually, I also would like to create AudioClip from wav or mp3 memory byte[ ] array.

This functionality already exists in Unity Engine, DownloadHandlerAudioClip class implements this, but requires UnityWebRequest.

Should be added creation of AudioClip from byte[ ] array by Unity3D developers)))
Thanks you!