微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何修复Visual Studio“ AttributeError:'Engine'对象没有属性'getproperty'”

如何解决如何修复Visual Studio“ AttributeError:'Engine'对象没有属性'getproperty'”

这是我的代码

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。 那是两个不同的标识符。 正确拼写,您的程序会更好地工作。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。