Godot supports in-game audio recording for Windows, macOS, Linux, Android and
The demo consists of a single scene. This scene includes two major parts: the
GUI and the audio.
We will focus on the audio part. In this demo, a bus named
Record with the
Record is created to handle the audio recording.
AudioStreamRecord is used for recording.
# We get the index of the "Record" bus.
var idx = AudioServer.get_bus_index("Record")
# And use it to retrieve its first effect, which has been defined
# as an "AudioEffectRecord" resource.
effect = AudioServer.get_bus_effect(idx, 0)
The audio recording is handled by the AudioEffectRecord resource
which has three methods:
recording = effect.get_recording()
$PlayButton.disabled = false
$SaveButton.disabled = false
$RecordButton.text = "Record"
$Status.text = ""
$PlayButton.disabled = true
$SaveButton.disabled = true
$RecordButton.text = "Stop"
$Status.text = "Recording..."
At the start of the demo, the recording effect is not active. When the user
RecordButton, the effect is enabled with
On the next button press, as
the recorded stream can be stored into the
recording variable by calling
var data = recording.get_data()
$AudioStreamPlayer.stream = recording
To playback the recording, you assign the recording as the stream of the
AudioStreamPlayer and call
var save_path = $SaveButton/Filename.text
$Status.text = "Saved WAV file to: %s\n(%s)" % [save_path, ProjectSettings.globalize_path(save_path)]
To save the recording, you call
save_to_wav() with the path to a file.
In this demo, the path is defined by the user via a
LineEdit input box.