我收到一個錯誤,名為“list”物件沒有屬性“setProperty”
我正在用 python 制作 ai 這是我的代碼 問題在于最后 2 行 任何人都可以修復它
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)
uj5u.com熱心網友回復:
問題不言自明:您正在嘗試使用setProperty串列中的函式。
這意味著您的變數voice是一個串列,因為您使用了以下行voice = voice.getProperty('voices')。這將回傳一個串列,并將其分配給變數voice。
正如@Oli所提到的,可能的解釋可能是您的代碼中的錯字。替換voice為voices可以幫助解決這個問題:
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)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/393666.html
上一篇:試圖讀取整個檔案但得到[Errno2]沒有這樣的檔案或目錄
下一篇:使用變數開發VSCode主題
