|
|
@ -4,6 +4,7 @@ from typing import Tuple
|
|
|
|
import re
|
|
|
|
import re
|
|
|
|
from os import getenv
|
|
|
|
from os import getenv
|
|
|
|
from mutagen.mp3 import MP3
|
|
|
|
from mutagen.mp3 import MP3
|
|
|
|
|
|
|
|
import translators as ts
|
|
|
|
from rich.progress import track
|
|
|
|
from rich.progress import track
|
|
|
|
from moviepy.editor import AudioFileClip, CompositeAudioClip, concatenate_audioclips
|
|
|
|
from moviepy.editor import AudioFileClip, CompositeAudioClip, concatenate_audioclips
|
|
|
|
from utils.console import print_step, print_substep
|
|
|
|
from utils.console import print_step, print_substep
|
|
|
@ -54,7 +55,7 @@ class TTSEngine:
|
|
|
|
self.reddit_object["thread_post"] != ""
|
|
|
|
self.reddit_object["thread_post"] != ""
|
|
|
|
and getenv("STORYMODE", "").casefold() == "true"
|
|
|
|
and getenv("STORYMODE", "").casefold() == "true"
|
|
|
|
):
|
|
|
|
):
|
|
|
|
self.call_tts("posttext", sanitize_text(self.reddit_object["thread_post"]))
|
|
|
|
self.call_tts("posttext", self.reddit_object["thread_post"])
|
|
|
|
|
|
|
|
|
|
|
|
idx = None
|
|
|
|
idx = None
|
|
|
|
for idx, comment in track(
|
|
|
|
for idx, comment in track(
|
|
|
@ -64,9 +65,9 @@ class TTSEngine:
|
|
|
|
if self.length > self.max_length:
|
|
|
|
if self.length > self.max_length:
|
|
|
|
break
|
|
|
|
break
|
|
|
|
if not self.tts_module.max_chars:
|
|
|
|
if not self.tts_module.max_chars:
|
|
|
|
self.call_tts(f"{idx}", sanitize_text(comment["comment_body"]))
|
|
|
|
self.call_tts(f"{idx}", comment["comment_body"])
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
self.split_post(sanitize_text(comment["comment_body"]), idx)
|
|
|
|
self.split_post(comment["comment_body"], idx)
|
|
|
|
|
|
|
|
|
|
|
|
print_substep("Saved Text to MP3 files successfully.", style="bold green")
|
|
|
|
print_substep("Saved Text to MP3 files successfully.", style="bold green")
|
|
|
|
return self.length, idx
|
|
|
|
return self.length, idx
|
|
|
@ -94,5 +95,16 @@ class TTSEngine:
|
|
|
|
Path(f"{self.path}/{idx}-{i}.part.mp3").unlink()
|
|
|
|
Path(f"{self.path}/{idx}-{i}.part.mp3").unlink()
|
|
|
|
|
|
|
|
|
|
|
|
def call_tts(self, filename: str, text: str):
|
|
|
|
def call_tts(self, filename: str, text: str):
|
|
|
|
self.tts_module.run(text=text, filepath=f"{self.path}/{filename}.mp3")
|
|
|
|
self.tts_module.run(
|
|
|
|
|
|
|
|
text=process_text(text), filepath=f"{self.path}/{filename}.mp3"
|
|
|
|
|
|
|
|
)
|
|
|
|
self.length += MP3(f"{self.path}/{filename}.mp3").info.length
|
|
|
|
self.length += MP3(f"{self.path}/{filename}.mp3").info.length
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def process_text(text: str):
|
|
|
|
|
|
|
|
lang = getenv("POSTLANG", "")
|
|
|
|
|
|
|
|
new_text = sanitize_text(text)
|
|
|
|
|
|
|
|
if lang:
|
|
|
|
|
|
|
|
print_substep("Translating Text...")
|
|
|
|
|
|
|
|
new_text = ts.google(text, to_language=lang)
|
|
|
|
|
|
|
|
return new_text
|
|
|
|