You can probably do more with this than me - I'm new to python. I just preferred a male voice over the old (annoying) female voice!pull/234/head
parent
db1ddce57a
commit
cdb6f85d98
@ -1,34 +1,36 @@
|
||||
from gtts import gTTS
|
||||
import pyttsx3
|
||||
from pathlib import Path
|
||||
from mutagen.mp3 import MP3
|
||||
from mutagen.wave import WAVE
|
||||
from utils.console import print_step, print_substep
|
||||
from rich.progress import track
|
||||
|
||||
|
||||
def save_text_to_mp3(reddit_obj):
|
||||
"""Saves Text to MP3 files.
|
||||
def save_text_to_wav(reddit_obj):
|
||||
"""Saves Text to WAV files.
|
||||
|
||||
Args:
|
||||
reddit_obj : The reddit object you received from the reddit API in the askreddit.py file.
|
||||
"""
|
||||
print_step("Saving Text to MP3 files...")
|
||||
print_step("Saving Text to WAV files...")
|
||||
length = 0
|
||||
|
||||
# Create a folder for the mp3 files.
|
||||
Path("assets/mp3").mkdir(parents=True, exist_ok=True)
|
||||
Path("assets/wav").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 = pyttsx3.init()
|
||||
engine.setProperty("rate", 180)
|
||||
engine.save_to_file(reddit_obj["thread_title"], f"assets/wav/title.wav")
|
||||
engine.runAndWait()
|
||||
length += WAVE(f"assets/wav/title.wav").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
|
||||
# ! Stop creating wav 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(comment["comment_body"], f"assets/wav/{idx}.wav")
|
||||
engine.runAndWait()
|
||||
length += WAVE(f"assets/wav/{idx}.wav").info.length
|
||||
|
||||
print_substep("Saved Text to MP3 files successfully.", style="bold green")
|
||||
print_substep("Saved Text to WAV files successfully.", style="bold green")
|
||||
# ! Return the index so we know how many screenshots of comments we need to make.
|
||||
return length, idx
|
||||
|
Loading…
Reference in new issue