【问题标题】:AttributeError: module 'pyttsx3' has no attribute 'init' [closed]AttributeError:模块'pyttsx3'没有属性'init'[关闭]
【发布时间】:2018-04-02 11:37:08
【问题描述】:

首先,我使用的是:

  • Windows 10
  • Python 3.6.2(但我也尝试过使用 Python 3.5.4)
  • pyttsx3模块

我正在尝试使用pyttsx3,但我无法初始化它,使用官方代码示例。

我的代码(就像herehere 中的示例):

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


    【解决方案1】:

    模块 pyttsx3 似乎没有正确初始化。我希望您在模块路径中的任何位置都没有名为 pyttsx3.py 的文件。我发现了一个相关的问题here

    【讨论】:

    • 哦,我完全忘记了我为测试创建了一个“pyttsx3.py”文件,我没有删除也没有重命名它。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2011-10-25
    • 2020-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-16
    • 2021-01-31
    • 2023-03-22
    相关资源
    最近更新 更多