Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the story mode with 2 methods and add min comment lenght #1288

Merged
merged 57 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
e71143d
Add files via upload
electro199 Aug 27, 2022
1bf9b34
Merge branch 'elebumm:master' into master
electro199 Oct 5, 2022
1424b3e
Added the stroy mode with two method and add min comment lenght
electro199 Oct 6, 2022
004d4c2
Merge branch 'develop' into master
electro199 Oct 6, 2022
614cb2f
error solved
electro199 Oct 6, 2022
3f6344a
edited some bug and typo
electro199 Oct 7, 2022
c6f7295
refactor: headless
electro199 Oct 9, 2022
d48d244
feat: themes
electro199 Oct 9, 2022
1d76310
bug: typo
electro199 Oct 9, 2022
2461fc0
FIX:fonts issue,typo
electro199 Oct 11, 2022
d1b3b68
fixed c drive issue
electro199 Oct 11, 2022
764530e
feat:Added AI based sentence processing
electro199 Oct 11, 2022
6de35b3
Feat:added req.txt
electro199 Oct 11, 2022
349bf72
bug: fixed audio collection error
electro199 Oct 14, 2022
234b8d2
Added depency to req.txt
electro199 Oct 24, 2022
8617136
feat:All native image for bot title and posttext | comments , Fonts ,…
electro199 Oct 26, 2022
719ca09
error: solved version check error
electro199 Oct 26, 2022
dabbd04
todo added
electro199 Oct 26, 2022
f0e5138
Fix:(Bug)empty string in story mode
electro199 Nov 12, 2022
437c851
Update video_creation/screenshot_downloader.py
electro199 Nov 12, 2022
1da0c95
error_msg:updated
electro199 Nov 12, 2022
b136816
Update requirements.txt
electro199 Nov 12, 2022
2a5609c
bump:spacy3.4.1 to spacy3.4.2
electro199 Nov 12, 2022
6100430
chores , naming
electro199 Nov 12, 2022
54db3e1
Merge branch 'master' of https://github.com/electro199/RedditVideoMak…
electro199 Nov 12, 2022
67f42f7
removed the beta test message
electro199 Nov 12, 2022
0f3c7d5
reverted for <3.10 compatiblity
electro199 Nov 13, 2022
3f349a9
typo fixed
electro199 Nov 13, 2022
bb83871
bug:typo error
electro199 Nov 14, 2022
e8cadd9
A lot of reformatting and a couple of bug fixes
OpenSourceSimon Nov 20, 2022
201d3ef
Fixed translation for story mode
OpenSourceSimon Nov 23, 2022
3a0b8a7
post url temp.config
electro199 Nov 23, 2022
2cd1596
Merge branch 'master' of https://github.com/electro199/RedditVideoMak…
electro199 Nov 23, 2022
b24925e
Max length
OpenSourceSimon Nov 23, 2022
1d64b5c
Merge branch 'master' of https://github.com/electro199/RedditVideoMak…
electro199 Nov 23, 2022
ec2b596
fixed : no selftext error
electro199 Nov 27, 2022
04e0977
fixed: removed tiktok from default
electro199 Dec 1, 2022
94cffcb
cleaned unnesscary config options
electro199 Dec 1, 2022
a909661
error fix : post id fixed
electro199 Dec 1, 2022
8f83881
version no. update
electro199 Dec 2, 2022
0a2999e
changed unnecessary non-optional voices options
electro199 Dec 2, 2022
7f44a80
better comment view may cause error
electro199 Dec 2, 2022
2043827
better error handling
electro199 Dec 2, 2022
489effa
fixed looping over same postid
electro199 Dec 2, 2022
ee55105
dev time
electro199 Dec 2, 2022
62e5c50
cleared clutter
electro199 Dec 2, 2022
f91bea3
Fixed,added: 0.mp3 not found and only translate
electro199 Dec 9, 2022
96e34c0
added translation with all panctuations
electro199 Dec 9, 2022
08d50cc
refomatting stuff
electro199 Dec 9, 2022
9113579
typo fixed
electro199 Dec 9, 2022
1d18963
better error meesage
electro199 Dec 10, 2022
49eb860
bug(Fixed) : keyerror "vwidth"
electro199 Dec 10, 2022
695aba6
Fix
OpenSourceSimon Dec 19, 2022
b002dd9
Fix
OpenSourceSimon Dec 19, 2022
5e63899
Change back DEFAULT_MAX_LENGTH
OpenSourceSimon Dec 19, 2022
adf31ac
Change version number
OpenSourceSimon Dec 19, 2022
bd57bf2
Merge branch 'develop' into master
OpenSourceSimon Dec 19, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions TTS/TikTok.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,25 @@ def run(self, text, filepath, random_voice: bool = False):
voice = (
self.randomvoice()
if random_voice
else (settings.config["settings"]["tts"]["tiktok_voice"] or random.choice(self.voices["human"]))
else (
settings.config["settings"]["tts"]["tiktok_voice"]
or random.choice(self.voices["human"])
)
)
try:
r = requests.post(f"{self.URI_BASE}{voice}&req_text={text}&speaker_map_type=0")
r = requests.post(
f"{self.URI_BASE}{voice}&req_text={text}&speaker_map_type=0"
)
except requests.exceptions.SSLError:
# https://stackoverflow.com/a/47475019/18516611
session = requests.Session()
retry = Retry(connect=3, backoff_factor=0.5)
adapter = HTTPAdapter(max_retries=retry)
session.mount("http://", adapter)
session.mount("https://", adapter)
r = session.post(f"{self.URI_BASE}{voice}&req_text={text}&speaker_map_type=0")
r = session.post(
f"{self.URI_BASE}{voice}&req_text={text}&speaker_map_type=0"
)
# print(r.text)
vstr = [r.json()["data"]["v_str"]][0]
b64d = base64.b64decode(vstr)
Expand Down
12 changes: 9 additions & 3 deletions TTS/aws_polly.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ def run(self, text, filepath, random_voice: bool = False):
voice = self.randomvoice()
else:
if not settings.config["settings"]["tts"]["aws_polly_voice"]:
raise ValueError(f"Please set the TOML variable AWS_VOICE to a valid voice. options are: {voices}")
voice = str(settings.config["settings"]["tts"]["aws_polly_voice"]).capitalize()
raise ValueError(
f"Please set the TOML variable AWS_VOICE to a valid voice. options are: {voices}"
)
voice = str(
settings.config["settings"]["tts"]["aws_polly_voice"]
).capitalize()
try:
# Request speech synthesis
response = polly.synthesize_speech(Text=text, OutputFormat="mp3", VoiceId=voice, Engine="neural")
response = polly.synthesize_speech(
Text=text, OutputFormat="mp3", VoiceId=voice, Engine="neural"
)
except (BotoCoreError, ClientError) as error:
# The service returned an error, exit gracefully
print(error)
Expand Down
114 changes: 62 additions & 52 deletions TTS/engine_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from utils.console import print_step, print_substep
from utils.voice import sanitize_text

DEFAULT_MAX_LENGTH: int = 50 # video length variable
DEFAULT_MAX_LENGTH: int = 50 # video length variable


class TTSEngine:
Expand All @@ -45,6 +45,7 @@ def __init__(
):
self.tts_module = tts_module()
self.reddit_object = reddit_object

self.redditid = re.sub(r"[^\w\s-]", "", reddit_object["thread_id"])
self.path = path + self.redditid + "/mp3"
self.max_length = max_length
Expand All @@ -54,39 +55,52 @@ def __init__(
def run(self) -> Tuple[int, int]:

Path(self.path).mkdir(parents=True, exist_ok=True)

# This file needs to be removed in case this post does not use post text, so that it won't appear in the final video
try:
Path(f"{self.path}/posttext.mp3").unlink()
except OSError:
pass

print_step("Saving Text to MP3 files...")

self.call_tts("title", process_text(self.reddit_object["thread_title"]))
processed_text = process_text(self.reddit_object["thread_post"])
if processed_text != "" and settings.config["settings"]["storymode"] == True:
self.call_tts("posttext", processed_text)

# processed_text = ##self.reddit_object["thread_post"] != ""
idx = None
for idx, comment in track(enumerate(self.reddit_object["comments"]), "Saving..."):
# ! Stop creating mp3 files if the length is greater than max length.
if self.length > self.max_length:
self.length -= self.last_clip_length
idx -= 1
break
if len(comment["comment_body"]) > self.tts_module.max_chars: # Split the comment if it is too long
self.split_post(comment["comment_body"], idx) # Split the comment
else: # If the comment is not too long, just call the tts engine
self.call_tts(f"{idx}", process_text(comment["comment_body"]))

if settings.config["settings"]["storymode"]:
if settings.config["settings"]["storymodemethod"] == 0:
if len(self.reddit_object["thread_post"]) > self.tts_module.max_chars:
self.split_post(self.reddit_object["thread_post"], "postaudio")
else:
self.call_tts(
"postaudio", process_text(self.reddit_object["thread_post"])
)
elif settings.config["settings"]["storymodemethod"] == 1:

for idx, text in track(enumerate(self.reddit_object["thread_post"])):
self.call_tts(f"postaudio-{idx}", process_text(text))

else:

for idx, comment in track(
enumerate(self.reddit_object["comments"]), "Saving..."
):
# ! Stop creating mp3 files if the length is greater than max length.
if self.length > self.max_length and idx > 1:
self.length -= self.last_clip_length
idx -= 1
break
if (
len(comment["comment_body"]) > self.tts_module.max_chars
): # Split the comment if it is too long
self.split_post(comment["comment_body"], idx) # Split the comment
else: # If the comment is not too long, just call the tts engine
self.call_tts(f"{idx}", process_text(comment["comment_body"]))

print_substep("Saved Text to MP3 files successfully.", style="bold green")
return self.length, idx

def split_post(self, text: str, idx: int):
def split_post(self, text: str, idx):
split_files = []
split_text = [
x.group().strip() for x in re.finditer(r" *(((.|\n){0," + str(self.tts_module.max_chars) + "})(\.|.$))", text)
x.group().strip()
for x in re.finditer(
r" *(((.|\n){0," + str(self.tts_module.max_chars) + "})(\.|.$))", text
)
]
self.create_silence_mp3()

Expand All @@ -100,15 +114,19 @@ def split_post(self, text: str, idx: int):
continue
else:
self.call_tts(f"{idx}-{idy}.part", newtext)
with open(f"{self.path}/list.txt", 'w') as f:
with open(f"{self.path}/list.txt", "w") as f:
for idz in range(0, len(split_text)):
f.write("file " + f"'{idx}-{idz}.part.mp3'" + "\n")
split_files.append(str(f"{self.path}/{idx}-{idy}.part.mp3"))
f.write("file " + f"'silence.mp3'" + "\n")

os.system("ffmpeg -f concat -y -hide_banner -loglevel panic -safe 0 " +
"-i " + f"{self.path}/list.txt " +
"-c copy " + f"{self.path}/{idx}.mp3")
os.system(
"ffmpeg -f concat -y -hide_banner -loglevel panic -safe 0 "
+ "-i "
+ f"{self.path}/list.txt "
+ "-c copy "
+ f"{self.path}/{idx}.mp3"
)
try:
for i in range(0, len(split_files)):
os.unlink(split_files[i])
Expand All @@ -118,43 +136,35 @@ def split_post(self, text: str, idx: int):
print("OSError")

def call_tts(self, filename: str, text: str):

self.tts_module.run(text, filepath=f"{self.path}/{filename}.mp3")
# try:
# self.length += MP3(f"{self.path}/{filename}.mp3").info.length
# except (MutagenError, HeaderNotFoundError):
# self.length += sox.file_info.duration(f"{self.path}/{filename}.mp3")
try:
self.tts_module.run(text, filepath=f"{self.path}/{filename}_no_silence.mp3")
self.create_silence_mp3()

with open(f"{self.path}/{filename}.txt", 'w') as f:
f.write("file " + f"'{filename}_no_silence.mp3'" + "\n")
f.write("file " + f"'silence.mp3'" + "\n")
f.close()
os.system("ffmpeg -f concat -y -hide_banner -loglevel panic -safe 0 " +
"-i " + f"{self.path}/{filename}.txt " +
"-c copy " + f"{self.path}/{filename}.mp3")
clip = AudioFileClip(f"{self.path}/{filename}.mp3")
self.length += clip.duration
self.last_clip_length = clip.duration
self.length += clip.duration
clip.close()
try:
name = [f"{filename}_no_silence.mp3", "silence.mp3", f"{filename}.txt"]
for i in range(0, len(name)):
os.unlink(str(rf"{self.path}/" + name[i]))
except FileNotFoundError as e:
print("File not found: " + e.filename)
except OSError:
print("OSError")
except:
self.length = 0

def create_silence_mp3(self):
silence_duration = settings.config["settings"]["tts"]["silence_duration"]
silence = AudioClip(make_frame=lambda t: np.sin(440 * 2 * np.pi * t), duration=silence_duration, fps=44100)
silence = AudioClip(
make_frame=lambda t: np.sin(440 * 2 * np.pi * t),
duration=silence_duration,
fps=44100,
)
silence = volumex(silence, 0)
silence.write_audiofile(f"{self.path}/silence.mp3", fps=44100, verbose=False, logger=None)
silence.write_audiofile(
f"{self.path}/silence.mp3", fps=44100, verbose=False, logger=None
)


def process_text(text: str):
def process_text(text: str , clean : bool = True):
lang = settings.config["reddit"]["thread"]["post_lang"]
new_text = sanitize_text(text)
new_text = sanitize_text(text) if clean else text
if lang:
print_substep("Translating Text...")
translated_text = ts.google(text, to_language=lang)
Expand Down
8 changes: 6 additions & 2 deletions TTS/pyttsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ def run(
if voice_id == "" or voice_num == "":
voice_id = 2
voice_num = 3
raise ValueError("set pyttsx values to a valid value, switching to defaults")
raise ValueError(
"set pyttsx values to a valid value, switching to defaults"
)
else:
voice_id = int(voice_id)
voice_num = int(voice_num)
Expand All @@ -32,7 +34,9 @@ def run(
voice_id = self.randomvoice()
engine = pyttsx3.init()
voices = engine.getProperty("voices")
engine.setProperty("voice", voices[voice_id].id) # changing index changes voices but ony 0 and 1 are working here
engine.setProperty(
"voice", voices[voice_id].id
) # changing index changes voices but ony 0 and 1 are working here
engine.save_to_file(text, f"{filepath}")
engine.runAndWait()

Expand Down
8 changes: 6 additions & 2 deletions TTS/streamlabs_polly.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ def run(self, text, filepath, random_voice: bool = False):
voice = self.randomvoice()
else:
if not settings.config["settings"]["tts"]["streamlabs_polly_voice"]:
raise ValueError(f"Please set the config variable STREAMLABS_POLLY_VOICE to a valid voice. options are: {voices}")
voice = str(settings.config["settings"]["tts"]["streamlabs_polly_voice"]).capitalize()
raise ValueError(
f"Please set the config variable STREAMLABS_POLLY_VOICE to a valid voice. options are: {voices}"
)
voice = str(
settings.config["settings"]["tts"]["streamlabs_polly_voice"]
).capitalize()
body = {"voice": voice, "text": text, "service": "polly"}
response = requests.post(self.url, data=body)
if not check_ratelimit(response):
Expand Down
Loading