diff --git a/.gitignore b/.gitignore index b541305..95aa7c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ assets/ .env reddit-bot-351418-5560ebc49cac.json -__pycache__ \ No newline at end of file +__pycache__ +venv \ No newline at end of file diff --git a/.env.template b/env.template similarity index 57% rename from .env.template rename to env.template index f00c2ac..9f14b65 100644 --- a/.env.template +++ b/env.template @@ -6,5 +6,10 @@ REDDIT_PASSWORD="" # Valid options are "yes" and "no" for the variable below REDDIT_2FA="" +THEME="" +# Enter a subreddit, e.g. "AskReddit" SUBREDDIT="" + +Valid options are "male" and "female" for the variable below +VoiceGender="" diff --git a/reddit/subreddit.py b/reddit/subreddit.py index 5d020fe..ed83b91 100644 --- a/reddit/subreddit.py +++ b/reddit/subreddit.py @@ -12,8 +12,8 @@ def get_subreddit_threads(): """ load_dotenv() - - print_step("Getting AskReddit threads...") + _SUBREDDIT = os.getenv("SUBREDDIT") + print_step(f"Getting {_SUBREDDIT} threads...") if os.getenv("REDDIT_2FA").lower() == "yes": print( diff --git a/requirements.txt b/requirements.txt index 59dc596..eb5b22e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,44 +1,8 @@ -appdirs==1.4.4 -black==20.8b1 -certifi==2021.10.8 -charset-normalizer==2.0.12 -click==7.1.2 -commonmark==0.9.1 -decorator==4.4.2 -flake8==3.8.3 -greenlet==1.1.2 -gTTS==2.2.4 -idna==3.3 -imageio==2.19.2 -imageio-ffmpeg==0.4.7 -mccabe==0.6.1 +librosa==0.9.1 moviepy==1.0.3 -mutagen==1.45.1 -mypy-extensions==0.4.3 -numpy==1.22.3 -pathspec==0.8.0 -Pillow==9.1.1 playwright==1.22.0 praw==7.6.0 -prawcore==2.3.0 -proglog==0.1.10 -pycodestyle==2.6.0 -pyee==8.1.0 -pyflakes==2.2.0 -Pygments==2.12.0 python-dotenv==0.20.0 - -regex==2020.10.15 - -requests==2.27.1 +pyttsx3==2.90 rich==12.4.4 -six==1.16.0 -toml==0.10.1 -tqdm==4.64.0 -typed-ast==1.5.4 -typing_extensions==4.2.0 -update-checker==0.18.0 -urllib3==1.26.9 -websocket-client==1.3.2 -websockets==10.1 -yt-dlp==2022.5.18 \ No newline at end of file +yt_dlp==2022.5.18 diff --git a/video_creation/voices.py b/video_creation/voices.py index e8d8e43..180293d 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -1,8 +1,14 @@ -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 +import pyttsx3 +from dotenv import load_dotenv +import os +import librosa + +load_dotenv() + +VoiceGender = os.getenv('VoiceGender') def save_text_to_mp3(reddit_obj): @@ -14,21 +20,36 @@ def save_text_to_mp3(reddit_obj): print_step("Saving Text to MP3 files...") length = 0 + # create the object + engine = pyttsx3.init() + voices = engine.getProperty('voices') + engine.setProperty('volume', 1.0) + + # Set the voice depending on what was set in .env + if VoiceGender == 'male': + engine.setProperty('voice', voices[0].id) + elif VoiceGender == 'female': + engine.setProperty('voice', voices[1].id) + # if nothing set default to female voice + else: + engine.setProperty('voice', voices[1].id) + + # 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 + engine.save_to_file(str(reddit_obj["thread_title"]), "./assets/mp3/title.mp3") + engine.runAndWait() + length += librosa.get_duration(filename='./assets/mp3/title.mp3') 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 + engine.save_to_file(str(comment["comment_body"]), f"./assets/mp3/{idx}.mp3") + engine.runAndWait() + length += librosa.get_duration(filename=f'./assets/mp3/{idx}.mp3') 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