using tmpefiles for tts so now we dont step on eachothers memes

This commit is contained in:
Luke Robles 2021-12-16 15:53:21 -08:00
parent c89b76acfc
commit 00ba84d392
2 changed files with 5 additions and 4 deletions

View File

@ -447,15 +447,15 @@ async def tts(ctx):
"Ok {}, check your DMs".format(ctx.message.author.mention) "Ok {}, check your DMs".format(ctx.message.author.mention)
) )
return await ctx.message.author.send(tts.get_all_langs()) return await ctx.message.author.send(tts.get_all_langs())
file_path = tts.text_to_speech(ctx.message.content)
await ctx.send( await ctx.send(
file=discord.File( file=discord.File(
tts.text_to_speech(ctx.message.content), file_path,
filename="A Message From {}.mp3".format(ctx.message.author.name) filename="A Message From {}.mp3".format(ctx.message.author.name)
) )
) )
await ctx.message.delete() await ctx.message.delete()
os.remove('/tmp/memes.mp3') os.remove(file_path)
@bot.command(name='issue') @bot.command(name='issue')
async def issue(ctx): async def issue(ctx):

View File

@ -1,4 +1,5 @@
from gtts import gTTS, lang from gtts import gTTS, lang
import tempfile
def text_to_speech(input): def text_to_speech(input):
""" """
@ -8,7 +9,7 @@ def text_to_speech(input):
that language. eg: what are you doing; ja, will return a file read by a japanese that language. eg: what are you doing; ja, will return a file read by a japanese
robot robot
""" """
file_path = '/tmp/memes.mp3' file, file_path = tempfile.mkstemp()
message = ' '.join(input.split()[1:]) message = ' '.join(input.split()[1:])
language = 'en' language = 'en'