From aa5cc242a3518b6efb82364a4d8e95a1c383a267 Mon Sep 17 00:00:00 2001 From: Callum Leslie Date: Mon, 6 Jun 2022 19:02:00 +0100 Subject: [PATCH] Move to new TTS workflow --- video_creation/voices.py | 39 ++++----------------------------------- 1 file changed, 4 insertions(+), 35 deletions(-) diff --git a/video_creation/voices.py b/video_creation/voices.py index c0df8b7..ea8e501 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -1,9 +1,7 @@ -from gtts import gTTS -from pathlib import Path -from mutagen.mp3 import MP3 from utils.console import print_step, print_substep from rich.progress import track - +from tts.engine_wrapper import TTSEngine +import tts.google_translate_tts def save_text_to_mp3(reddit_obj): """Saves Text to MP3 files. @@ -11,34 +9,5 @@ def save_text_to_mp3(reddit_obj): Args: reddit_obj : The reddit object you received from the reddit API in the askreddit.py file. """ - print_step("Saving Text to MP3 files...") - length = 0 - - # Create a folder for the mp3 files. - Path("assets/mp3").mkdir(parents=True, exist_ok=True) - - tts = gTTS(text=reddit_obj["thread_title"], lang="en", slow=False) - 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"] != "": - tts = gTTS(text=reddit_obj["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=comment["comment_body"], lang="en", slow=False) - tts.save(f"assets/mp3/{idx}.mp3") - length += MP3(f"assets/mp3/{idx}.mp3").info.length - - print_substep("Saved Text to MP3 files successfully.", style="bold green") - # ! Return the index so we know how many screenshots of comments we need to make. - return length, idx + text_to_mp3 = TTSEngine(tts.google_translate_tts.run, reddit_obj) + return text_to_mp3.run()