From 3aedbdac86fde9ee86f3509033c1d8f83d4f86c1 Mon Sep 17 00:00:00 2001 From: zechs Date: Mon, 6 Jun 2022 14:23:05 +0530 Subject: [PATCH] Fix: removed code. Working on a different version of the repo accidentally removed new code. --- video_creation/voices.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/video_creation/voices.py b/video_creation/voices.py index ea2d790..c29187e 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -45,11 +45,23 @@ def save_text_to_mp3(reddit_obj): tts.save(f"assets/mp3/title.mp3") length += MP3(f"assets/mp3/title.mp3").info.length + try: + Path(f"assets/mp3/posttext.mp3").unlink() + except OSError as e: + pass + + if reddit_obj["thread_post"] != "": + thread_post = sanitize_text(reddit_obj["thread_post"]) + tts = gTTS(text=thread_post, lang="en", slow=False) + tts.save(f"assets/mp3/posttext.mp3") + length += MP3(f"assets/mp3/posttext.mp3").info.length + for idx, comment in track(enumerate(reddit_obj["comments"]), "Saving..."): # ! Stop creating mp3 files if the length is greater than 50 seconds. This can be longer, but this is just a good starting point if length > 50: break - tts = gTTS(text=sanitize_text(comment["comment_body"]), lang="en", slow=False) + comment = sanitize_text(comment["comment_body"]) + tts = gTTS(text=comment, lang="en", slow=False) tts.save(f"assets/mp3/{idx}.mp3") length += MP3(f"assets/mp3/{idx}.mp3").info.length