-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTextToSpeech.py
More file actions
32 lines (26 loc) · 855 Bytes
/
TextToSpeech.py
File metadata and controls
32 lines (26 loc) · 855 Bytes
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
import pyttsx3
import threading
from GlobalHelpers import *
import time
from collections import defaultdict
message_interval = 5
message_timestamp_dict = defaultdict(lambda: -1)
def engine_thread():
engine = pyttsx3.init()
while True:
text = global_queue.get(block=True)
if text == "end":
break
engine.say(text)
engine.runAndWait()
t = threading.Thread(target=engine_thread, daemon=True)
t.start()
def BotSpeak(unique_id, text):
print("unique_id", unique_id)
ctime = time.time()
mtime = message_timestamp_dict[unique_id]
# 100 is for rep completion
if ctime - mtime > message_interval or mtime == -1 or unique_id == 100:
message_timestamp_dict[unique_id] = time.time()
print("speaking message ")
global_queue.put(text)