From c6c5d9c9a7e0d89b7e3377ad4342464807527c7c Mon Sep 17 00:00:00 2001 From: norohind <60548839+norohind@users.noreply.github.com> Date: Mon, 16 May 2022 19:20:34 +0300 Subject: [PATCH] Add more debug prints for TTSCore, separate try blocks for playing and synth --- cogs/TTSCore.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/cogs/TTSCore.py b/cogs/TTSCore.py index 8558719..65575eb 100644 --- a/cogs/TTSCore.py +++ b/cogs/TTSCore.py @@ -78,19 +78,27 @@ class TTSCore(commands.Cog, Observ.Observer): try: wav_file_like_object = self.tts.synthesize_text(message.content, speaker=speaker) sound_source = FFmpegPCMAudio(wav_file_like_object, pipe=True, stderr=subprocess.PIPE) - if voice_client.is_playing(): - # Then we need to enqueue prepared sound for playing through self.tts_queues mechanism - - self.tts_queues[message.guild.id].append(sound_source) - await message.channel.send(f"Enqueued for play, queue size: {len(self.tts_queues[message.guild.id])}") - return - - voice_client.play(sound_source, after=lambda e: self.queue_player(message)) except Exception as synth_exception: logger.opt(exception=True).warning(f'Exception on synthesize {message.content!r}: {synth_exception}') - await message.channel.send(f'Internal error') + await message.channel.send(f'Synthesize error') DB.SynthesisErrors.create(speaker=speaker.value, text=message.content) + return + + else: + try: + if voice_client.is_playing(): + # Then we need to enqueue prepared sound for playing through self.tts_queues mechanism + self.tts_queues[message.guild.id].append(sound_source) + await message.channel.send(f"Enqueued for play, queue size: {len(self.tts_queues[message.guild.id])}") + return + + voice_client.play(sound_source, after=lambda e: self.queue_player(message)) + + except Exception as play_exception: + logger.opt(exception=True).warning(f'Exception on playing for: {message.guild.name}[#{message.channel.name}]: {message.author.display_name} / {play_exception}') + await message.channel.send(f'Playing error') + return def queue_player(self, message: discord.Message): voice_client: Optional[discord.VoiceClient] = message.guild.voice_client @@ -118,6 +126,8 @@ class TTSCore(commands.Cog, Observ.Observer): if members[0].id == self.bot.user.id: await before.channel.guild.voice_client.disconnect(force=False) + # TODO: leave voice channel after being moved there alone + async def setup(bot): await bot.add_cog(TTSCore(bot))