gpt4 book ai didi

Python-名称错误: name 'engine' is not defined/Driver not found

转载 作者:行者123 更新时间:2023-12-01 08:06:32 26 4
gpt4 key购买 nike

我一直在尝试使用以下视频在 PyCharm 中开展 AI 项目:https://www.youtube.com/watch?time_continue=179&v=rU_ppVsyJu8

这是代码:

import sys
print(sys.path)

import speech_recognition as sr
import pyttsx3

try:
engine = pyttsx3.init()
except ImportError:
print("Driver not found")
except RuntimeError:
print("Driver fails to init")

voices = engine.getProperty("voices")

for voice in voices:
print(voice.id)

并且有一个错误:

enter image description here

尽管它说找不到驱动程序,我还是在这里安装了 pyttsx3:

enter image description here

我已经解决这个问题一周了,但我无法继续前进。如果有人提供帮助,我们将不胜感激。

最佳答案

您无法执行engine = pyttsx3.init()。这就是它无法识别引擎对象的原因。尝试下面的代码。您将从 Exception 中收到错误消息。尝试解决该错误。

import sys
print(sys.path)

import speech_recognition as sr
import pyttsx3

try:
engine = pyttsx3.init()
**except Exception as e:
print(e)**
except ImportError:
print("Driver not found")
except RuntimeError:
print("Driver fails to init")

voices = engine.getProperty("voices")

for voice in voices:
print(voice.id)

关于Python-名称错误: name 'engine' is not defined/Driver not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55506571/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com