Search code examples
pythonpython-3.xmoduletext-to-speechpyttsx

How to fix Visual Studio "AttributeError: 'Engine' object has no attribute 'getproperty'"


This is my code:

import pyttsx3

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
print(voices[0].id)
engine.setProperty('voice',voices[0].id)




def speak(audio):
    engine.say(audio)
    engine.runAndWait()

if __name__=="__main__":
    speak("hello world")

Note: I have already installed the pyttsx3 module

ERROR:

[Running] python -u "f:\jarvis\jarvis.py"
Traceback (most recent call last):
  File "f:\jarvis\jarvis.py", line 3, in <module>
    voices = engine.getproperty('voices')
AttributeError: 'Engine' object has no attribute 'getproperty'

[Done] exited with code=1 in 2.08 seconds

Help me please How to fix this?


Solution

  • Python identifiers are case sensitive.

    You wrote:

    voices = engine.getProperty('voices')
    

    which is fine, and matches the docs exactly.

    The diagnostic you show is for some different code:

    voices = engine.getproperty('voices')
    AttributeError: 'Engine' object has no attribute 'getproperty'
    

    The diagnostic is correct. While there is a getProperty attribute, the engine lacks getproperty. Those are two different identifiers. Spell it correctly and your program will work better.