From d135265798da8c2698f363237f4cb74b682f3f9e Mon Sep 17 00:00:00 2001 From: salmonik Date: Fri, 17 Apr 2026 15:36:12 +0200 Subject: make voice great again Signed-off-by: salmonik --- cogs/vclogs.py | 55 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) (limited to 'cogs/vclogs.py') diff --git a/cogs/vclogs.py b/cogs/vclogs.py index 477aa1c..274d6ca 100644 --- a/cogs/vclogs.py +++ b/cogs/vclogs.py @@ -76,40 +76,41 @@ class VcLogs(commands.Cog): tts_file = os.path.join(temp_dir, f"temp_tts_{os.getpid()}.mp3") tts = gTTS(text=text, lang='pl') logger.info("saving file") - tts.save(tts_file) - - # Get voice status using our new method - voice_status = await voice_mgr.get_voice_status(channel.guild) - voice_client = voice_status[0] if voice_status else None - is_connected = voice_status[1] if voice_status else False - is_playing = voice_status[2] if voice_status else False - # Ensure we have a connected voice client - if not is_connected: - voice_client = await voice_mgr.join_channel(channel) - # Update status after joining + loop = asyncio.get_event_loop() + await loop.run_in_executor(None, tts.save, tts_file) + + try: voice_status = await voice_mgr.get_voice_status(channel.guild) voice_client = voice_status[0] if voice_status else None is_connected = voice_status[1] if voice_status else False is_playing = voice_status[2] if voice_status else False - - if not is_connected or voice_client is None: - logger.error("Failed to join voice channel") + + if not is_connected: + voice_client = await voice_mgr.join_channel(channel) + voice_status = await voice_mgr.get_voice_status(channel.guild) + voice_client = voice_status[0] if voice_status else None + is_connected = voice_status[1] if voice_status else False + is_playing = voice_status[2] if voice_status else False + + if not is_connected or voice_client is None: + logger.error("Failed to join voice channel") + return + + volume = get_volume() + logger.info(f"connected: {voice_client}") + + if voice_client and not is_playing: + logger.info("preparing to play audio") + audio_source = discord.FFmpegPCMAudio(tts_file, options=f'-filter:a "volume={volume}"') + voice_client.play(audio_source) + while voice_client.is_playing(): + await asyncio.sleep(0.5) + except Exception as e: + logger.error(f"TTS playback error: {e}") + finally: if os.path.exists(tts_file): os.remove(tts_file) - return - - volume = get_volume() - logger.info(f"connected: {voice_client}") - - if voice_client and not is_playing: - logger.info("preparing to play audio") - audio_source = discord.FFmpegPCMAudio(tts_file, options=f'-filter:a "volume={volume}"') - voice_client.play(audio_source) - while voice_client.is_playing(): - await asyncio.sleep(0.5) - if os.path.exists(tts_file): - os.remove(tts_file) @commands.slash_command( name="log_volume" -- cgit v1.2.3