From c0053ca98912901b5d387d58fbc57f9b7da91f38 Mon Sep 17 00:00:00 2001 From: salmonik Date: Wed, 18 Mar 2026 15:29:51 +0100 Subject: voice doesn't work due to DAVE, but we got copyparty search --- cogs/tts.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'cogs/tts.py') diff --git a/cogs/tts.py b/cogs/tts.py index a330b74..46ab637 100644 --- a/cogs/tts.py +++ b/cogs/tts.py @@ -40,16 +40,14 @@ class TTS(commands.Cog): logger.error(f"Error sending file: {e}") await ctx.respond("eror :c", ephemeral=True) + def _get_voice_manager(self): + from cogs.voice import get_voice_manager + return get_voice_manager(self.bot) + async def _get_or_connect_voice_client(self, channel): """Get existing voice client or connect to new channel""" - voice_client = discord.utils.get(self.bot.voice_clients, guild=channel.guild) - - if not voice_client or not voice_client.is_connected(): - voice_client = await channel.connect() - elif voice_client.channel != channel: - await voice_client.move_to(channel) - - return voice_client + voice_mgr = self._get_voice_manager() + return await voice_mgr.join_channel(channel) async def _handle_voice_output(self, ctx, temp_path, text, volume): """Handle TTS voice channel output""" @@ -65,6 +63,10 @@ class TTS(commands.Cog): try: voice_client = await self._get_or_connect_voice_client(channel) + if not voice_client: + await ctx.respond("Failed to connect to voice channel", ephemeral=True) + return + # Play the TTS audio with volume adjustment audio_source = discord.FFmpegPCMAudio( temp_path, @@ -96,9 +98,10 @@ class TTS(commands.Cog): ): await ctx.defer() - # Create temporary file path asynchronously - temp_fd, temp_path = tempfile.mkstemp(suffix=".mp3") - os.close(temp_fd) # Close the file descriptor, we'll write to it asynchronously + # Create temporary file in temp folder + temp_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'temp') + os.makedirs(temp_dir, exist_ok=True) + temp_path = os.path.join(temp_dir, f"tts_{os.getpid()}_{asyncio.get_event_loop().time()}.mp3") try: # Generate and save TTS to temp file -- cgit v1.2.3