Can't save audio recording file

Godot Version

Godot 4.2.2

Question

I can’t save the recording, I get this error:
1
And I use this code:

extends TextureButton
var audio_rec:AudioEffectRecord
var rec:bool=false

func _ready():
	audio_rec = AudioEffectRecord.new()
	audio_rec.set_format(AudioStreamWAV.FORMAT_16_BITS)
	connect("pressed",_press)
	pass
	

func _press():
	rec=!rec
	if rec:
		texture_normal=preload("res://microphone_rec.png")
		audio_rec.set_recording_active(true)
	else:
		texture_normal=preload("res://microphone.png")
		var err = audio_rec.get_recording().save_to_wav("res://asd.wav")
		audio_rec.set_recording_active(false)
	pass

Seems like your recording is null. Maybe you need to set_recording_active(false) before trying to save.

audio_rec.set_recording_active(false)

var recording = audio_rec.get_recording()
if recording:
	var err = recording.save_to_wav("res://asd.wav")
	assert(err == OK, "Couldn't save to wav: %s" % error_string(err))
else:
	push_warning("No recording found")

I placed the recording activation before and after, it didn’t help.
As it turned out, the entry is really empty, then how to fill it? I produce sound in the background using godot and the main default_bus_layout, and activate recording

Checking the docs for this type I think you do not want to try making it manually in scripts. This tutorial outlines how to record with a microphone, but if you place the “Record” effect on the master bus it will record the entire game.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.