Luke R 8b44daa832
All checks were successful
Build and push / changes (push) Successful in 4s
Build and push / Lint-Python (push) Successful in 2s
Build and push / Build-and-Push-Docker (push) Successful in 3m12s
Build and push / sync-argocd-app (push) Successful in 2s
Build and push / post-failure-to-discord (push) Has been skipped
Build and push / post-success-to-discord (push) Successful in 2s
Adding fstrings and also a message if ollama is off
2025-04-22 12:38:32 -07:00

32 lines
742 B
Python
Executable File

from gtts import gTTS, lang
import tempfile
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
"""
file, file_path = tempfile.mkstemp()
language = "en"
gTTS(text=input, lang=language, slow=False).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 += f"{key}: {value}\n"
return f"```css\n{blob}```"