-2

I am getting an error called 'list' object has no attribute 'setProperty'

I am making a ai in python this is my code THE ISSUE IS WITH THE LAST 2 LINES CAN ANYONE PLEASE FIX IT

import datetime
import random
import sys
import webbrowser
import googlesearch
import pyttsx3
import speech_recognition as sr
from playsound import playsound

print("")
voice = pyttsx3.init()

voice = voice.getProperty('voices')
voice.setProperty('voice', voices[0].id)
Antoine Delia
  • 1,728
  • 5
  • 26
  • 42
  • 3
    Please do not post code as image. Rather, write down your code directly in the question. – Antoine Delia Dec 23 '21 at 10:10
  • 1
    Welcome to stackoverflow. This question is of a low quality, if you would like others to spend the time to answer the quesiton maybe more time should be spent on the quality of the question, this include code in the question, and a LACK OF CAPS. We would be happy to help once the question is improved. – Matt Seymour Dec 23 '21 at 10:12
  • I'm not experienced with this library, but looking at the code in https://stackoverflow.com/q/44858120/6744133, it appears line 13 should be `voices = voice.getProperty('voices')`. That's `voices`, not `voice`. Does this work? – Oli Dec 23 '21 at 10:16

1 Answers1

1

The issue is self explanatory: you are trying to use the function setProperty on a list.

That means your variable voice is a list, because you use the following line voice = voice.getProperty('voices'). This will return a list, and you assign it to the variable voice.

As mentioned by @Oli, a possible explanation could be a typo in your code. Replacing voice by voices could help with this issue:

import datetime
import random
import sys
import webbrowser
import googlesearch
import pyttsx3
import speech_recognition as sr
from playsound import playsound

print("")
voice = pyttsx3.init()

voices = voice.getProperty('voices')
voice.setProperty('voice', voices[0].id)
Antoine Delia
  • 1,728
  • 5
  • 26
  • 42
  • I had tried to make so make ai but all of them failed so I made this but I got this error yesterday evening thanks for fixing it actually there are 160 lines of code in this project right now I am sure It will increase thanks for your help – Rubain Riyam Dec 24 '21 at 09:40