|
|
@ -1,11 +1,11 @@
|
|
|
|
from gtts import gTTS
|
|
|
|
# from gtts import gTTS
|
|
|
|
|
|
|
|
import pyttsx3
|
|
|
|
from pathlib import Path
|
|
|
|
from pathlib import Path
|
|
|
|
from mutagen.mp3 import MP3
|
|
|
|
|
|
|
|
from utils.console import print_step, print_substep
|
|
|
|
from utils.console import print_step, print_substep
|
|
|
|
from rich.progress import track
|
|
|
|
from rich.progress import track
|
|
|
|
|
|
|
|
import audioread
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def save_text_to_mp3(reddit_obj, voices, selected_voice):
|
|
|
|
def save_text_to_mp3(reddit_obj):
|
|
|
|
|
|
|
|
"""Saves Text to MP3 files.
|
|
|
|
"""Saves Text to MP3 files.
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
Args:
|
|
|
@ -14,12 +14,22 @@ def save_text_to_mp3(reddit_obj):
|
|
|
|
print_step("Saving Text to MP3 files...")
|
|
|
|
print_step("Saving Text to MP3 files...")
|
|
|
|
length = 0
|
|
|
|
length = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not selected_voice:
|
|
|
|
|
|
|
|
selected_voice = 0
|
|
|
|
|
|
|
|
|
|
|
|
# Create a folder for the mp3 files.
|
|
|
|
# Create a folder for the mp3 files.
|
|
|
|
Path("assets/mp3").mkdir(parents=True, exist_ok=True)
|
|
|
|
Path("assets/mp3").mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
|
tts = gTTS(text=reddit_obj["thread_title"], lang="en", slow=False)
|
|
|
|
# tts = gTTS(text=reddit_obj["thread_title"], lang="en", slow=False)
|
|
|
|
tts.save(f"assets/mp3/title.mp3")
|
|
|
|
# tts.save(f"assets/mp3/title.mp3")
|
|
|
|
length += MP3(f"assets/mp3/title.mp3").info.length
|
|
|
|
engine = pyttsx3.init()
|
|
|
|
|
|
|
|
engine.setProperty("rate", 180)
|
|
|
|
|
|
|
|
engine.setProperty("voice", voices[selected_voice].id)
|
|
|
|
|
|
|
|
engine.save_to_file(reddit_obj["thread_title"], f"assets/mp3/title.mp3")
|
|
|
|
|
|
|
|
engine.runAndWait()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# length += MP3(f"assets/mp3/title.mp3").info.length
|
|
|
|
|
|
|
|
length += audioread.audio_open(f"assets/mp3/title.mp3").duration
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
Path(f"assets/mp3/posttext.mp3").unlink()
|
|
|
|
Path(f"assets/mp3/posttext.mp3").unlink()
|
|
|
@ -27,17 +37,32 @@ def save_text_to_mp3(reddit_obj):
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
if reddit_obj["thread_post"] != "":
|
|
|
|
if reddit_obj["thread_post"] != "":
|
|
|
|
tts = gTTS(text=reddit_obj["thread_post"], lang="en", slow=False)
|
|
|
|
# tts = gTTS(text=reddit_obj["thread_post"], lang="en", slow=False)
|
|
|
|
tts.save(f"assets/mp3/posttext.mp3")
|
|
|
|
# tts.save(f"assets/mp3/posttext.mp3")
|
|
|
|
length += MP3(f"assets/mp3/posttext.mp3").info.length
|
|
|
|
engine = pyttsx3.init()
|
|
|
|
|
|
|
|
engine.setProperty("rate", 180)
|
|
|
|
|
|
|
|
engine.setProperty("voice", voices[selected_voice].id)
|
|
|
|
|
|
|
|
engine.save_to_file(reddit_obj["thread_post"], f"assets/mp3/posttext.mp3")
|
|
|
|
|
|
|
|
engine.runAndWait()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# length += MP3(f"assets/mp3/posttext.mp3").info.length
|
|
|
|
|
|
|
|
length += audioread.audio_open(f"assets/mp3/posttext.mp3").duration
|
|
|
|
|
|
|
|
|
|
|
|
for idx, comment in track(enumerate(reddit_obj["comments"]), "Saving..."):
|
|
|
|
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
|
|
|
|
# ! 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 > 50:
|
|
|
|
break
|
|
|
|
break
|
|
|
|
tts = gTTS(text=comment["comment_body"], lang="en", slow=False)
|
|
|
|
# tts = gTTS(text=comment["comment_body"], lang="en", slow=False)
|
|
|
|
tts.save(f"assets/mp3/{idx}.mp3")
|
|
|
|
# tts.save(f"assets/mp3/{idx}.mp3")
|
|
|
|
length += MP3(f"assets/mp3/{idx}.mp3").info.length
|
|
|
|
engine = pyttsx3.init()
|
|
|
|
|
|
|
|
engine.setProperty("rate", 180)
|
|
|
|
|
|
|
|
engine.setProperty("voice", voices[selected_voice].id)
|
|
|
|
|
|
|
|
engine.save_to_file(comment["comment_body"], f"assets/mp3/{idx}.mp3")
|
|
|
|
|
|
|
|
engine.runAndWait()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# length += MP3(f"assets/mp3/{idx}.mp3").info.length
|
|
|
|
|
|
|
|
length += audioread.audio_open(f"assets/mp3/{idx}.mp3").duration
|
|
|
|
|
|
|
|
|
|
|
|
print_substep("Saved Text to MP3 files successfully.", style="bold green")
|
|
|
|
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 the index so we know how many screenshots of comments we need to make.
|
|
|
|