Change properties on multiple audio files

I always do compression of audio at the end of my workflow. This is an extremely boring, clumsy and time consuming process, where I have to go through the Audio Importer for each of the files, change a range of properties and press Apply.

Can this be done for all (or a range of) audio files in the project at once?

#Note - Unity finally fixed this.

You can now select multiple AudioClip, and change them all at once. Phew.

I would really like to try out various compression levels on a general level. This is simply impossible, handling one audio file at a time.

Hacks are very welcome, if there are no official way! :slight_smile:

Note, unity fixed this around 2014. Just select multiple AudioClip in the Project. (You do have to expand all folders before doing so, and here’s a critical tip on that!)

Historic answer…


You need to create a custom AssetPostprocessor script in the folder ‘Assets/Editor’. Define a function called OnPreprocessAudio, and set the clip properties with the AudioImporter object.

This script will then automatically get called whenever an asset is imported. This means whenever an asset is added to your project, or whenever you reimport an asset (using its context menu in the project explorer). To reimport a range of assets, select them all and then reimport.

Here is an example script I made to set imported sounds to 2d by default:

using UnityEngine;
using UnityEditor;

public class Force2dAudio : AssetPostprocessor {
	void OnPreprocessAudio () {
		AudioImporter importer = (AudioImporter) assetImporter;
		importer.threeD = false;
	}
}

NOTE: The inspector is not updated when you reimport an asset that you have selected, but if you click away and click back you will see the changes.

I still didn’t tinker enough on this but I believe you gonna have to load the assets in a folder into an array and then process them.
useful links :
Resources.LoadAll http://unity3d.com/support/documentation/ScriptReference/Resources.LoadAll.html

compression http://unity3d.com/support/documentation/ScriptReference/AudioImporter-compressionBitrate.html

untested code I was doing for my project:

 //verifies if there is music to import and if it is 2D
function OnPreprocessAudio () {
	var audioImporter : AudioImporter;
	if(audioImporter.format != AudioImporterFormat.Compressed){
		audioImporter.format = AudioImporterFormat.Compressed;
		audioImporter.loadType = AudioImporterLoadType.CompressedInMemory;
		//audioImporter.loadType = AudioImporterLoadType.StreamFromDisc;
		//audioImporter.loadType = AudioImporterLoadType.DecompressOnLoad;
		Debug.Log(audioImporter.assetPath+" is being compressed");
	}
	
	if(audioImporter.threeD){
		Debug.LogWarning(audioImporter.assetPath + " is not a 2D audio. Changing it to 2D");
		audioImporter.threeD = false;
}
[CODE/]
I hope this helps