aboutsummaryrefslogtreecommitdiffstats
path: root/cogs/tts.py
diff options
context:
space:
mode:
authorsalmonik <raisersoft@proton.me>2026-05-21 17:10:23 +0200
committersalmonik <raisersoft@proton.me>2026-05-21 17:10:23 +0200
commit2e614665e0c62fe572b5af53a2a6be1116d66720 (patch)
treedbb48ad5d665a3f3d8c793db30a523264f17bcde /cogs/tts.py
parentfix naming not resolving things like %20 (diff)
parentFix voice reconnect race: reuse VoiceClient instead of destroying it (diff)
downloadsenator-sperma-2e614665e0c62fe572b5af53a2a6be1116d66720.tar.gz
senator-sperma-2e614665e0c62fe572b5af53a2a6be1116d66720.zip
Merge pull request 'Voice related fixes, alongside simplifying assistant' (#5) from dev into main
Reviewed-on: https://codeberg.org/salmonik/senator-sperma/pulls/5
Diffstat (limited to '')
-rw-r--r--cogs/tts.py16
1 files changed, 7 insertions, 9 deletions
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):
42 await ctx.respond(content="\u200b", ephemeral=True) 42 await ctx.respond(content="\u200b", ephemeral=True)
43 await ctx.interaction.delete_original_response() 43 await ctx.interaction.delete_original_response()
44 44
45 # Check if the user is in a voice channel
46 if not (ctx.author.voice and ctx.author.voice.channel): 45 if not (ctx.author.voice and ctx.author.voice.channel):
47 logger.info("User is not in a voice channel") 46 logger.info("User is not in a voice channel")
48 return 47 return
49 48
50 channel = ctx.author.voice.channel 49 channel = ctx.author.voice.channel
51 try: 50 try:
52 voice_client = await self._get_or_connect_voice_client(channel) 51 voice_mgr = self._get_voice_manager()
53 52
54 if not voice_client: 53 if voice_mgr.get_voice_client and await voice_mgr.get_client(channel.guild):
55 await ctx.respond("Failed to connect to voice channel", ephemeral=True) 54 vc = await voice_mgr.get_client(channel.guild)
56 return 55 if vc and vc.is_playing():
57 56 logger.info("Audio already playing, skipping TTS")
58 if voice_client.is_playing(): 57 return
59 await ctx.respond("Audio is already playing, try again later", ephemeral=True)
60 return
61 58
62 audio_source = discord.FFmpegPCMAudio( 59 audio_source = discord.FFmpegPCMAudio(
63 temp_path, 60 temp_path,
64 options=f'-filter:a "volume={volume}"' 61 options=f'-filter:a "volume={volume}"'
65 ) 62 )
66 logger.info(f"Playing TTS: {text}") 63 logger.info(f"Playing TTS: {text}")
64 await voice_mgr.play_source(channel, audio_source)
67 65
68 except Exception as e: 66 except Exception as e:
69 logger.error(f"Error in voice channel handling: {e}") 67 logger.error(f"Error in voice channel handling: {e}")