Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyttsx always busy #54

Open
symsymmas opened this issue Apr 18, 2017 · 5 comments
Open

pyttsx always busy #54

symsymmas opened this issue Apr 18, 2017 · 5 comments

Comments

@symsymmas
Copy link

runAndWait infinitely loop. I think that's because of isBusy function which always returns "True".

@spreadred
Copy link

Can you post your relevant code so someone can try to reproduce this?

@Julian-O
Copy link

Julian-O commented May 1, 2017

I've recently been getting the same problem - Related to threading module? Related to Python 3.6?

Yet to produce a "minimum faulty program" for a bug report.

@Julian-O
Copy link

Julian-O commented May 1, 2017

    """ 
    pyttsx deadlocks in certain conditions.
    
    This code has been tested and fails to terminate on:
    Python 3.4.3, Windows 32-bit.
    Python 3.5.1, Windows 64-bit.
    Python 3.6.1, Winoows 64-bit.
    Python
    
    This code, below, is strongly based on @shark3y's answer on Stack Overflow:
    http://stackoverflow.com/a/39069269/8014
    """
    
    import sys
    print(sys.version)
    
    import pyttsx
    from queue import Queue
    import threading
    
    class VoiceAssistant(threading.Thread):
        def __init__(self):
            super(VoiceAssistant, self).__init__()
            self.engine = pyttsx.init()
            self.q = Queue()
            self.daemon = True
    
        def add_say(self, msg):
            self.q.put(msg)
    
        def run(self):
            while True:
                self.engine.say(self.q.get())
                print("runAndWait starts.")
                try:
                    self.engine.runAndWait()
                except:
                    print("runAndWait had an exception.") # Doesn't happen
                print("runAndWait completes.") # Doesn't happen
                self.q.task_done()
    
    
    if __name__ == '__main__':
        va = VoiceAssistant()
        va.start()
        for i in range(0, 3):
            va.add_say('Sally sells seashells by the seashore.')
        print("The main thread is now going to wait for the VoiceAssistant thread to complete.")
        va.q.join() # ends the loop when queue is empty
        print("Done")

@Julian-O
Copy link

Julian-O commented May 1, 2017

    """ 
    pyttsx deadlocks in certain conditions.
    
    This code has been tested and runs on:
    Python 3.4.3, Windows 32-bit.
    Python 3.5.1, Windows 64-bit.
    Python 3.6.1, Windows 64-bit.
    
    This code, below, is strongly based on @shark3y's answer on Stack Overflow:
    http://stackoverflow.com/a/39069269/8014
    """
    
    import sys
    print(sys.version)
    
    import pyttsx
    
    class VoiceAssistant():
        def __init__(self):
            self.engine = pyttsx.init()
    
        def add_say(self, msg):
            self.engine.say(msg)
    
            print("runAndWait starts.")
            try:
                self.engine.runAndWait()
            except:
                print("runAndWait had an exception.")  # Doesn't happen
            print("runAndWait completes.")  # Happens
    
    
    if __name__ == '__main__':
        va = VoiceAssistant()
        for i in range(0, 3):
            va.add_say('Sally sells seashells by the seashore.')
        print("Done")

@Julian-O
Copy link

Julian-O commented May 1, 2017

The above two snippets show a working and non-working version of pyttsx on Windows. The non-working version involves a second thread.

Note: This is based on Julian-O\pyttsx, which has had a trivial change to setup.py, to use pypiwin32 over win32com, as it is compatible with virtualenv.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants