diff --git a/TTS/pyttsx.py b/TTS/pyttsx.py index 7e0fad1..2be3b53 100644 --- a/TTS/pyttsx.py +++ b/TTS/pyttsx.py @@ -2,41 +2,37 @@ import random import pyttsx3 from utils import settings -max_chars = 0 -# Uses the system voices, significantly faster than other tts +class pyttsx: - -class Pyttsx: def __init__(self): - self.max_chars = 0 + self.max_chars = 5000 self.voices = [] def run( self, - text: str = "Python Text to Speech", - filepath: str = "assets/temp/mp3", + text: str , + filepath: str, random_voice=False, ): - if (settings.config["settings"]["tts"]["python_voice"] == '' or settings.config["settings"]["tts"]["python_voice"] == ""): - voice_id = 0 + voice_id = settings.config["settings"]['tts']["python_voice"] + voice_num = settings.config["settings"]['tts']["py_voice_num"] + if (voice_id == "" or voice_num == ""): + voice_id = 2 voice_num = 3 + raise ValueError("set pyttsx values to a valid value, switching to defaults") else: - voice_id = int(settings.config["settings"]["tts"]["python_voice"]) - voice_num = int(settings.config["settings"]["tts"]["python_voice"]) - for i in range(voice_num - 1): + voice_id = int(voice_id) + voice_num = int(voice_num) + for i in range(voice_num): self.voices.append(i) - i = +1 + i=+1 if random_voice: - voice_id = self.randomvoice() - else: - voice = voice_id + voice_id = self.randomvoice() 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 + voices = engine.getProperty('voices') + engine.setProperty('voice', voices[voice_id].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) diff --git a/tempTEMP_MPY_wvf_snd.mp4 b/tempTEMP_MPY_wvf_snd.mp4 deleted file mode 100644 index e453248..0000000 Binary files a/tempTEMP_MPY_wvf_snd.mp4 and /dev/null differ diff --git a/utils/.config.template.toml b/utils/.config.template.toml index fe377fe..0ec28c9 100644 --- a/utils/.config.template.toml +++ b/utils/.config.template.toml @@ -36,4 +36,4 @@ aws_polly_voice = { optional = false, default = "Matthew", example = "Matthew", 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, start from zero)"} -python_voice_number = {optional = false, default = "2", example = "2", explanation= "the number of system voices(2 are pre-installed in windows)"} +py_voice_num = {optional = false, default = "2", example = "2", explanation= "the number of system voices(2 are pre-installed in windows)"} diff --git a/video_creation/voices.py b/video_creation/voices.py index 80a83ad..29c2b57 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -9,7 +9,7 @@ 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 TTS.pyttsx import pyttsx from utils import settings from utils.console import print_table, print_step @@ -21,7 +21,7 @@ TTSProviders = { "AWSPolly": AWSPolly, "StreamlabsPolly": StreamlabsPolly, "TikTok": TikTok, - "pyttsx": Pyttsx, + "pyttsx": pyttsx, }