Search Unity

Audio How to create an AudioClip from WAV data in memory?

Discussion in 'Audio & Video' started by JoeStrout, Jun 23, 2019.

  1. JoeStrout


    Jan 14, 2011
    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?

    - Joe
  2. Deleted User

    Deleted User


    The first idea that comes into my mind is implementing OnAudioFilterRead in a behavior script (docs with example: 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.
  3. Lesha-VH


    Jul 3, 2012
    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!