aboutsummaryrefslogtreecommitdiffstats
path: root/cogs/tts.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--cogs/tts.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/cogs/tts.py b/cogs/tts.py
index 41dc366..2481ab3 100644
--- a/cogs/tts.py
+++ b/cogs/tts.py
@@ -1,8 +1,10 @@
1import datetime
2import os
3
1import discord 4import discord
2from discord.ext import commands 5from discord.ext import commands
3from gtts import gTTS 6from gtts import gTTS
4import os 7
5import datetime
6 8
7class TTS(commands.Cog): 9class TTS(commands.Cog):
8 def __init__(self, bot): 10 def __init__(self, bot):
@@ -10,22 +12,22 @@ class TTS(commands.Cog):
10 12
11 @commands.slash_command(name="tts", description="Generuje TTS dla danego tekstu") 13 @commands.slash_command(name="tts", description="Generuje TTS dla danego tekstu")
12 async def tts(self, ctx, 14 async def tts(self, ctx,
13 text: str = discord.Option(str, "Tekst do przeczytania", required=True), 15 text: str = discord.Option(str, "Tekst do przeczytania", required=True),
14 output: str = discord.Option(str, "Wybierz sposób odtwarzania", choices=["file", "vc"], required=True) 16 output: str = discord.Option(str, "Wybierz sposób odtwarzania", choices=["file", "vc"], required=True)
15 ): 17 ):
16 tts = gTTS(text=text, lang='pl') 18 tts = gTTS(text=text, lang='pl')
17 tts.save('tts.mp3') 19 tts.save('tts.mp3')
18 if output == "file": 20 if output == "file":
19 await ctx.respond(file=discord.File('tts.mp3')) 21 await ctx.respond(file=discord.File('tts.mp3'))
20 os.remove('tts.mp3') 22 os.remove('tts.mp3')
21 elif output == "vc": 23 elif output == "vc":
22 # Check if user is in a voice channel 24 # Check if the user is in a voice channel
23 if not (ctx.author.voice and ctx.author.voice.channel): 25 if not (ctx.author.voice and ctx.author.voice.channel):
24 await ctx.respond("Musisz być na kanale głosowym, aby odtworzyć TTS!", ephemeral=True) 26 await ctx.respond("Musisz być na kanale głosowym, aby odtworzyć TTS!", ephemeral=True)
25 os.remove('tts.mp3') 27 os.remove('tts.mp3')
26 return 28 return
27 channel = ctx.author.voice.channel 29 channel = ctx.author.voice.channel
28 # Connect to voice channel if not already connected 30 # Connect to the voice channel if not already connected
29 voice_client = discord.utils.get(self.bot.voice_clients, guild=channel.guild) 31 voice_client = discord.utils.get(self.bot.voice_clients, guild=channel.guild)
30 if not voice_client or not voice_client.is_connected(): 32 if not voice_client or not voice_client.is_connected():
31 voice_client = await channel.connect() 33 voice_client = await channel.connect()
@@ -43,5 +45,6 @@ class TTS(commands.Cog):
43 await ctx.respond("Nieznany sposób odtwarzania.", ephemeral=True) 45 await ctx.respond("Nieznany sposób odtwarzania.", ephemeral=True)
44 os.remove('tts.mp3') 46 os.remove('tts.mp3')
45 47
48
46def setup(bot): 49def setup(bot):
47 bot.add_cog(TTS(bot)) \ No newline at end of file 50 bot.add_cog(TTS(bot))