Live VC is incredibly staticky

Godot Version

4.7.1

Question

Hello, I’m currently in the process of making live VC for my game, and I have encountered an issue. When playing audio its either mostly or entirely just static.
I’m not sure if its an issue of the AudioSteamPlayers themselves or an issue of the code.

I’ll also note I have taken the time to go through the forum and a few tutorials but I haven’t found anything that has solved the issue (duh thats why Im here :sob: )

so thus I ask the question is there something I’m missing?
thanks in advanced!


# // Constants //
const VCInputThreshold := 0.005;

# // Variables //
var RecordEffect : AudioEffectCapture; ## Effect used for recording mic audio
var VCToggled : bool = false; ## Whether or not VC is toggled on. Used when VC mode is set to toggled
var OutputBuffers : Dictionary[Node, PackedFloat32Array];
func _process(_delta):
	if CanSpeak : ## Dont worry about this, its true
		ProcessMic();
	
	# // Output
	ProcessOutputs();
func AddOutputAudio(Output : Node, AudioData : PackedFloat32Array) : ## adds an audio to an output to be played
	if !Output is AudioStreamPlayer and !Output is AudioStreamPlayer3D : return;
	if !Output.stream or !Output.stream in AudioStreamGenerator : print("Output has invalid stream."); return;
	
	if !Output in OutputBuffers :
		OutputBuffers[Output] = PackedFloat32Array();
		
		if !Output.playing :
			Output.play();
		
		Output.stream.mix_rate = Steam.getVoiceOptimalSampleRate();
	
	OutputBuffers[Output].append_array(AudioData);

# // processing

func ProcessMic() : ## Processes the users mic input
	var SterioData : PackedVector2Array = RecordEffect.get_buffer(RecordEffect.get_frames_available());
	
	if SterioData.size() > 0 :
		
		# // Acquire data
		var data := PackedFloat32Array();
		data.resize(SterioData.size());
		var SumOfSquares := 0.0;
		
		for Index in range(SterioData.size()) :
			var Value : float = (SterioData[Index].x + SterioData[Index].y) / 2;
			#MaxAmplitude = max(Value, MaxAmplitude);
			SumOfSquares += Value * Value;
			data[Index] = Value;
		
		var MeanSquare : float = SumOfSquares / SterioData.size();
		
		if sqrt(MeanSquare) < VCInputThreshold : # Too quite, cancel.
			return
		
		rpc_id(1, "_send_player_audio", data);

func ProcessOutputs() : ## Processes all outputs
	for Output : Node in OutputBuffers :
		if !Output is AudioStreamPlayer and !Output is AudioStreamPlayer3D : continue;
		
		var Playback : AudioStreamGeneratorPlayback = Output.get_stream_playback();
		
		print("Output: ", Output.name);
		
		if OutputBuffers[Output].size() <= 0 :
			Playback.push_frame(Vector2.ZERO);
		else :
			for i in range (min(Playback.get_frames_available(), OutputBuffers[Output].size())) :
				Playback.push_frame(Vector2(OutputBuffers[Output][0], OutputBuffers[Output][0]));
				OutputBuffers[Output].remove_at(0);

I didnt include any of the RPC functions seeing as they dont modify the data in anyway, but I will note the AddOutputAudio function is called by an RPC that is triggered via the ProcessMic function.

if there are any other details I should provide please let me know