adding support for multiple lanagues in tts
This commit is contained in:
parent
0289483038
commit
f414c3a0b3
@ -7,7 +7,6 @@ then imported into the main bot
|
||||
|
||||
import os
|
||||
import requests
|
||||
from gtts import gTTS
|
||||
|
||||
import core_utils
|
||||
import decide
|
||||
@ -24,6 +23,7 @@ import questions
|
||||
import role_check
|
||||
import set_avatar
|
||||
import stock
|
||||
import tts
|
||||
import wallpaper
|
||||
import weather
|
||||
|
||||
@ -313,19 +313,11 @@ async def on_message(message):
|
||||
)
|
||||
|
||||
if message.content.startswith('!tts'):
|
||||
myobj = gTTS(
|
||||
text=' '.join(message.content.split()[1:]),
|
||||
lang='en',
|
||||
slow=False
|
||||
)
|
||||
file_path = '/tmp/memes.mp3'
|
||||
myobj.save(file_path)
|
||||
|
||||
await client.send_file(
|
||||
message.channel,
|
||||
file_path,
|
||||
tts.text_to_speech(message.content),
|
||||
)
|
||||
os.remove(file_path)
|
||||
os.remove('/tmp/memes.mp3')
|
||||
|
||||
if message.content.startswith('!wallpaper'):
|
||||
await client.send_message(
|
||||
|
30
app/tts.py
Normal file
30
app/tts.py
Normal file
@ -0,0 +1,30 @@
|
||||
from gtts import gTTS
|
||||
|
||||
def text_to_speech(input):
|
||||
"""
|
||||
text_to_speech(input)
|
||||
receives the message from discord and returns an MP3 of it.
|
||||
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#supported-languages
|
||||
"""
|
||||
file_path = '/tmp/memes.mp3'
|
||||
message = ' '.join(input.split()[1:])
|
||||
|
||||
language = 'en'
|
||||
# check for another language denoted at the end of the message
|
||||
if ';' in message:
|
||||
print(message.split(';'))
|
||||
language = message.split(';')[1].strip()
|
||||
message = message.split(';')[0]
|
||||
|
||||
gTTS(
|
||||
text=message,
|
||||
lang=language,
|
||||
slow=False
|
||||
).save(file_path)
|
||||
|
||||
return file_path
|
Loading…
x
Reference in New Issue
Block a user