我正在用 Python3 上的语音进行试验,我对 python 很陌生,我已经搜索了所有的互联网以了解我的代码有什么问题,当我运行代码时,我得到了你可以在下面看到的错误。请帮助我更好地了解正在发生的事情。
这是我的代码:
import speech_recognition as sr
import time
import pyttsx3
r = sr.Recognizer()
with sr.Microphone() as mic:
print("Say something")
audio = r.listen(mic)
print("Recording Stopped")
r.recognize_google(audio)
if r.recognize_google(audio) == "I'm pretty" or r.recognize_google(audio) == "I am pretty" :
engine = pyttsx3.init()
engine.say("You said: I'm Ugly")
engine.runAndWait()
else:
engine = pyttsx3.init()
engine.say("You said: " + r.recognize_google(audio))
engine.runAndWait()
这是错误消息:
Last login: Sat Feb 16 18:03:26 on ttys002
ErenUcar-3:~ eucar$ python /Users/eucar/.atom/packages/atom-python-run/lib/../cp/main.py --pause -- python3 /Users/eucar/Documents/Testing/noob.py
Say something
Recording Stopped
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyttsx3/__init__.py", line 44, in init
eng = _activeEngines[driverName]
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/weakref.py", line 137, in __getitem__
o = self.data[key]()
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/eucar/Documents/Testing/noob.py", line 23, in <module>
engine = pyttsx3.init()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyttsx3/__init__.py", line 46, in init
eng = Engine(driverName, debug)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyttsx3/engine.py", line 52, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyttsx3/driver.py", line 75, in __init__
self._module = importlib.import_module(name)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyttsx3/drivers/nsss.py", line 2, in <module>
from Foundation import *
ModuleNotFoundError: No module named 'Foundation'
Process returned 1 (0x1) execution time : 10.702 s
Close this window to continue...
ErenUcar-3:~ eucar$