aboutsummaryrefslogtreecommitdiffstats
path: root/cogs
diff options
context:
space:
mode:
authorsalmonik <raisersoft@proton.me>2026-05-20 15:37:14 +0200
committersalmonik <raisersoft@proton.me>2026-05-20 15:37:14 +0200
commit03b94f61318675f1df83d384670b506a0df6e118 (patch)
tree79c179cd43a2a419670bd85d9f966215a37f8179 /cogs
parentFold AudioPlaybackManager into VoiceManager + Future-based play (diff)
downloadsenator-sperma-03b94f61318675f1df83d384670b506a0df6e118.tar.gz
senator-sperma-03b94f61318675f1df83d384670b506a0df6e118.zip
Fix TTS and AI voice playback bugs
- 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
Diffstat (limited to 'cogs')
-rw-r--r--cogs/ai.py7
-rw-r--r--cogs/tts.py16
2 files changed, 11 insertions, 12 deletions
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
9import logging 9import logging
10import httpx 10import httpx
11from gtts import gTTS 11from gtts import gTTS
12from cogs.music import audio_playback
13import io 12import io
14 13
15logger = logging.getLogger(__name__) 14logger = logging.getLogger(__name__)
@@ -61,12 +60,14 @@ class AI(commands.Cog):
61 else: 60 else:
62 response_text = response_data["choices"][0]["message"]["content"] 61 response_text = response_data["choices"][0]["message"]["content"]
63 if tts: 62 if tts:
64 # Generate TTS
65 tts_obj = gTTS(text=response_text, lang='pl') 63 tts_obj = gTTS(text=response_text, lang='pl')
66 tts_buffer = io.BytesIO() 64 tts_buffer = io.BytesIO()
67 tts_obj.write_to_fp(tts_buffer) 65 tts_obj.write_to_fp(tts_buffer)
68 tts_buffer.seek(0) 66 tts_buffer.seek(0)
69 await audio_playback.AudioPlaybackManager.play(ctx, discord.FFmpegPCMAudio(tts_buffer), delete_after_play=True, interrupt=False) 67 from cogs.voice import get_voice_manager
68 vm = get_voice_manager(self.bot)
69 channel = ctx.author.voice.channel
70 await vm.play_source(channel, discord.FFmpegPCMAudio(tts_buffer), interrupt=False)
70 71
71 else: 72 else:
72 await ctx.send_followup(response_text) 73 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):
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}")