added full pyttsx functionality

pull/1085/head
Supreme-hub 3 years ago
parent ae41127a91
commit 3da1debf83

@ -2,39 +2,35 @@ import random
import pyttsx3 import pyttsx3
from utils import settings from utils import settings
max_chars = 0 class pyttsx:
# Uses the system voices, significantly faster than other tts
class Pyttsx:
def __init__(self): def __init__(self):
self.max_chars = 0 self.max_chars = 5000
self.voices = [] self.voices = []
def run( def run(
self, self,
text: str = "Python Text to Speech", text: str ,
filepath: str = "assets/temp/mp3", filepath: str,
random_voice=False, random_voice=False,
): ):
if (settings.config["settings"]["tts"]["python_voice"] == '' or settings.config["settings"]["tts"]["python_voice"] == ""): voice_id = settings.config["settings"]['tts']["python_voice"]
voice_id = 0 voice_num = settings.config["settings"]['tts']["py_voice_num"]
if (voice_id == "" or voice_num == ""):
voice_id = 2
voice_num = 3 voice_num = 3
raise ValueError("set pyttsx values to a valid value, switching to defaults")
else: else:
voice_id = int(settings.config["settings"]["tts"]["python_voice"]) voice_id = int(voice_id)
voice_num = int(settings.config["settings"]["tts"]["python_voice"]) voice_num = int(voice_num)
for i in range(voice_num - 1): for i in range(voice_num):
self.voices.append(i) self.voices.append(i)
i=+1 i=+1
if random_voice: if random_voice:
voice_id = self.randomvoice() voice_id = self.randomvoice()
else:
voice = voice_id
engine = pyttsx3.init() engine = pyttsx3.init()
voices = engine.getProperty("voices") voices = engine.getProperty('voices')
engine.setProperty( engine.setProperty('voice', voices[voice_id].id) #changing index changes voices but ony 0 and 1 are working here
"voice", voices[voice].id
) # changing index changes voices but ony 0 and 1 are working here
engine.save_to_file(text, f"{filepath}") engine.save_to_file(text, f"{filepath}")
engine.runAndWait() engine.runAndWait()

Binary file not shown.

@ -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" } 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" } 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 = {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)"}

@ -9,7 +9,7 @@ from TTS.GTTS import GTTS
from TTS.streamlabs_polly import StreamlabsPolly from TTS.streamlabs_polly import StreamlabsPolly
from TTS.aws_polly import AWSPolly from TTS.aws_polly import AWSPolly
from TTS.TikTok import TikTok from TTS.TikTok import TikTok
from TTS.pyttsx import Pyttsx from TTS.pyttsx import pyttsx
from utils import settings from utils import settings
from utils.console import print_table, print_step from utils.console import print_table, print_step
@ -21,7 +21,7 @@ TTSProviders = {
"AWSPolly": AWSPolly, "AWSPolly": AWSPolly,
"StreamlabsPolly": StreamlabsPolly, "StreamlabsPolly": StreamlabsPolly,
"TikTok": TikTok, "TikTok": TikTok,
"pyttsx": Pyttsx, "pyttsx": pyttsx,
} }

Loading…
Cancel
Save