Stores audio data loaded from WAV files.
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.
$DOCS_URL/tutorials/io/runtime_file_loading_and_saving.html
Creates a new [AudioStreamWAV] instance from the given buffer. The buffer must contain WAV data. The keys and values of [param options] match the properties of [ResourceImporterWAV]. The usage of [param options] is identical to [method AudioStreamWAV.load_from_file].
Creates a new [AudioStreamWAV] instance from the given file path. The file must be in WAV format. The keys and values of [param options] match the properties of [ResourceImporterWAV]. [b]Example:[/b] Load the first file dropped as a WAV and play it: [codeblock] @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() [/codeblock]
Saves the AudioStreamWAV as a WAV file to [param path]. Samples with IMA ADPCM or Quite OK Audio formats can't be saved. [b]Note:[/b] A [code].wav[/code] extension is automatically appended to [param path] if it is missing.
- Contains the audio data in bytes. [b]Note:[/b] If [member format] is set to [constant FORMAT_8_BITS], this property expects signed 8-bit PCM data. To convert from unsigned 8-bit PCM, subtract 128 from each byte. [b]Note:[/b] If [member format] is set to [constant FORMAT_QOA], this property expects data from a full QOA file.
- Audio format.
- The loop start point (in number of samples, relative to the beginning of the stream).
- The loop end point (in number of samples, relative to the beginning of the stream).
- The loop mode.
- 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 [code]11025[/code], [code]16000[/code], [code]22050[/code], [code]32000[/code], [code]44100[/code], and [code]48000[/code]. According to the [url=https://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem]Nyquist-Shannon sampling theorem[/url], 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 [code]32000[/code] or [code]22050[/code] may be usable with no loss in quality.
- If [code]true[/code], audio is stereo.
- Contains user-defined tags if found in the WAV data. Commonly used tags include [code]title[/code], [code]artist[/code], [code]album[/code], [code]tracknumber[/code], and [code]date[/code] ([code]date[/code] does not have a standard date format). [b]Note:[/b] No tag is [i]guaranteed[/i] to be present in every file, so make sure to account for the keys not always existing. [b]Note:[/b] Only WAV files using a [code]LIST[/code] chunk with an identifier of [code]INFO[/code] to encode the tags are currently supported.
8-bit PCM audio codec.
16-bit PCM audio codec.
Audio is lossily compressed as IMA ADPCM.
Audio is lossily compressed as [url=https://qoaformat.org/]Quite OK Audio[/url].
Audio does not loop.
Audio loops the data between [member loop_begin] and [member loop_end], playing forward only.
Audio loops the data between [member loop_begin] and [member loop_end], playing back and forth.
Audio loops the data between [member loop_begin] and [member loop_end], playing backward only.