1

My code for my personal assistant:

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

# text to speech
def speak(audio):
    engine.say(audio)
    print(audio)
    engine.runAndWait()

Error shown:

Traceback (most recent call last):
  File "c:\Users\Samarth S\OneDrive\Desktop\AI Projects\AIVVA\3\main.py", line 18, in <module>
    engine.setProperty('voice', voices[0].id)
AttributeError: 'str' object has no attribute 'id'

This is my first python project and I am struck in the voices itself.

martineau
  • 119,623
  • 25
  • 170
  • 301
Samartha S
  • 11
  • 2

1 Answers1

0

You are close, the problem is specifically this line of code where you call getProperty with 'voice' as the parameter:

voices = engine.getProperty('voice') 

Instead, you should call getProperty with 'voices' as the parameter:

voices = engine.getProperty('voices') 

Calling getProperty with 'voices' will return a list of pyttsx3.voice.Voice descriptor objects which should make this line of code work:

engine.setProperty('voice', voices[0].id)

Take a look at the pyttsx3 engine documentation for specifics.

rhurwitz
  • 2,557
  • 2
  • 10
  • 18