aboutsummaryrefslogtreecommitdiffstats
path: root/cogs/tts.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--cogs/tts.py21
1 files changed, 10 insertions, 11 deletions
diff --git a/cogs/tts.py b/cogs/tts.py
index 65f1fce..3dc4c09 100644
--- a/cogs/tts.py
+++ b/cogs/tts.py
@@ -46,15 +46,15 @@ class TTS(commands.Cog):
46 if not (ctx.author.voice and ctx.author.voice.channel): 46 if not (ctx.author.voice and ctx.author.voice.channel):
47 logger.info("User is not in a voice channel") 47 logger.info("User is not in a voice channel")
48 return 48 return
49 49
50 channel = ctx.author.voice.channel 50 channel = ctx.author.voice.channel
51 try: 51 try:
52 voice_client = await self._get_or_connect_voice_client(channel) 52 voice_client = await self._get_or_connect_voice_client(channel)
53 53
54 if not voice_client: 54 if not voice_client:
55 await ctx.respond("Failed to connect to voice channel", ephemeral=True) 55 await ctx.respond("Failed to connect to voice channel", ephemeral=True)
56 return 56 return
57 57
58 # Play the TTS audio with volume adjustment 58 # Play the TTS audio with volume adjustment
59 audio_source = discord.FFmpegPCMAudio( 59 audio_source = discord.FFmpegPCMAudio(
60 temp_path, 60 temp_path,
@@ -62,11 +62,11 @@ class TTS(commands.Cog):
62 ) 62 )
63 voice_client.play(audio_source) 63 voice_client.play(audio_source)
64 logger.info(f"Playing TTS: {text}") 64 logger.info(f"Playing TTS: {text}")
65 65
66 # Wait for the audio to finish playing 66 # Wait for the audio to finish playing
67 while voice_client.is_playing(): 67 while voice_client.is_playing():
68 await asyncio.sleep(0.1) 68 await asyncio.sleep(0.1)
69 69
70 except Exception as e: 70 except Exception as e:
71 logger.error(f"Error in voice channel handling: {e}") 71 logger.error(f"Error in voice channel handling: {e}")
72 await ctx.respond("eror :c", ephemeral=True) 72 await ctx.respond("eror :c", ephemeral=True)
@@ -85,11 +85,10 @@ class TTS(commands.Cog):
85 output: str = discord.Option(str, "Wybierz sposób odtwarzania", choices=["file", "vc"], default="vc") 85 output: str = discord.Option(str, "Wybierz sposób odtwarzania", choices=["file", "vc"], default="vc")
86 ): 86 ):
87 await ctx.defer() 87 await ctx.defer()
88 88
89 # Create temporary file in temp folder 89 # Create temporary file in temp folder
90 temp_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'temp') 90 from cogs.utils.temp import get_temp_dir
91 os.makedirs(temp_dir, exist_ok=True) 91 temp_path = os.path.join(get_temp_dir(), f"tts_{os.getpid()}_{asyncio.get_event_loop().time()}.mp3")
92 temp_path = os.path.join(temp_dir, f"tts_{os.getpid()}_{asyncio.get_event_loop().time()}.mp3")
93 92
94 try: 93 try:
95 # Generate and save TTS to temp file 94 # Generate and save TTS to temp file
@@ -105,7 +104,7 @@ class TTS(commands.Cog):
105 await self._handle_file_output(ctx, temp_path, text) 104 await self._handle_file_output(ctx, temp_path, text)
106 elif output == "vc": 105 elif output == "vc":
107 await self._handle_voice_output(ctx, temp_path, text, volume) 106 await self._handle_voice_output(ctx, temp_path, text, volume)
108 107
109 except Exception as e: 108 except Exception as e:
110 logger.error(f"TTS generation error: {e}") 109 logger.error(f"TTS generation error: {e}")
111 await ctx.respond("Error generating TTS", ephemeral=True) 110 await ctx.respond("Error generating TTS", ephemeral=True)
@@ -113,4 +112,4 @@ class TTS(commands.Cog):
113 await self._cleanup_temp_file(temp_path) 112 await self._cleanup_temp_file(temp_path)
114 113
115def setup(bot): 114def setup(bot):
116 bot.add_cog(TTS(bot)) \ No newline at end of file 115 bot.add_cog(TTS(bot))