mirror of
https://github.com/EyeTrackVR/EyeTrackVR.git
synced 2025-11-04 14:39:42 +08:00
27 lines
626 B
Python
27 lines
626 B
Python
import pyttsx3
|
|
import queue
|
|
import threading
|
|
|
|
|
|
class SpeechEngine:
|
|
def __init__(self, queue: "queue.Queue[str | None]"):
|
|
self.engine = pyttsx3.init()
|
|
self.queue = queue
|
|
|
|
def say(self, item):
|
|
self.engine.say(item)
|
|
|
|
def force_stop(self):
|
|
self.engine.stop()
|
|
|
|
def run(self):
|
|
while True:
|
|
print("Waiting for speech item")
|
|
item = self.queue.get()
|
|
if item is None:
|
|
print("Stopping speech engine")
|
|
self.engine.stop()
|
|
return
|
|
self.engine.say(item)
|
|
self.engine.runAndWait()
|