From 03b94f61318675f1df83d384670b506a0df6e118 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 20 May 2026 15:37:14 +0200 Subject: Fix TTS and AI voice playback bugs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - tts.py _handle_voice_output: add missing voice_client.play() call via VoiceManager.play_source() — was creating the audio source and then doing nothing - ai.py: use VoiceManager.play_source() instead of passing an FFmpegPCMAudio object to play() which expects a string path --- cogs/ai.py | 7 ++++--- cogs/tts.py | 16 +++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) (limited to 'cogs') diff --git a/cogs/ai.py b/cogs/ai.py index c9237c4..ef2ba7c 100644 --- a/cogs/ai.py +++ b/cogs/ai.py @@ -9,7 +9,6 @@ from discord.ext import commands import logging import httpx from gtts import gTTS -from cogs.music import audio_playback import io logger = logging.getLogger(__name__) @@ -61,12 +60,14 @@ class AI(commands.Cog): else: response_text = response_data["choices"][0]["message"]["content"] if tts: - # Generate TTS tts_obj = gTTS(text=response_text, lang='pl') tts_buffer = io.BytesIO() tts_obj.write_to_fp(tts_buffer) tts_buffer.seek(0) - await audio_playback.AudioPlaybackManager.play(ctx, discord.FFmpegPCMAudio(tts_buffer), delete_after_play=True, interrupt=False) + from cogs.voice import get_voice_manager + vm = get_voice_manager(self.bot) + channel = ctx.author.voice.channel + await vm.play_source(channel, discord.FFmpegPCMAudio(tts_buffer), interrupt=False) else: await ctx.send_followup(response_text) diff --git a/cogs/tts.py b/cogs/tts.py index 68eb27f..ca81d3a 100644 --- a/cogs/tts.py +++ b/cogs/tts.py @@ -42,28 +42,26 @@ class TTS(commands.Cog): await ctx.respond(content="\u200b", ephemeral=True) await ctx.interaction.delete_original_response() - # Check if the user is in a voice channel if not (ctx.author.voice and ctx.author.voice.channel): logger.info("User is not in a voice channel") return channel = ctx.author.voice.channel try: - voice_client = await self._get_or_connect_voice_client(channel) + voice_mgr = self._get_voice_manager() - if not voice_client: - await ctx.respond("Failed to connect to voice channel", ephemeral=True) - return - - if voice_client.is_playing(): - await ctx.respond("Audio is already playing, try again later", ephemeral=True) - return + if voice_mgr.get_voice_client and await voice_mgr.get_client(channel.guild): + vc = await voice_mgr.get_client(channel.guild) + if vc and vc.is_playing(): + logger.info("Audio already playing, skipping TTS") + return audio_source = discord.FFmpegPCMAudio( temp_path, options=f'-filter:a "volume={volume}"' ) logger.info(f"Playing TTS: {text}") + await voice_mgr.play_source(channel, audio_source) except Exception as e: logger.error(f"Error in voice channel handling: {e}") -- cgit v1.2.3