I would like to make an instance from pyttsx inside a class and have a settings function to change the speech rate. But the init is not working properly as it gives the following error message:
AttributeError: TTSengine instance has no attribute 'say'
From my codes:
import pyttsx
class TTSengine():
def __init__(self):
self.engine = pyttsx.init()
def settings(self):
self.rate = self.engine.getProperty('rate')
self.engine.setProperty('rate', self.rate-50)
y = pyttsx.init()
print y
y.say('I am ok')
y.runAndWait()
x = TTSengine()
print x
x.say('I am ok')
x.runAndWait()
Your class itself doesn't have a say function. Your class has a pyttsx engine as a member variable, so the following should work: