refactor: Simplify VoiceAudioSink initialization by removing voice_client parameter

This commit is contained in:
Slipstream 2025-05-30 22:07:42 -06:00
parent 09a9ced39c
commit 2706abe5f6
Signed by: slipstream
GPG Key ID: 13E498CE010AC6FD

View File

@ -106,10 +106,10 @@ def _convert_audio_to_16khz_mono(raw_pcm_data_48k_stereo: bytes) -> bytes:
class VoiceAudioSink(voice_recv.AudioSink): # Inherit from voice_recv.AudioSink
def __init__(self, cog_instance, voice_client: voice_recv.VoiceRecvClient): # Updated type hint
def __init__(self, cog_instance): # Removed voice_client parameter
super().__init__()
self.cog = cog_instance
self.voice_client = voice_client # Store the voice_client
# self.voice_client is set by the library when listen() is called
# user_audio_data now keyed by user_id, 'decoder' removed
self.user_audio_data = {} # {user_id: {'buffer': bytearray, 'speaking': False, 'silent_frames': 0, 'speech_frames': 0, 'vad': VAD_instance}}
@ -338,9 +338,9 @@ class VoiceGatewayCog(commands.Cog):
voice_client.stop_listening() # Stop previous listening if any
self.active_sinks[guild_id].cleanup() # Clean old state
# Re-initialize or ensure the sink is fresh for the current VC
self.active_sinks[guild_id] = VoiceAudioSink(self, voice_client)
self.active_sinks[guild_id] = VoiceAudioSink(self)
else:
self.active_sinks[guild_id] = VoiceAudioSink(self, voice_client)
self.active_sinks[guild_id] = VoiceAudioSink(self)
if not voice_client.is_listening():
voice_client.listen(self.active_sinks[guild_id])