python - 如何修复 Visual Studio "AttributeError: ' 引擎'对象没有属性 'getproperty' ”

标签 python python-3.x module text-to-speech pyttsx

这是我的代码:

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/

相关文章:

python - Heroku H10错误— Python

python - 在Python中关联不同的类对象

python - 删除所有 Matplotlib 图形的上轴和右轴(不仅仅是一个图形)

python - 将列表拆分为均匀大小的重叠 block n-max

ruby - 获取包含模块的类列表

python - 类型错误 : Error when calling the metaclass bases module

python - 如何使用 .find() 来定位一个单元格并在循环中开始更新下面行中的单元格?

c++ - 如何从 C 或 C++ 调用 .pyc 函数?

python - 计算包含地理坐标的线串的边界框

module - 如何获取模块的不同文件的文件路径?