reworked the tts system

pull/520/head
Jason 2 years ago
parent b8c6ae2dc1
commit dcb42a4939

@ -0,0 +1,7 @@
from gtts import gTTS
class GTTS:
def tts(self, req_text: str = "Google Text To Speech", filename: str = "title.mp3", random_speaker=False, censer=False):
tts = gTTS(text=req_text, lang="en", slow=False)
tts.save(f"{filename}")

@ -65,7 +65,7 @@ noneng = [
# 'ok': ['en_au_002', 'en_uk_001']} # less en_us_stormtrooper more less en_us_rocket en_us_ghostface # 'ok': ['en_au_002', 'en_uk_001']} # less en_us_stormtrooper more less en_us_rocket en_us_ghostface
class TTTTSWrapper: # TikTok Text-to-Speech Wrapper class TikTok: # TikTok Text-to-Speech Wrapper
def __init__(self): def __init__(self):
self.URI_BASE = "https://api16-normal-useast5.us.tiktokv.com/media/api/text/speech/invoke/?text_speaker=" self.URI_BASE = "https://api16-normal-useast5.us.tiktokv.com/media/api/text/speech/invoke/?text_speaker="

@ -0,0 +1,20 @@
from os import getenv
from dotenv import load_dotenv
from TTS.GTTS import GTTS
from TTS.TikTok import TikTok
CHOICE_DIR = {
'tiktok': TikTok,
'gtts': GTTS
}
class TTS:
def __new__(cls):
load_dotenv()
CHOICE = getenv('TTsChoice').casefold()
valid_keys = [key.lower() for key in CHOICE_DIR.keys()]
if CHOICE not in valid_keys:
raise ValueError(f'{CHOICE} is not valid. Please use one of these {valid_keys} options')
return CHOICE_DIR.get(CHOICE)()

@ -23,7 +23,7 @@ print(banner)
load_dotenv() load_dotenv()
# Modified by JasonLovesDoggo # Modified by JasonLovesDoggo
print_markdown( 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." "### 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. You can find solutions to many common problems in the [Documentation](https://luka-hietala.gitbook.io/documentation-for-the-reddit-bot/)"
) )
time.sleep(1) time.sleep(1)

@ -1,20 +1,19 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from gtts import gTTS from os import getenv
from pathlib import Path from pathlib import Path
from os import getenv, name
import sox import sox
from mutagen import MutagenError from mutagen import MutagenError
from mutagen.mp3 import MP3, HeaderNotFoundError from mutagen.mp3 import MP3, HeaderNotFoundError
from rich.progress import track
from rich.console import Console from rich.console import Console
from rich.progress import track
from TTS.swapper import TTS
console = Console() console = Console()
import re
from utils.console import print_step, print_substep from utils.console import print_step, print_substep
from utils.voice import sanitize_text from utils.voice import sanitize_text
from video_creation.TTSwrapper import TTTTSWrapper
VIDEO_LENGTH: int = 40 # secs VIDEO_LENGTH: int = 40 # secs
@ -29,9 +28,8 @@ def save_text_to_mp3(reddit_obj):
# Create a folder for the mp3 files. # Create a folder for the mp3 files.
Path("assets/temp/mp3").mkdir(parents=True, exist_ok=True) Path("assets/temp/mp3").mkdir(parents=True, exist_ok=True)
TextToSpeech = TTS()
ttttsw = TTTTSWrapper() # tiktok text to speech wrapper TextToSpeech.tts(
ttttsw.tts(
sanitize_text(reddit_obj["thread_title"]), sanitize_text(reddit_obj["thread_title"]),
filename=f"assets/temp/mp3/title.mp3", filename=f"assets/temp/mp3/title.mp3",
random_speaker=False, random_speaker=False,
@ -41,19 +39,19 @@ def save_text_to_mp3(reddit_obj):
except HeaderNotFoundError: # note to self AudioFileClip except HeaderNotFoundError: # note to self AudioFileClip
length += sox.file_info.duration(f"assets/temp/mp3/title.mp3") length += sox.file_info.duration(f"assets/temp/mp3/title.mp3")
if getenv("STORYMODE").casefold() == "true": if getenv("STORYMODE").casefold() == "true":
ttttsw.tts( TextToSpeech.tts(
sanitize_text(reddit_obj["thread_content"]), sanitize_text(reddit_obj["thread_content"]),
filename=f"assets/temp/mp3/story_content.mp3", filename=f"assets/temp/mp3/story_content.mp3",
random_speaker=False, random_speaker=False,
) )
#'story_content' # 'story_content'
com = 0 com = 0
for comment in track((reddit_obj["comments"]), "Saving..."): for comment in track((reddit_obj["comments"]), "Saving..."):
# ! Stop creating mp3 files if the length is greater than VIDEO_LENGTH seconds. This can be longer, but this is just a good_voices starting point # ! Stop creating mp3 files if the length is greater than VIDEO_LENGTH seconds. This can be longer, but this is just a good_voices starting point
if length > VIDEO_LENGTH: if length > VIDEO_LENGTH:
break break
ttttsw.tts( TextToSpeech.tts(
sanitize_text(comment["comment_body"]), sanitize_text(comment["comment_body"]),
filename=f"assets/temp/mp3/{com}.mp3", filename=f"assets/temp/mp3/{com}.mp3",
random_speaker=False, random_speaker=False,

Loading…
Cancel
Save