parent
b81ee722b8
commit
c5fda9d3fe
@ -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)
|
@ -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()
|
@ -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"
|
||||||
|
}
|
||||||
|
]
|
Loading…
Reference in new issue