[Python] Python pyttsx, how to use external loop

Discussão em 'Python' iniciado por Stack, Julho 2, 2025.

  1. Stack

    Stack Membro Participativo

    In my program I need class(which can be some thread) to check some list like "say_list" and when other classes add some text to it, pyttsx say that text. I search in pyttsx docs and I find some external loops feature but I can not find example which work correctly. I want something like this:

    import pyttsx
    import threading

    class VoiceAssistant(threading.Thread):
    def __init__(self):
    super(VoiceAssistant, self).__init__()
    self.engine = pyttsx.init()
    self.say_list = []

    def add_say(self, msg):
    self.say_list.append(msg)

    def run(self):
    while True:
    if len(self.say_list) > 0:
    self.engine.say(self.say_list[0])
    self.say_list.remove(self.say_list[0])


    if __name__ == '__main__':
    va = VoiceAssistant()
    va.start()


    Thanks.

    Continue reading...

Compartilhe esta Página