Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to run pyttsx3 in a loop

import pyttsx
from Queue import Queue
from threading import Thread

q = Queue()

def say_loop():
    engine = pyttsx.init()
    while True:
        engine.say(q.get())
        engine.runAndWait()
        q.task_done()

def another_method():
    t = Thread(target=say_loop)
    t.daemon = True
    t.start()
    for i in range(0, 3):
        q.put('Sally sells seashells by the seashore.')
    print "end of another method..."

def third_method():
    q.put('Something Something Something')

if __name__=="__main__":
    another_method()
    third_method()
    q.join() # ends the loop when queue is empty
Comment

PREVIOUS NEXT
Code Example
Python :: or in django query 
Python :: django check user admin 
Python :: how to convert a list to dataframe in python 
Python :: cross join pandas 
Python :: random in python 
Python :: how to iterate through a list in python 
Python :: Python NumPy repeat Function Syntax 
Python :: random.choice 
Python :: python spammer 
Python :: multiple boxplots python 
Python :: pandas earliest date in column 
Python :: catch error data with except python 
Python :: pyqt5 button connect 
Python :: how to set variable to null in python 
Python :: python plot groupby colors 
Python :: python virtualenv 
Python :: access first element of dictionary python 
Python :: display data from database in django 
Python :: add caption to plot python 
Python :: np.random.RandomState 
Python :: add place in certain index python string 
Python :: how to capitalize first letter in python 
Python :: finding path of a module in python 
Python :: euclidean distance python 3 variables 
Python :: discord py check if user has permission return message if not 
Python :: raspberry pi keyboard python input 
Python :: Python Changing Directory 
Python :: how to change frame in tkinter 
Python :: audioplayer python 
Python :: python tkinter arabic 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =