diff options
Diffstat (limited to '')
| -rw-r--r-- | cogs/vclogs.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/cogs/vclogs.py b/cogs/vclogs.py index e5ca202..35826d4 100644 --- a/cogs/vclogs.py +++ b/cogs/vclogs.py | |||
| @@ -116,7 +116,7 @@ class VcLogs(commands.Cog): | |||
| 116 | 116 | ||
| 117 | voice_mgr = self.get_voice_manager() | 117 | voice_mgr = self.get_voice_manager() |
| 118 | temp_dir = get_temp_dir() | 118 | temp_dir = get_temp_dir() |
| 119 | tts_file = os.path.join(temp_dir, f"temp_tts_{os.getpid()}.mp3") | 119 | tts_file = os.path.join(temp_dir, f"temp_tts_{os.getpid()}_{asyncio.get_event_loop().time()}.mp3") |
| 120 | tts = gTTS(text=text, lang='pl') | 120 | tts = gTTS(text=text, lang='pl') |
| 121 | logger.info("saving file") | 121 | logger.info("saving file") |
| 122 | 122 | ||
| @@ -129,6 +129,16 @@ class VcLogs(commands.Cog): | |||
| 129 | is_connected = voice_status[1] if voice_status else False | 129 | is_connected = voice_status[1] if voice_status else False |
| 130 | is_playing = voice_status[2] if voice_status else False | 130 | is_playing = voice_status[2] if voice_status else False |
| 131 | 131 | ||
| 132 | if is_connected: | ||
| 133 | from cogs.voice import is_voice_client_alive | ||
| 134 | if not is_voice_client_alive(voice_client, channel.guild): | ||
| 135 | logger.warning("Stale voice client in play_tts, reconnecting") | ||
| 136 | try: | ||
| 137 | await voice_client.disconnect() | ||
| 138 | except Exception: | ||
| 139 | pass | ||
| 140 | is_connected = False | ||
| 141 | |||
| 132 | if not is_connected: | 142 | if not is_connected: |
| 133 | voice_client = await voice_mgr.join_channel(channel) | 143 | voice_client = await voice_mgr.join_channel(channel) |
| 134 | voice_status = await voice_mgr.get_voice_status(channel.guild) | 144 | voice_status = await voice_mgr.get_voice_status(channel.guild) |
| @@ -150,12 +160,7 @@ class VcLogs(commands.Cog): | |||
| 150 | 160 | ||
| 151 | logger.info("preparing to play audio") | 161 | logger.info("preparing to play audio") |
| 152 | audio_source = discord.FFmpegPCMAudio(tts_file) | 162 | audio_source = discord.FFmpegPCMAudio(tts_file) |
| 153 | if volume != 1.0: | 163 | await voice_mgr.play_source(channel, audio_source, volume=volume) |
| 154 | audio_source = discord.PCMVolumeTransformer(audio_source) | ||
| 155 | audio_source.volume = volume | ||
| 156 | voice_client.play(audio_source) | ||
| 157 | while voice_client.is_playing(): | ||
| 158 | await asyncio.sleep(0.1) | ||
| 159 | except Exception as e: | 164 | except Exception as e: |
| 160 | logger.error(f"TTS playback error: {e}") | 165 | logger.error(f"TTS playback error: {e}") |
| 161 | finally: | 166 | finally: |
