这是我的代码:
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")
注意:我已经安装了 pyttsx3 模块
错误:
[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
请帮帮我 如何解决这个问题?
最佳答案
Python 标识符区分大小写。
你写道:
voices = engine.getProperty('voices')
这很好,并且匹配 the docs完全正确。
您显示的诊断适用于某些不同的代码:
voices = engine.getproperty('voices') AttributeError: 'Engine' object has no attribute 'getproperty'
诊断正确。
虽然有一个 getProperty
属性,
引擎缺少getproperty
。
这是两个不同的标识符。
拼写正确,您的程序将会运行得更好。
关于python - 如何修复 Visual Studio "AttributeError: ' 引擎'对象没有属性 'getproperty' ”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63428694/