diff options
| author | Samlon <stankiewiczgracjan2019@gmail.com> | 2025-08-13 14:59:22 +0200 |
|---|---|---|
| committer | Samlon <stankiewiczgracjan2019@gmail.com> | 2025-08-13 14:59:22 +0200 |
| commit | 8d0a52ab34563beab33be2dfb207da0e03a8fe32 (patch) | |
| tree | 6d670fe2985259c9c2a69ce80f1b8a0bd1d16d6c /cogs/tts.py | |
| parent | prevent discord from complaining (diff) | |
| download | senator-sperma-8d0a52ab34563beab33be2dfb207da0e03a8fe32.tar.gz senator-sperma-8d0a52ab34563beab33be2dfb207da0e03a8fe32.zip | |
prevent discord from complaining and bot does not leave vc after playing
Diffstat (limited to 'cogs/tts.py')
| -rw-r--r-- | cogs/tts.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/cogs/tts.py b/cogs/tts.py index c00259f..7461a1f 100644 --- a/cogs/tts.py +++ b/cogs/tts.py | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | import datetime | 1 | import datetime |
| 2 | import os | 2 | import os |
| 3 | 3 | import json | |
| 4 | import discord | 4 | import discord |
| 5 | from discord.ext import commands | 5 | from discord.ext import commands |
| 6 | from gtts import gTTS | 6 | from gtts import gTTS |
| @@ -20,6 +20,13 @@ class TTS(commands.Cog): | |||
| 20 | tts = gTTS(text=text, lang='pl') | 20 | tts = gTTS(text=text, lang='pl') |
| 21 | tts.save('tts.mp3') | 21 | tts.save('tts.mp3') |
| 22 | 22 | ||
| 23 | if os.path.exists('settings.json'): | ||
| 24 | with open('settings.json') as f: | ||
| 25 | data = json.load(f) | ||
| 26 | volume = data['volume'] | ||
| 27 | else: | ||
| 28 | logger.error("settings.json not found") | ||
| 29 | |||
| 23 | if output == "file": | 30 | if output == "file": |
| 24 | await ctx.respond(file=discord.File('tts.mp3')) | 31 | await ctx.respond(file=discord.File('tts.mp3')) |
| 25 | logger.info("TTS file sent") | 32 | logger.info("TTS file sent") |
| @@ -42,7 +49,7 @@ class TTS(commands.Cog): | |||
| 42 | await voice_client.move_to(channel) | 49 | await voice_client.move_to(channel) |
| 43 | # Play the TTS audio | 50 | # Play the TTS audio |
| 44 | if not voice_client.is_playing(): | 51 | if not voice_client.is_playing(): |
| 45 | audio_source = discord.FFmpegPCMAudio('tts.mp3', options='-filter:a "volume=6"') | 52 | audio_source = discord.FFmpegPCMAudio('tts.mp3', options=f'-filter:a "volume={volume}"') |
| 46 | logger.info("TTS audio played") | 53 | logger.info("TTS audio played") |
| 47 | voice_client.play(audio_source) | 54 | voice_client.play(audio_source) |
| 48 | # Wait for playback to finish | 55 | # Wait for playback to finish |
| @@ -55,5 +62,4 @@ class TTS(commands.Cog): | |||
| 55 | os.remove('tts.mp3') | 62 | os.remove('tts.mp3') |
| 56 | 63 | ||
| 57 | def setup(bot): | 64 | def setup(bot): |
| 58 | bot.add_cog(TTS(bot)) | 65 | bot.add_cog(TTS(bot)) \ No newline at end of file |
| 59 | 1 \ No newline at end of file | ||
