From e899211ee81edf8ca3560a9b93cbf7f81455f6c5 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Wed, 27 Jun 2018 11:45:20 -0700 Subject: [PATCH] Add method to print out all the languages supported by tts --- app/dragon-bot.py | 5 +++++ app/help_methods.py | 3 ++- app/tts.py | 16 +++++++++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/dragon-bot.py b/app/dragon-bot.py index 284aef57..2860239b 100644 --- a/app/dragon-bot.py +++ b/app/dragon-bot.py @@ -344,6 +344,11 @@ async def on_message(message): ) if message.content.startswith('!tts'): + if message.content.split()[1] == 'langs': + return await client.send_message( + message.channel, + tts.get_all_langs() + ) await client.send_file( message.channel, tts.text_to_speech(message.content), diff --git a/app/help_methods.py b/app/help_methods.py index 0f419223..7ef42546 100644 --- a/app/help_methods.py +++ b/app/help_methods.py @@ -114,7 +114,8 @@ def get_help_message(method): ], 'tts': [ 'Uploads a file with the specified text as an MP3.\nThis is advanced shitposting', - '\nUsage: !tts who watches the watchmen?' + '\nUsage: !tts who watches the watchmen?', + '\nTo list all languages, you can type `!tts langs`' ], } diff --git a/app/tts.py b/app/tts.py index fe053e0e..75045220 100644 --- a/app/tts.py +++ b/app/tts.py @@ -1,4 +1,5 @@ from gtts import gTTS +from gtts import lang def text_to_speech(input): """ @@ -7,9 +8,6 @@ def text_to_speech(input): If you pass in a language after a semicolon, it will return it read in that language. eg: what are you doing; ja, will return a file read by a japanese robot - - List of supported languages here: - https://github.com/pndurette/gTTS/tree/050377d2424b137cfb084a37fc1ec9b0d07bfee1#supported-languages """ file_path = '/tmp/memes.mp3' message = ' '.join(input.split()[1:]) @@ -28,3 +26,15 @@ def text_to_speech(input): ).save(file_path) return file_path + +def get_all_langs(): + """ + get_all_langs() + + returns a dictionary with all supported languages + """ + blob = "" + for key, value in lang.tts_langs().items(): + blob += "{}: {}\n".format(key, value) + + return "```css\n{}```".format(blob)