属性错误:"引擎"对象没有属性"runandwait"



下面的程序给了我一个错误。这是我的程序:

import pyttsx3 as tts
def speak(text):
engine = tts.init("sapi5")
engine.say(text)
engine.runandwait()
speak('Hello user this is a test message.')

这是我收到的错误消息:

Traceback (most recent call last):
File "c:UsersSIDDHESHProjectstest.py", line 6, in <module>
speak('Hello user this is a test message.')
File "c:UsersSIDDHESHProjectstest.py", line 5, in speak
engine.runandwait()
AttributeError: 'Engine' object has no attribute 'runandwait'

我想指出的是,我的变量被称为engine,但错误消息说明了变量'Engine'的一些内容。我还想指出,我正在使用VisualStudioCode来运行我的代码。

看起来您需要编写engine.runAndWait(),每个新词都以大写字母开头。请记住,python是区分大小写的,这意味着runandwaitrunAndWait是不同的属性。

最新更新