BHOZ4 TOOLS

Play random sound variations in Godot 4

The same footstep, hit or coin sound playing over and over starts to sound mechanical. You recorded several takes. Here is how to make Godot 4 pick between them.

How Godot does it

Godot 4 has a built-in resource for this, AudioStreamRandomizer. Its class reference says it "Wraps a pool of audio streams with pitch and volume shifting."

Setting up one randomizer is easy. The work grows when you have dozens of sound families.

Fix 1, free: build it in the Inspector

  1. Select your AudioStreamPlayer. Its stream property holds "The AudioStream resource to be played." Create a new AudioStreamRandomizer there.
  2. Set streams_count to the number of takes and drag one file into each stream slot.
  3. Set the playback mode, weights, random_pitch and random_volume_offset_db.
  4. Save it as a .tres file to reuse it. The Resources page of the manual says to "click the save icon at the top of the Inspector, and select "Save" or "Save As..."".

Fine for a few sounds. Slow for many.

Fix 2, free: build banks with a script

The class reference lists add_stream(index, stream, weight = 1.0), and says that if the index is less than zero, "the insertion occurs at the end". The Resources page shows ResourceSaver.save(my_res, "res://my_res.tres").

var bank := AudioStreamRandomizer.new()
for path in ["res://sfx/step_01.wav", "res://sfx/step_02.wav", "res://sfx/step_03.wav"]:
    bank.add_stream(-1, load(path))
ResourceSaver.save(bank, "res://sfx/step_bank.tres")

Run it once from a script in your project. You still need to write the file lists, or code that groups your files into families.

Fix 3, paid: group a whole folder of takes at once

I make Cue Banks for Godot 4 ($8, with a free sample project). It turns several families of audio takes into separate, editable Godot 4 randomizer resources. You review the grouping and numbering gaps, audition the source clips, set weights and choose which banks to export. The ZIP it exports contains native .tres files and a source path manifest. The free sample is a Godot project with six original WAVs and three exported banks, loaded and checked in Godot 4.7.2. One purchase covers an individual or a studio.

It supports WAV, OGG and MP3. Your original files must stay at the matching res:// paths, or the banks will not find them. It was tested in desktop Chrome on Windows. You extract the ZIP and open index.html.

Which one to use