From c5fda9d3fe96b74d294d96c278f452abdb93fedc Mon Sep 17 00:00:00 2001 From: Supreme-hub <60816807+Supreme-hub@users.noreply.github.com> Date: Wed, 27 Jul 2022 23:41:02 +0530 Subject: [PATCH] added pyttsx option --- TTS/pyttsx.py | 38 +++++++++++++++++++++++++ ptt.py | 9 ++++++ utils/.config.template.toml | 4 ++- video_creation/data/videos.json | 19 ++++++++++++- video_creation/screenshot_downloader.py | 1 + video_creation/voices.py | 3 ++ 6 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 TTS/pyttsx.py create mode 100644 ptt.py diff --git a/TTS/pyttsx.py b/TTS/pyttsx.py new file mode 100644 index 0000000..0e6d3bb --- /dev/null +++ b/TTS/pyttsx.py @@ -0,0 +1,38 @@ +import pyttsx3 +from utils import settings +import random + +max_chars = 0 + +#Uses the system voices, significantly faster than other tts + +class pyttsx: + + def __init__(self): + self.max_chars = 0 + self.voices = [] + + def run( + self, + text: str = "Python Text to Speech", + filepath: str = "assets/temp/mp3", + random_voice=False, + censor=False, + ): + voice_id = int(settings.config["settings"]["tts"]["python_voice"]) + voice_num = int(settings.config["settings"]["tts"]["python_voice_number"]) + for i in range(voice_num): + self.voices.append(i) + i=+1 + if random_voice: + voice_id = self.randomvoice() + else: + voice = voice_id + engine = pyttsx3.init() + voices = engine.getProperty('voices') + engine.setProperty('voice', voices[voice].id) #changing index changes voices but ony 0 and 1 are working here + engine.save_to_file(text, f"{filepath}") + engine.runAndWait() + + def randomvoice(self): + return random.choice(self.voices) \ No newline at end of file diff --git a/ptt.py b/ptt.py new file mode 100644 index 0000000..b82c8e0 --- /dev/null +++ b/ptt.py @@ -0,0 +1,9 @@ +import pyttsx3 +engine = pyttsx3.init() +voices = engine.getProperty('voices') +for voice in voices: + print(voice, voice.id) + engine.setProperty('voice', voice.id) + engine.say("Hello World!") + engine.runAndWait() + engine.stop() \ No newline at end of file diff --git a/utils/.config.template.toml b/utils/.config.template.toml index 010a29b..20a163a 100644 --- a/utils/.config.template.toml +++ b/utils/.config.template.toml @@ -31,7 +31,9 @@ background_choice = { optional = true, default = "minecraft", example = "rocket- [settings.tts] -voice_choice = { optional = false, default = "", options = ["streamlabspolly", "tiktok", "googletranslate", "awspolly", ], example = "tiktok", explanation = "The voice platform used for TTS generation. This can be left blank and you will be prompted to choose at runtime." } +voice_choice = { optional = false, default = "", options = ["streamlabspolly", "tiktok", "googletranslate", "awspolly", "pyttsx"], example = "tiktok", explanation = "The voice platform used for TTS generation. This can be left blank and you will be prompted to choose at runtime." } aws_polly_voice = { optional = false, default = "Matthew", example = "Matthew", explanation = "The voice used for AWS Polly" } streamlabs_polly_voice = { optional = false, default = "Matthew", example = "Matthew", explanation = "The voice used for Streamlabs Polly" } tiktok_voice = { optional = false, default = "en_us_006", example = "en_us_006", explanation = "The voice used for TikTok TTS" } +python_voice = {optional = false, default = "1", example = "1", explanation = "The index of the system tts voices (can be downloaded externally, run ptt.py to find value)"} +python_voice_number = {optional = false, default = "2", example = "2", explanation= "the number of system voices(2 are pre-installed in windows)"} diff --git a/video_creation/data/videos.json b/video_creation/data/videos.json index fe51488..b851d3e 100644 --- a/video_creation/data/videos.json +++ b/video_creation/data/videos.json @@ -1 +1,18 @@ -[] +[ + { + "subreddit": "tifu", + "id": "w97htn", + "time": "1658942748", + "background_credit": "Achy Gaming", + "reddit_title": "TIFU by refusing to give tea to a Chinese senator", + "filename": "TIFU by refusing to give tea to a Chinese senator.mp4" + }, + { + "subreddit": "tifu", + "id": "w9iqby", + "time": "1658945240", + "background_credit": "Achy Gaming", + "reddit_title": "TIFU by giving my boss a RedBull", + "filename": "TIFU by giving my boss a RedBull.mp4" + } +] \ No newline at end of file diff --git a/video_creation/screenshot_downloader.py b/video_creation/screenshot_downloader.py index 7898e8d..4574675 100644 --- a/video_creation/screenshot_downloader.py +++ b/video_creation/screenshot_downloader.py @@ -1,3 +1,4 @@ +from distutils.command.config import config import json from pathlib import Path diff --git a/video_creation/voices.py b/video_creation/voices.py index 066921c..2a82b27 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -3,12 +3,14 @@ from typing import Dict, Tuple from rich.console import Console +from TTS import pyttsx from TTS.engine_wrapper import TTSEngine from TTS.GTTS import GTTS from TTS.streamlabs_polly import StreamlabsPolly from TTS.aws_polly import AWSPolly from TTS.TikTok import TikTok +from TTS.pyttsx import pyttsx from utils import settings from utils.console import print_table, print_step @@ -20,6 +22,7 @@ TTSProviders = { "AWSPolly": AWSPolly, "StreamlabsPolly": StreamlabsPolly, "TikTok": TikTok, + "pyttsx" : pyttsx, }