diff options
Diffstat (limited to '')
| -rw-r--r-- | cogs/ai.py | 7 | ||||
| -rw-r--r-- | cogs/tts.py | 16 |
2 files changed, 11 insertions, 12 deletions
| @@ -9,7 +9,6 @@ from discord.ext import commands | |||
| 9 | import logging | 9 | import logging |
| 10 | import httpx | 10 | import httpx |
| 11 | from gtts import gTTS | 11 | from gtts import gTTS |
| 12 | from cogs.music import audio_playback | ||
| 13 | import io | 12 | import io |
| 14 | 13 | ||
| 15 | logger = logging.getLogger(__name__) | 14 | logger = 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}") |
