Hi friends, I have an AudioStreamSample with stereo data. How can I convert it to mono? This will reduce the size by half, I think.

Welcome to the forums!

In the import tab on the Godot Editor, I believe there is an option to convert audio to mono. From what I remember, it is near the bottom of the import settings for audio files.

Hello TwistedTwigleg =) !

Thanks for your help! But this is not quite for me. I need to convert throughout the gameplay.

I already wrote a small function for this:

func convert_stereo_to_mono(stream:AudioStreamSample):
	var old_data = stream.get_data()
	var new_data = range(old_data.size() / 2)
	if stream.format == stream.FORMAT_16_BITS:
		for i in new_data.size() / 2:
			new_data[i * 2] = (old_data[i * 4] + old_data[i * 4 + 2]) / 2.0
			new_data[i * 2+1] = (old_data[i * 4 + 1] + old_data[i * 4 + 3])/2.0
	else:
		for i in new_data.size():
			new_data[i] = (old_data[i * 2] + old_data[i * 2 + 1]) / 2.0
	stream.data = new_data
	stream.stereo = false

It works great.

3 years later