Add male voice

pull/92/head
Arjun Dureja 3 years ago
parent 5b3989611f
commit c03bd2ae82

@ -2,3 +2,4 @@ REDDIT_CLIENT_ID=""
REDDIT_CLIENT_SECRET=""
REDDIT_USERNAME=""
REDDIT_PASSWORD=""
VOICE="female"

@ -5,6 +5,8 @@ from video_creation.background import download_background, chop_background_video
from video_creation.voices import save_text_to_mp3
from video_creation.screenshot_downloader import download_screenshots_of_reddit_posts
from video_creation.final_video import make_final_video
from dotenv import load_dotenv
import os
print_markdown(
"### Thanks for using this tool! 😊 [Feel free to contribute to this project on GitHub!](https://lewismenelaws.com). If you have any questions, feel free to reach out to me on Twitter or submit a GitHub issue."
@ -15,7 +17,8 @@ time.sleep(3)
reddit_object = get_askreddit_threads()
length, number_of_comments = save_text_to_mp3(reddit_object)
load_dotenv()
length, number_of_comments = save_text_to_mp3(reddit_object, os.getenv("VOICE"))
download_screenshots_of_reddit_posts(reddit_object, number_of_comments)
download_background()
chop_background_video(length)

@ -3,9 +3,10 @@ from pathlib import Path
from mutagen.mp3 import MP3
from utils.console import print_step, print_substep
from rich.progress import track
import requests
def save_text_to_mp3(reddit_obj):
def save_text_to_mp3(reddit_obj, voice):
"""Saves Text to MP3 files.
Args:
@ -17,16 +18,34 @@ def save_text_to_mp3(reddit_obj):
# Create a folder for the mp3 files.
Path("assets/mp3").mkdir(parents=True, exist_ok=True)
if voice == "female":
tts = gTTS(text=reddit_obj["thread_title"], lang="en", slow=False, tld="co.uk")
tts.save(f"assets/mp3/title.mp3")
elif voice == "male":
url = 'https://streamlabs.com/polly/speak'
body = {'voice': 'Brian', 'text': reddit_obj["thread_title"]}
response = requests.post(url, data = body)
voice_data = requests.get(response.json()['speak_url'])
f = open('assets/mp3/title.mp3', 'wb')
f.write(voice_data.content)
length += MP3(f"assets/mp3/title.mp3").info.length
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
if voice == "female":
tts = gTTS(text=comment["comment_body"], lang="en")
tts.save(f"assets/mp3/{idx}.mp3")
elif voice == "male":
body = {'voice': 'Brian', 'text': comment["comment_body"]}
response = requests.post(url, data = body)
voice_data = requests.get(response.json()['speak_url'])
f = open(f"assets/mp3/{idx}.mp3", 'wb')
f.write(voice_data.content)
length += MP3(f"assets/mp3/{idx}.mp3").info.length
print_substep("Saved Text to MP3 files Successfully.", style="bold green")

Loading…
Cancel
Save