【发布时间】:2018-04-02 11:37:08
【问题描述】:
首先,我使用的是:
- Windows 10
- Python 3.6.2(但我也尝试过使用 Python 3.5.4)
- pyttsx3模块
我正在尝试使用pyttsx3,但我无法初始化它,使用官方代码示例。
import pyttsx3
engine = pyttsx3.init()
engine.say('Just a sample text.')
engine.runAndWait()
第二行给了我这个错误:
AttributeError: 模块 'pyttsx3' 没有属性 'init'
我是用 PIP 安装的:
pip install pyttsx3
我尝试安装 pypiwin32 来修复它,但它仍然无法正常工作:
pip install pypiwin32
当我执行以下脚本时:
import pyttsx3
print(dir(pyttsx3))
我明白了:
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'pyttsx3']
有这个:
drivers (folder)
__pycache__ (folder)
driver.py
engine.py
six.py
voice.py
__init__.py
在:
C:\Program Files\Python36\Lib\site-packages\pyttsx3
还有文件__init__.py的内容(我省略了cmets):
from .engine import Engine
import weakref
_activeEngines = weakref.WeakValueDictionary()
def init(driverName=None, debug=False):
try:
eng = _activeEngines[driverName]
except KeyError:
eng = Engine(driverName, debug)
_activeEngines[driverName] = eng
return eng
【问题讨论】:
标签: python text-to-speech pyttsx