2

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?

Ed Lucas
  • 5,955
  • 4
  • 30
  • 42
  • Did you mean `voices = engine.getProperty('voices')`? The code you posted works fine for me, but your full error traceback (well done for posting it) reveals some different code that *you* are actually running. Try copying your own code out of your question and run that. – quamrana Aug 15 '20 at 17:15
  • I copied this code out of my code and pasted it in this question. I double checked every step but still this error is coming. – Bhargab Dutta Aug 16 '20 at 10:14

1 Answers1

2

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.

J_H
  • 17,926
  • 4
  • 24
  • 44
  • I spelled it exactly as in this question but still this error is coming. I even double checked it. I spelled it `getProperty` but still , the error is showing as`'Engine' object has no attribute 'getproperty'` – Bhargab Dutta Aug 16 '20 at 10:13
  • If you are seeing this error then you **must** have the wrong spelling somewhere. – quamrana Aug 16 '20 at 15:52
  • I am getting the exact same error.
    File "c:\Users\SIDDHESH\Projects\file_reader.py", line 11, in speak engine.runandwait() AttributeError: 'Engine' object has no attribute 'runandwait'
    – Siddhesh Agarwal Jan 03 '21 at 07:40