removed pyglet because playsound appears to work just fine
added documentation to several functions in tty.py
This commit is contained in:
parent
f02bb4d3ee
commit
68674de54e
@ -5,5 +5,4 @@ SQLAlchemy
|
|||||||
pandas
|
pandas
|
||||||
numpy
|
numpy
|
||||||
gTTS
|
gTTS
|
||||||
playsound
|
playsound
|
||||||
pyglet
|
|
||||||
18
tts.py
18
tts.py
@ -16,6 +16,11 @@ def tts(inputText: str, *args):
|
|||||||
|
|
||||||
|
|
||||||
def create_speech_gtts(input_text: str):
|
def create_speech_gtts(input_text: str):
|
||||||
|
"""
|
||||||
|
Will create a sound file for the provided text by using gTTS
|
||||||
|
:param input_text: any reasonable english text
|
||||||
|
:return: returns the path of the file for the sound
|
||||||
|
"""
|
||||||
path = os.path.join(get_tts_dir(), create_file_name(input_text, "mp3"))
|
path = os.path.join(get_tts_dir(), create_file_name(input_text, "mp3"))
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
sound_digest = gTTS(text=input_text, lang='en')
|
sound_digest = gTTS(text=input_text, lang='en')
|
||||||
@ -24,6 +29,11 @@ def create_speech_gtts(input_text: str):
|
|||||||
|
|
||||||
|
|
||||||
def create_speech_streamlabs(text: str):
|
def create_speech_streamlabs(text: str):
|
||||||
|
"""
|
||||||
|
Will create a sound file for the provided text by querying and downloading a file from streamlabs
|
||||||
|
:param text: any reasonable english text
|
||||||
|
:return: returns the path of the file for the sound
|
||||||
|
"""
|
||||||
path = os.path.join(get_tts_dir(), create_file_name(text, "ogg"))
|
path = os.path.join(get_tts_dir(), create_file_name(text, "ogg"))
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
body = {"voice": config.streamlabsVoice.value, "text": text}
|
body = {"voice": config.streamlabsVoice.value, "text": text}
|
||||||
@ -44,6 +54,12 @@ speechCreationFunctions = { # this is a mapping of the Speaker enum to function
|
|||||||
|
|
||||||
|
|
||||||
def create_speech_file(text: str):
|
def create_speech_file(text: str):
|
||||||
|
"""
|
||||||
|
Helper function that will create a sound file for the provided text. This will use the configuration in config.py
|
||||||
|
to use TTS engines and name the file
|
||||||
|
:param text: the text you would like to turn into a sound file
|
||||||
|
:return: returns the path of the sound file
|
||||||
|
"""
|
||||||
text_creation_function = speechCreationFunctions.get(config.currentSpeaker)
|
text_creation_function = speechCreationFunctions.get(config.currentSpeaker)
|
||||||
output_path = text_creation_function(text)
|
output_path = text_creation_function(text)
|
||||||
return output_path
|
return output_path
|
||||||
@ -60,7 +76,7 @@ def create_file_name(text: str, ext: str):
|
|||||||
unique_id = hashlib.md5(bytes(text, 'utf-8')).hexdigest()
|
unique_id = hashlib.md5(bytes(text, 'utf-8')).hexdigest()
|
||||||
return "%s_tts.%s" % (unique_id, ext)
|
return "%s_tts.%s" % (unique_id, ext)
|
||||||
|
|
||||||
elif config.fileNameStrategy == config.FileNameStrategy.CONTENT_BASED:
|
elif config.fileNameStrategy == config.FileNameStrategy.TIME_BASED:
|
||||||
time = datetime.datetime.now()
|
time = datetime.datetime.now()
|
||||||
return "%s_tts.%s" % (time.strftime("%m-%d-%Y_%H-%M-%S"), ext)
|
return "%s_tts.%s" % (time.strftime("%m-%d-%Y_%H-%M-%S"), ext)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user