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)
CodePudding user response:
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)