Best way to handle huge number of audio assets

A project that I’m working on now contains a somewhat unseemly huge number of audio assets; upwards of 10,000 individual audio files (approximately 500mb total). Most of these files are voice clips, usually only a few seconds long. They generally play only one at a time, as the game script calls for them. We’re only targeting PC, but it might be cool to do mac or linux in the future.

There’s two main issues. Unity often doesn’t like working with that many files at a time. It adds a rather long period of time to building, it can freeze if you try to move them, and heaven forbid you want to do something like set them all to 2d audio sources. And secondly, I’d like to easily be able to deploy patches, in case files change, and unity’s internal format doesn’t make that particularly easy, everything just gets shoved into a big resources.assets file, I’m not even sure you can patch changes to it.

My first thought then was just to pack all the files in a separate archive and load them external to unity. I had originally thought of using unity asset bundles, or perhaps just using simple package files (no compression, just a whole bunch of files in one or two big files). Asset bundles it turns out are a no go; Loading from a local asset bundle containing all the audio files takes anywhere from 30 - 60 seconds. My simple package files plan was similarly thwarted by the fact that there is no way to actually load an AudioClip object from an mp3 or ogg file. You can load external ogg’s from a WWW object, but not from a byte array. I suppose it could work if I just threw all the audio files into a folder, but that’s not very professional, and the OS doesn’t like a lot of small files either.

Does anyone have any thoughts on how perhaps I should approach this?

You could “ban” all the files from your Unity project and load them at runtime via WWW. Unity can only load those types at runtime: Ogg(Web/Standalones), WAV, XM, IT, MOD and S3M. Only on mobile you also have MP3 since they have hardware support for them. There is no MP3 support in Unity due to licencing issues.

For more information see the function WWW.GetAudioClip.

For testing purposes i would temporally replace the filepath to a fix path on your development machine. Once you’re done you would place the files in some subfolder of your build after you build the game.

basically … keep them in Resources. In a folder. Have carefully organized subfolders.

per folder, load them more or less like this …

clips = Resources.LoadAll("VoiceReads/" + folderTextname, AudioClip );

But that’s all the easy part, you’ve actually stumbled on to (sorry for the bad news) one of the biggest and most annoying snags in Unity …

notice me and others ranting about it there.

Hope this helps in some way!