From 68674de54eda8fe773aacf6923ffe6e493ec7061 Mon Sep 17 00:00:00 2001 From: dtookey Date: Sun, 20 Sep 2020 13:51:14 -0400 Subject: [PATCH] removed pyglet because playsound appears to work just fine added documentation to several functions in tty.py --- requirements.txt | 3 +-- tts.py | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 0e8c8c3..d052841 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,5 +5,4 @@ SQLAlchemy pandas numpy gTTS -playsound -pyglet \ No newline at end of file +playsound \ No newline at end of file diff --git a/tts.py b/tts.py index b4d3bf5..3223b76 100644 --- a/tts.py +++ b/tts.py @@ -16,6 +16,11 @@ def tts(inputText: str, *args): 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")) if not os.path.exists(path): 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): + """ + 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")) if not os.path.exists(path): 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): + """ + 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) output_path = text_creation_function(text) return output_path @@ -60,7 +76,7 @@ def create_file_name(text: str, ext: str): unique_id = hashlib.md5(bytes(text, 'utf-8')).hexdigest() 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() return "%s_tts.%s" % (time.strftime("%m-%d-%Y_%H-%M-%S"), ext)