Overview
Godot supports multiple audio formats through theAudioStream system. Each format has different characteristics suited for specific use cases, from compressed music files to uncompressed sound effects.
AudioStream is the base class for all audio streams. Specific formats like WAV, OGG, and MP3 are implemented as specialized classes.
Supported Audio Formats
AudioStreamWAV
Uncompressed PCM audio, best for short sound effects: Advantages:- No decompression overhead (instant playback)
- Perfect for sound effects
- Supports loop points
- Can be generated at runtime
- Large file size
- Not suitable for music or long audio
format- Audio format (8-bit, 16-bit, IMA ADPCM)loop_mode- Disabled, Forward, Ping-Pong, Backwardsloop_begin- Loop start point in samplesloop_end- Loop end point in samplesmix_rate- Sample rate in Hzstereo- Mono or stereo
AudioStreamOggVorbis
Compressed audio format, ideal for music: Advantages:- Excellent compression ratio
- Good quality
- Supports looping
- Widely supported
- CPU cost for decompression
- Lossy compression
AudioStreamMP3
MP3 audio support: Advantages:- Universal format
- Good compression
- Works well for voice and music
- Slightly worse quality than OGG at same bitrate
- Higher CPU usage for decoding
- Licensing considerations (less relevant now)
Format Comparison
| Format | Best For | File Size | CPU Usage | Quality |
|---|---|---|---|---|
| WAV | Sound effects | Large | Minimal | Perfect |
| OGG Vorbis | Music, ambient | Small | Moderate | Excellent |
| MP3 | Voice, music | Small | Moderate | Good |
Looping Audio
Basic Looping
Most audio formats support loop mode:Loop Points (WAV)
For WAV files, you can set precise loop points:AudioStream Properties
Getting Stream Information
Metadata and Tags
Access audio file metadata:AudioStreamGenerator
Generate audio procedurally at runtime:AudioStreamGenerator is useful for synthesizers, dynamic sound effects, or audio visualization.
AudioStreamRandomizer
Randomly play variations of sounds:AudioStreamPlayback
TheAudioStreamPlayback represents an active playback instance:
Importing Audio Files
Import Settings
When importing audio files in Godot, you can configure: For WAV files:force/8_bit- Reduce to 8-bit audioforce/mono- Convert to monoforce/max_rate- Limit sample rateedit/trim- Remove silenceedit/normalize- Normalize volumeedit/loop_mode- Set loop behavioredit/loop_begin- Loop start pointedit/loop_end- Loop end point
loop- Enable loopingloop_offset- Loop start offset in seconds
Best Practices
Choose the right format
Choose the right format
Use WAV for short sound effects (< 1 second), OGG Vorbis for music and ambient sounds, and consider MP3 for voice dialogue.
Optimize file sizes
Optimize file sizes
Use appropriate bitrates: 128-192 kbps for music, 96-128 kbps for ambient, 64-96 kbps for voice.
Prepare loop points
Prepare loop points
Set proper loop points in your audio editor before importing to ensure seamless loops.
Use mono for non-positional audio
Use mono for non-positional audio
Convert to mono when stereo isn’t necessary to reduce file size and memory usage.
Normalize audio levels
Normalize audio levels
Ensure consistent volume across all audio files to avoid manual volume adjustments.
See Also
Audio Overview
Learn about AudioServer and basic playback
Audio Effects
Apply effects to audio buses
Interactive Music
Create dynamic music systems