diff options
| author | Samlon <stankiewiczgracjan2019@gmail.com> | 2025-08-21 12:22:00 +0200 |
|---|---|---|
| committer | Samlon <stankiewiczgracjan2019@gmail.com> | 2025-08-21 12:22:00 +0200 |
| commit | d4248bca50064d4435db713cf2c81a007d394c63 (patch) | |
| tree | f43996574b412cad31150ea848ac45ff384909aa /cogs/tts.py | |
| parent | play.py rework (diff) | |
| download | senator-sperma-d4248bca50064d4435db713cf2c81a007d394c63.tar.gz senator-sperma-d4248bca50064d4435db713cf2c81a007d394c63.zip | |
small changes
Diffstat (limited to 'cogs/tts.py')
| -rw-r--r-- | cogs/tts.py | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/cogs/tts.py b/cogs/tts.py index 7461a1f..74fc12c 100644 --- a/cogs/tts.py +++ b/cogs/tts.py | |||
| @@ -17,6 +17,7 @@ class TTS(commands.Cog): | |||
| 17 | text: str = discord.Option(str, "Tekst do przeczytania", required=True), | 17 | text: str = discord.Option(str, "Tekst do przeczytania", required=True), |
| 18 | output: str = discord.Option(str, "Wybierz sposób odtwarzania", choices=["file", "vc"], default="vc") | 18 | output: str = discord.Option(str, "Wybierz sposób odtwarzania", choices=["file", "vc"], default="vc") |
| 19 | ): | 19 | ): |
| 20 | await ctx.defer() | ||
| 20 | tts = gTTS(text=text, lang='pl') | 21 | tts = gTTS(text=text, lang='pl') |
| 21 | tts.save('tts.mp3') | 22 | tts.save('tts.mp3') |
| 22 | 23 | ||
| @@ -29,11 +30,11 @@ class TTS(commands.Cog): | |||
| 29 | 30 | ||
| 30 | if output == "file": | 31 | if output == "file": |
| 31 | await ctx.respond(file=discord.File('tts.mp3')) | 32 | await ctx.respond(file=discord.File('tts.mp3')) |
| 32 | logger.info("TTS file sent") | 33 | logger.info(f"sent {text}") |
| 33 | os.remove('tts.mp3') | 34 | os.remove('tts.mp3') |
| 34 | elif output == "vc": | 35 | elif output == "vc": |
| 35 | await ctx.respond(content="\u200b", ephemeral=True) | 36 | await ctx.respond(content="\u200b", ephemeral=True) |
| 36 | await ctx.interaction.delete_original_message() | 37 | await ctx.interaction.delete_original_response() |
| 37 | 38 | ||
| 38 | # Check if the user is in a voice channel | 39 | # Check if the user is in a voice channel |
| 39 | if not (ctx.author.voice and ctx.author.voice.channel): | 40 | if not (ctx.author.voice and ctx.author.voice.channel): |
| @@ -50,11 +51,8 @@ class TTS(commands.Cog): | |||
| 50 | # Play the TTS audio | 51 | # Play the TTS audio |
| 51 | if not voice_client.is_playing(): | 52 | if not voice_client.is_playing(): |
| 52 | audio_source = discord.FFmpegPCMAudio('tts.mp3', options=f'-filter:a "volume={volume}"') | 53 | audio_source = discord.FFmpegPCMAudio('tts.mp3', options=f'-filter:a "volume={volume}"') |
| 53 | logger.info("TTS audio played") | 54 | logger.info(f"playing {text}") |
| 54 | voice_client.play(audio_source) | 55 | voice_client.play(audio_source) |
| 55 | # Wait for playback to finish | ||
| 56 | while voice_client.is_playing(): | ||
| 57 | await discord.utils.sleep_until(datetime.datetime.now() + datetime.timedelta(seconds=1)) | ||
| 58 | os.remove('tts.mp3') | 56 | os.remove('tts.mp3') |
| 59 | else: | 57 | else: |
| 60 | await ctx.respond("Nieznany sposób odtwarzania.", ephemeral=True) | 58 | await ctx.respond("Nieznany sposób odtwarzania.", ephemeral=True) |
