Revert "Add Option for Male Voice"

pull/316/head
Lewis Menelaws 3 years ago committed by GitHub
parent 80f453182a
commit 42f364d622
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,10 +2,7 @@ REDDIT_CLIENT_ID=""
REDDIT_CLIENT_SECRET="" REDDIT_CLIENT_SECRET=""
REDDIT_USERNAME="" REDDIT_USERNAME=""
REDDIT_PASSWORD="" REDDIT_PASSWORD=""
# Valid options are "female" and "male" # Valid options are "yes" and "no"
VOICE="female"
# Valid options are "yes" and "no" for the variable below
REDDIT_2FA="" REDDIT_2FA=""
# Valid options are "light" and "dark" # Valid options are "light" and "dark"

@ -35,8 +35,8 @@ except:
configured = False configured = False
if configured: if configured:
reddit_object = get_subreddit_threads(os.getenv("VOICE")) reddit_object = get_subreddit_threads()
length, number_of_comments = save_text_to_mp3(reddit_object, os.getenv("VOICE")) length, number_of_comments = save_text_to_mp3(reddit_object)
download_screenshots_of_reddit_posts(reddit_object, number_of_comments, os.getenv("THEME", "light")) download_screenshots_of_reddit_posts(reddit_object, number_of_comments, os.getenv("THEME", "light"))
download_background() download_background()
chop_background_video(length) chop_background_video(length)

@ -2,7 +2,7 @@ from utils.console import print_markdown, print_step, print_substep
from dotenv import load_dotenv from dotenv import load_dotenv
import os, random, praw, re import os, random, praw, re
def get_subreddit_threads(voice): def get_subreddit_threads():
global submission global submission
""" """
Returns a list of threads from the AskReddit subreddit. Returns a list of threads from the AskReddit subreddit.
@ -55,16 +55,14 @@ def get_subreddit_threads(voice):
content["comments"] = [] content["comments"] = []
for top_level_comment in submission.comments: for top_level_comment in submission.comments:
if voice == "male" and len(top_level_comment.body) > 550: if not top_level_comment.stickied:
continue content["comments"].append(
if not top_level_comment.stickied: {
content["comments"].append( "comment_body": top_level_comment.body,
{ "comment_url": top_level_comment.permalink,
"comment_body": top_level_comment.body, "comment_id": top_level_comment.id,
"comment_url": top_level_comment.permalink, }
"comment_id": top_level_comment.id, )
}
)
except AttributeError as e: except AttributeError as e:
pass pass

@ -3,10 +3,9 @@ from pathlib import Path
from mutagen.mp3 import MP3 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 requests
def save_text_to_mp3(reddit_obj, voice): def save_text_to_mp3(reddit_obj):
"""Saves Text to MP3 files. """Saves Text to MP3 files.
Args: Args:
@ -18,29 +17,18 @@ def save_text_to_mp3(reddit_obj, voice):
# 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)
generate_and_save_tts(voice, reddit_obj["thread_title"], "assets/mp3/title.mp3") 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 length += MP3(f"assets/mp3/title.mp3").info.length
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)
generate_and_save_tts(voice, comment["comment_body"], f"assets/mp3/{idx}.mp3") tts.save(f"assets/mp3/{idx}.mp3")
length += MP3(f"assets/mp3/{idx}.mp3").info.length length += MP3(f"assets/mp3/{idx}.mp3").info.length
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.
return length, idx return length, idx
def generate_and_save_tts(voice, text, file_name):
if voice == "female":
tts = gTTS(text=text, lang="en")
tts.save(file_name)
elif voice == "male":
url = 'https://streamlabs.com/polly/speak'
body = {'voice': 'Brian', 'text': text}
response = requests.post(url, data = body)
voice_data = requests.get(response.json()['speak_url'])
f = open(file_name, 'wb')
f.write(voice_data.content)
Loading…
Cancel
Save