Table of Contents

Class AudioStreamWAV

Stores audio data loaded from WAV files.

Inheritance
AudioStreamWAV

Remarks

AudioStreamWAV stores sound samples loaded from WAV files. To play the stored sound, use an AudioStreamPlayer (for non-positional audio) or AudioStreamPlayer2D/AudioStreamPlayer3D (for positional audio). The sound can be looped.

This class can also be used to store dynamically-generated PCM audio data. See also AudioStreamGenerator for procedural audio generation.

See Also

Properties

data

Contains the audio data in bytes.

Note: If format is set to AudioStreamWAV.FORMAT_8_BITS, this property expects signed 8-bit PCM data. To convert from unsigned 8-bit PCM, subtract 128 from each byte.

Note: If format is set to AudioStreamWAV.FORMAT_QOA, this property expects data from a full QOA file.

var data : PackedByteArray = PackedByteArray()

Property Value

PackedByteArray

Remarks

format

Audio format. See Format constants for values.

var format : int = 0

Property Value

int

Remarks

  • void set_format(int value)
  • int get_format

loop_begin

The loop start point (in number of samples, relative to the beginning of the stream).

var loop_begin : int = 0

Property Value

int

Remarks

  • void set_loop_begin(int value)
  • int get_loop_begin

loop_end

The loop end point (in number of samples, relative to the beginning of the stream).

var loop_end : int = 0

Property Value

int

Remarks

  • void set_loop_end(int value)
  • int get_loop_end

loop_mode

The loop mode. See LoopMode constants for values.

var loop_mode : int = 0

Property Value

int

Remarks

  • void set_loop_mode(int value)
  • int get_loop_mode

mix_rate

The sample rate for mixing this audio. Higher values require more storage space, but result in better quality.

In games, common sample rates in use are 11025, 16000, 22050, 32000, 44100, and 48000.

According to the Nyquist-Shannon sampling theorem, there is no quality difference to human hearing when going past 40,000 Hz (since most humans can only hear up to ~20,000 Hz, often less). If you are using lower-pitched sounds such as voices, lower sample rates such as 32000 or 22050 may be usable with no loss in quality.

var mix_rate : int = 44100

Property Value

int

Remarks

  • void set_mix_rate(int value)
  • int get_mix_rate

stereo

If true, audio is stereo.

var stereo : bool = false

Property Value

bool

Remarks

  • void set_stereo(bool value)
  • bool is_stereo

Methods

load_from_buffer(PackedByteArray, Dictionary)

Qualifiers: static

Creates a new AudioStreamWAV instance from the given buffer. The buffer must contain WAV data.

The keys and values of options match the properties of ResourceImporterWAV. The usage of options is identical to AudioStreamWAV.load_from_file.

AudioStreamWAV load_from_buffer(PackedByteArray stream_data, Dictionary options)

Parameters

stream_data PackedByteArray
options Dictionary

load_from_file(String, Dictionary)

Qualifiers: static

Creates a new AudioStreamWAV instance from the given file path. The file must be in WAV format.

The keys and values of options match the properties of ResourceImporterWAV.

Example: Load the first file dropped as a WAV and play it:

@onready var audio_player = $AudioStreamPlayer

func _ready():
    get_window().files_dropped.connect(_on_files_dropped)

func _on_files_dropped(files):
    if files[0].get_extension() == "wav":
        audio_player.stream = AudioStreamWAV.load_from_file(files[0], {
                "force/max_rate": true,
                "force/max_rate_hz": 11025
            })
        audio_player.play()

AudioStreamWAV load_from_file(String path, Dictionary options)

Parameters

path String
options Dictionary

save_to_wav(String)

Saves the AudioStreamWAV as a WAV file to path. Samples with IMA ADPCM or Quite OK Audio formats can't be saved.

Note: A .wav extension is automatically appended to path if it is missing.

int save_to_wav(String path)

Parameters

path String