2

I am receiving the following error with the following code

import speech_recognition as sr
import pyttsx3

engine = pyttsx3.init()
engine.runAndWait
engine.say("Hello")
  Traceback (most recent call last):
       File "C:\Users\ProBook\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyttsx3\__init__.py",
 line 20, in init
         eng = _activeEngines[driverName]
       File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\lib\weakref.py",
 line 137, in \_\_getitem\_\_
         o = self.data[key]()
     KeyError: None

During the handling of the above exception, another exception occurred:

Traceback (most recent call last):
       File "C:\Users\ProBook\Desktop\app1\APP.py", line 3, in <module>
         engine = pyttsx3.init()
       File "C:\Users\ProBook\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyttsx3\__init__.py",
 line 22, in init
         eng = Engine(driverName, debug)
       File "C:\Users\ProBook\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyttsx3\engine.py",
 line 30, in __init__
         self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
       File "C:\Users\ProBook\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyttsx3\driver.py",
 line 50, in __init__
         self._module = importlib.import_module(name)
       File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.1776.0_x64__qbz5n2kfra8p0\lib\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 "C:\Users\ProBook\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\pyttsx3\drivers\sapi5.py",
 line 3, in <module>
         import win32com.client
       File "C:\Users\ProBook\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\win32com\__init__.py",
 line 5, in <module>
         import win32api, sys, os
     ImportError: DLL load failed: The specified module could not be found.

Does anyone have a solution for this? I already tried installing and re-installing the packages as well as python several times

MyStackRunnethOver
  • 4,872
  • 2
  • 28
  • 42
Luis Carnero
  • 21
  • 1
  • 2
  • Did you `pip install pywin32`? – CristiFati Jan 14 '20 at 14:22
  • Yes i installed all of the packages needed I even tried with pypiwin32 – Luis Carnero Jan 14 '20 at 23:17
  • It's ***pywin32***. Try opening an interpreter console and type `import sys`, `import os`, `import win32api` on 3 separate lines, and check which gets the error. Secondly, did you install the modules on the right *Python* installation? – CristiFati Jan 15 '20 at 08:54

3 Answers3

0

It looks like the default sapi5 engine is missing. Try to explicitly specify the language engine.

pyttsx3.init("sapi5")

If the problem persists, try installing espeak and initializing the pyttsx with it. More info there

Ivan Muravlev
  • 179
  • 1
  • 6
0

Try the command python -m pip install --upgrade pip i had the same problem ..this will upgrade your pip packages ..it worked for me though

lczapski
  • 4,026
  • 3
  • 16
  • 32
Aditya
  • 1
0

if pyttsx3 module not installed in your operating system just write these command on Anaconda Prompt or Python command

pip install pyttsx3==2.71 OR pip install -U pyttsx3==2.71
Scransom
  • 3,175
  • 3
  • 31
  • 51