fix: Update asyncio task creation to use bot loop in VoiceAudioSink for audio segment processing

This commit is contained in:
Slipstream 2025-05-30 22:11:41 -06:00
parent 429d416010
commit 7dd00644a2
Signed by: slipstream
GPG Key ID: 13E498CE010AC6FD

View File

@ -204,7 +204,7 @@ class VoiceAudioSink(voice_recv.AudioSink): # Inherit from voice_recv.AudioSink
entry['speech_frames'] += 1
if entry['speech_frames'] >= MAX_SPEECH_FRAMES:
# print(f"Max speech frames reached for User {user_id}. Processing segment.")
asyncio.create_task(self.cog.process_audio_segment(user_id, bytes(entry['buffer']), self.voice_client.guild))
self.cog.bot.loop.create_task(self.cog.process_audio_segment(user_id, bytes(entry['buffer']), self.voice_client.guild))
entry['buffer'].clear()
entry['speaking'] = False
entry['speech_frames'] = 0
@ -213,7 +213,7 @@ class VoiceAudioSink(voice_recv.AudioSink): # Inherit from voice_recv.AudioSink
entry['silent_frames'] += 1
if entry['silent_frames'] >= SILENCE_THRESHOLD_FRAMES:
# print(f"Silence threshold reached for User {user_id}. Processing segment.")
asyncio.create_task(self.cog.process_audio_segment(user_id, bytes(entry['buffer']), self.voice_client.guild))
self.cog.bot.loop.create_task(self.cog.process_audio_segment(user_id, bytes(entry['buffer']), self.voice_client.guild))
entry['buffer'].clear()
entry['speaking'] = False
entry['speech_frames'] = 0
@ -230,7 +230,7 @@ class VoiceAudioSink(voice_recv.AudioSink): # Inherit from voice_recv.AudioSink
if self.voice_client and self.voice_client.guild:
guild = self.voice_client.guild
print(f"Processing remaining audio for User ID {user_id} on cleanup.")
asyncio.create_task(self.cog.process_audio_segment(user_id, bytes(data_entry['buffer']), guild))
self.cog.bot.loop.create_task(self.cog.process_audio_segment(user_id, bytes(data_entry['buffer']), guild))
else:
print(f"Cannot process remaining audio for User ID {user_id}: voice_client or guild not available.")
self.user_audio_data.clear()