回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>所以我在youtube上看了一个简单的教程,不管我做什么,我总是得到同样的问题。在</p>
<p>这是我使用的代码。在</p>
<pre><code>import speech_recognition as sr
import pyttsx3
voices = []
engine = pyttsx3.init()
voices = engine.getProperty('voices')
for voice in voices:
print(voice.id)
</code></pre>
<p>我是用sublimitext3写的。每次我建立这个,我得到相同的错误。在</p>
<blockquote>
<p>File "C:\Users\This PC\Desktop\Py\introTest.py", line 14, in
voices = engine.getProperty('voices') NameError: name 'engine' is not defined</p>
</blockquote>
<p>不知道为什么说“引擎”没有定义。我很清楚的在尝试下定义了它。任何帮助都将不胜感激。在</p>
<p>删除try/exceptions之后,我有很多新的错误。这是构建日志。在</p>
<blockquote>
<p>Traceback (most recent call last): File "C:\Users\This
PC\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pyttsx3__init__.py",
line 44, in init
eng = _activeEngines[driverName] File "C:\Users\This PC\AppData\Local\Programs\Python\Python37-32\lib\weakref.py", line
137, in <strong>getitem</strong>
o = self.datakey KeyError: None</p>
<p>During handling of the above exception, another exception occurred:</p>
<p>Traceback (most recent call last): File "C:\Users\This
PC\Desktop\Py\demo.py", line 7, in
engine = pyttsx3.init() File "C:\Users\This PC\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pyttsx3__init__.py",
line 46, in init
eng = Engine(driverName, debug) File "C:\Users\This PC\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pyttsx3\engine.py",
line 52, in <strong>init</strong>
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug) File "C:\Users\This
PC\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pyttsx3\driver.py",
line 75, in <strong>init</strong>
self._module = importlib.import_module(name) File "C:\Users\This PC\AppData\Local\Programs\Python\Python37-32\lib\importlib__init__.py",
line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level) File "", line 1006, in _gcd_import File
"", line 983, in _find_and_load File
"", line 967, in _find_and_load_unlocked
File "", line 677, in _load_unlocked<br/>
File "", line 728, in
exec_module File "", line 219, in
_call_with_frames_removed File "C:\Users\This PC\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pyttsx3\drivers\sapi5.py",
line 3, in
import win32com.client ModuleNotFoundError: No module named 'win32com' [Finished in 0.1s]</p>
</blockquote>