Update voices.py

Added max and min length
If The title or post text is greater than max length the program will exit!
pull/400/head
Ghostweaver 3 years ago committed by GitHub
parent 23b42ac2e9
commit 2b526d195d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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)

Loading…
Cancel
Save