Playing voice files from AssetBundles

In the last tutorial, we used the auto-naming method to have AC play voice files according to a naming convention. These voice files are placed in an Assets subfolder named Resources for automatic retrieval at runtime.

However, while this method is convenient for getting up-and-running quickly, it is not the best choice for performance. It is instead more efficient to rely on AssetBundles, which can be loaded and unloaded at runtime dynamically.

AssetBundles are an advanced topic of Unity, and it assumes a prior working knowledge of their usage. For an official guide to AssetBundles, see Unity's own documentation here.

For an audio file to be included in an asset bundle, we need to check Addressable at the top of its Inspector. Unity will generate a unique name for it when doing so, but AC requires that this matches the filename as listed in the Speech Manager. Here, we have the audio file "Brain8.mp3", given the Addressable name "Brain8":

All audio files for a given translation will need to be placed within a single bundle. This bundle will then need to be generated. There are several ways to generate an AssetBundle, but Unity provides a sample script on their own website here.

Asset bundles are built per-platform, so you'll need to make a new bundle if you switch your game's target platform.

Once you have created the AssetBundle, it will need to be moved to an Assets subfolder named StreamingAssets.

The audio files can now be taken out of the Resources folder, if that's where they are.

To inform AC that we wish to use AssetBundles for voice files, navigate to the Speech Manager and set the Reference speech files field to By Asset Bundle.

Once set, an Audio AssetBundle name field will appear for each language that allows for speech audio. Here, you must supply the name of the AssetBundle that stores audio for that language:

Selecting a speech line from the Game text panel will inform you of the expected AssetBundle and filepath for the audio:

If your game makes use of lipsyncing, lipsync files will also need to be placed in AssetBundles. These can either be the same bundles used by audio, or separate ones - but the bundle names must similarly be entered into the Lipsync AssetBundle name field(s).