From 2b526d195d39c96c45f869ea704ba7f68b6421be Mon Sep 17 00:00:00 2001 From: Ghostweaver <84856013+rougeplane@users.noreply.github.com> Date: Sat, 11 Jun 2022 07:15:51 +0500 Subject: [PATCH] Update voices.py Added max and min length If The title or post text is greater than max length the program will exit! --- video_creation/voices.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/video_creation/voices.py b/video_creation/voices.py index 4467306..ba1e43a 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -16,6 +16,8 @@ def save_text_to_mp3(reddit_obj): """ print_step("Saving Text to MP3 files...") length = 0 + min_length = 50 # min length of video in seconds, Please note video may be shorter due to lack of comments!! + max_length = 60 # max length of video in seconds skipped_idx = [] # Create a folder for the mp3 files. @@ -34,16 +36,18 @@ def save_text_to_mp3(reddit_obj): tts = gTTS(text=reddit_obj["thread_post"], lang="en", slow=False) tts.save("assets/mp3/posttext.mp3") length += MP3("assets/mp3/posttext.mp3").info.length + + if length > max_length: + print_substep(f"length before adding comments is {length} seconds please increase the max length") + exit() - - max_length_in_seconds = 60 for idx, comment in track(enumerate(reddit_obj["comments"])): #allow user to see what comment is being saved print_substep(f"Saving MP3 {idx + 1} ") # ! 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: + if length > min_length: break comment=comment["comment_body"] text=re.sub('((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z]){2,6}([a-zA-Z0-9\.\&\/\?\:@\-_=#])*', '', comment) @@ -52,7 +56,7 @@ def save_text_to_mp3(reddit_obj): length += MP3(f"assets/mp3/{idx}.mp3").info.length # doesn't allow length to exceed max_length_in_seconds seconds - if length > max_length_in_seconds: + if length > max_length: length -= MP3(f"assets/mp3/{idx}.mp3").info.length skipped_idx.append(idx)