aboutsummaryrefslogtreecommitdiffstats
path: root/cogs/tts.py
diff options
context:
space:
mode:
authorsalmonik <raisersoft@proton.me>2026-03-18 15:29:51 +0100
committersalmonik <raisersoft@proton.me>2026-03-18 15:29:51 +0100
commitc0053ca98912901b5d387d58fbc57f9b7da91f38 (patch)
tree14fe7a7beae1ca2745333dcd7032a6ced28de0f7 /cogs/tts.py
parentfix tts (diff)
downloadsenator-sperma-c0053ca98912901b5d387d58fbc57f9b7da91f38.tar.gz
senator-sperma-c0053ca98912901b5d387d58fbc57f9b7da91f38.zip
voice doesn't work due to DAVE, but we got copyparty search
Diffstat (limited to '')
-rw-r--r--cogs/tts.py25
1 files changed, 14 insertions, 11 deletions
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):
40 logger.error(f"Error sending file: {e}") 40 logger.error(f"Error sending file: {e}")
41 await ctx.respond("eror :c", ephemeral=True) 41 await ctx.respond("eror :c", ephemeral=True)
42 42
43 def _get_voice_manager(self):
44 from cogs.voice import get_voice_manager
45 return get_voice_manager(self.bot)
46
43 async def _get_or_connect_voice_client(self, channel): 47 async def _get_or_connect_voice_client(self, channel):
44 """Get existing voice client or connect to new channel""" 48 """Get existing voice client or connect to new channel"""
45 voice_client = discord.utils.get(self.bot.voice_clients, guild=channel.guild) 49 voice_mgr = self._get_voice_manager()
46 50 return await voice_mgr.join_channel(channel)
47 if not voice_client or not voice_client.is_connected():
48 voice_client = await channel.connect()
49 elif voice_client.channel != channel:
50 await voice_client.move_to(channel)
51
52 return voice_client
53 51
54 async def _handle_voice_output(self, ctx, temp_path, text, volume): 52 async def _handle_voice_output(self, ctx, temp_path, text, volume):
55 """Handle TTS voice channel output""" 53 """Handle TTS voice channel output"""
@@ -65,6 +63,10 @@ class TTS(commands.Cog):
65 try: 63 try:
66 voice_client = await self._get_or_connect_voice_client(channel) 64 voice_client = await self._get_or_connect_voice_client(channel)
67 65
66 if not voice_client:
67 await ctx.respond("Failed to connect to voice channel", ephemeral=True)
68 return
69
68 # Play the TTS audio with volume adjustment 70 # Play the TTS audio with volume adjustment
69 audio_source = discord.FFmpegPCMAudio( 71 audio_source = discord.FFmpegPCMAudio(
70 temp_path, 72 temp_path,
@@ -96,9 +98,10 @@ class TTS(commands.Cog):
96 ): 98 ):
97 await ctx.defer() 99 await ctx.defer()
98 100
99 # Create temporary file path asynchronously 101 # Create temporary file in temp folder
100 temp_fd, temp_path = tempfile.mkstemp(suffix=".mp3") 102 temp_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'temp')
101 os.close(temp_fd) # Close the file descriptor, we'll write to it asynchronously 103 os.makedirs(temp_dir, exist_ok=True)
104 temp_path = os.path.join(temp_dir, f"tts_{os.getpid()}_{asyncio.get_event_loop().time()}.mp3")
102 105
103 try: 106 try:
104 # Generate and save TTS to temp file 107 # Generate and save TTS to temp file