diff --git a/TTS/pyttsx.py b/TTS/pyttsx.py new file mode 100644 index 0000000..06d27c5 --- /dev/null +++ b/TTS/pyttsx.py @@ -0,0 +1,42 @@ +import random +import pyttsx3 +from utils import settings + + +class pyttsx: + def __init__(self): + self.max_chars = 5000 + self.voices = [] + + def run( + self, + text: str, + filepath: str, + random_voice=False, + ): + 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(voice_id) + voice_num = int(voice_num) + for i in range(voice_num): + self.voices.append(i) + i = +1 + if random_voice: + voice_id = self.randomvoice() + engine = pyttsx3.init() + 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/ptt.py b/ptt.py new file mode 100644 index 0000000..6b49ef6 --- /dev/null +++ b/ptt.py @@ -0,0 +1,10 @@ +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() diff --git a/utils/.config.template.toml b/utils/.config.template.toml index 010a29b..31ae9aa 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, start from zero)"} +py_voice_num = {optional = false, default = "2", example = "2", explanation= "the number of system voices(2 are pre-installed in windows)"} diff --git a/utils/console.py b/utils/console.py index 6f99a41..1518c27 100644 --- a/utils/console.py +++ b/utils/console.py @@ -118,3 +118,4 @@ def handle_input( console.print( "[red bold]" + err_message + "\nValid options are: " + ", ".join(map(str, options)) + "." ) + diff --git a/video_creation/data/videos.json b/video_creation/data/videos.json index fe51488..0637a08 100644 --- a/video_creation/data/videos.json +++ b/video_creation/data/videos.json @@ -1 +1 @@ -[] +[] \ No newline at end of file diff --git a/video_creation/voices.py b/video_creation/voices.py index 066921c..f49514d 100644 --- a/video_creation/voices.py +++ b/video_creation/voices.py @@ -9,6 +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 utils import settings from utils.console import print_table, print_step @@ -20,6 +21,7 @@ TTSProviders = { "AWSPolly": AWSPolly, "StreamlabsPolly": StreamlabsPolly, "TikTok": TikTok, + "pyttsx": pyttsx, }