How to mass substitute audio files?

I need to change file format of the audio. Right now the audio files are mostly .wav, they will be changed to .mp3.

I’ve seen this post , but it says that mass Replace in Audio Bin requires files to have exactly the same name. Actually, this Replace thing does not work for me even if the files do have the same names - when I ‘select the folder that contains all of the new files’, nothing happens, and when I click the folder again, it either opens the folder to browse the files inside it, or promts me to rename the folder, depending on where exactly I click. What am I doing wrong? And what if the files have the same name, but a different file extension?

Another question (kinda off-topic, but relevant to my case) is about different audio formats of the source files and whether that affects space the project takes. Since FMOD converts files when building, will the format and quality of the source files affect the size of the final game build or how much RAM it takes when that build is running? I’m usig Unity, if that makes any difference.

That feature was present on FMOD Studio 1.06, but has since been removed in favor of the “Replace with…” context menu option, which is specifically to replace usage of a given asset with another asset in the FMOD Studio project. This was done to facilitate the ability to undo the replacement, as the old feature combined a replacement in FMOD Studio (undoable via Studio) with an import via filesystem (not undoable via Studio). The 1.06 feature required identical filenames including type extensions, so it wouldn’t work for your purposes.

The “Replace with…” feature will work for your purposes, but may be too arduous for your project. Instead, you can use the Studio Scripting API to do this in bulk. The following code takes the asset currently that selected in the Asset browser, and replaces usage of all other assets in the project that share the same name (but not file extension) with itself - put it in a file ending in .js in the ./Scripts directory of your FMOD Studio install:

studio.menu.addMenuItem({
    name: "Search and Replace Based on Selected Asset",
    isEnabled: function() { return studio.window.browserCurrent() != null && studio.window.browserCurrent().isOfExactType('AudioFile') },
    execute: function() {
        ReplaceBasedOnSelectedAsset(studio.window.browserCurrent());
    }
});

function ReplaceBasedOnSelectedAsset(newAsset){
    var assets = studio.project.workspace.masterAssetFolder.assets;
    assets.forEach(function (asset){
        if (asset.isOfExactType('AudioFile')){
            if (GetAssetName(asset) === GetAssetName(newAsset) && !(GetAssetExtension(asset) === GetAssetExtension(newAsset)))
                asset.sounds.forEach(function (sound) {
                    sound.audioFile = newAsset;
                });
        }
    });
}

function GetFullAssetName(asset){
    var assetPath = asset.getAssetPath().split('/');
    return assetPath.pop()
}

function GetAssetName(asset){
    var assetName = GetFullAssetName(asset);
    var lastIndexOf = assetName.lastIndexOf('.');
    return assetName.slice(0, lastIndexOf);
}

function GetAssetExtension(asset){
    var assetName = GetFullAssetName(asset);
    var lastIndexOf = assetName.lastIndexOf('.');
    return assetName.slice(lastIndexOf + 1);
}

For example, if I have an asset called “myAsset.wav” in the Asset Browser that I’m using in several events. select an asset called “myAsset.mp3” in the Asset Browser, and run the above script, it replaces all usages of the former with the latter. Be aware that this is not undoable, so I would recommend testing it ahead of time on a different project first. Please let me know whether you run into any issues.

To apply this to a large amount of assets in bulk, you may wish to modify it to connect to the project.audioFileImported signal and then disconnect from the signal when finished substituting assets. Alternatively, you could import all of your replacement assets, and then enumerate them and run the above code for each instead of just the selected asset.

Using different audio formats for your source audio assets primarily affects the size of the assets on disk in your FMOD Studio project, as well as their quality. It will also take up more RAM and potentially incur differing CPU usage when the build process is occurring in FMOD Studio. Since FMOD Studio re-encodes the assets when building banks, using assets that take up more space shouldn’t affect the size of your banks. However, it may affect the quality of the re-encoded assets if your source audio is of lower quality. Using Unity shouldn’t make a difference.

1 Like