-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtxt2sp.py
40 lines (30 loc) · 1.02 KB
/
txt2sp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/Library/Frameworks/Python.framework/Versions/3.10/bin/python3
import pyttsx3
import json
import random
import sys
import datetime
engine = pyttsx3.init()
try:
post_json = open("./media/post/post.json")
post = json.load(post_json)
voices = engine.getProperty("voices")
acceptable_voices = [0, 1, 6, 7, 5, 17, 26, 27, 28, 32, 33, 37, 40, 45]
engine.setProperty("rate", 280)
engine.setProperty("volume", 1.2)
# comments
for index, comment in enumerate(post["comments"]):
engine.setProperty("voice", voices[random.choice(acceptable_voices)].id)
comment_txt = comment["comment_txt"]
engine.save_to_file(
comment_txt, f"./media/post/comments/{index}/comment_speach.aiff"
)
# main post
engine.setProperty("voice", voices[7].id)
post_txt = post["post_txt"]
engine.save_to_file(post_txt, f"./media/post/post_speach.aiff")
engine.runAndWait()
print(f"{sys.argv[0]} ✅ {datetime.datetime.now()}")
sys.exit(1)
except:
sys.exit(0)