1

So basically I am building a python virtual assistant software in a virtual environment and I want to use pyttsx3 to convert text to speech. The first issue is that if i run pyttsx3.init() I get an error

o = self.data[key]()
KeyError: None

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".\__init__.py", line 3, in <module>
    init_speech()
  File "C:\Users\DJETHA\eclipse-workspace\PythonFull\PythonProjects\Betax\index.py", line 31, in init_speech
    engine = pyttsx3.init()
  File "C:\Users\DJETHA\eclipse-workspace\PythonFull\PythonProjects\Betax\venv\lib\site-packages\pyttsx3\__init__.py", line 46, in init
    eng = Engine(driverName, debug)
  File "C:\Users\DJETHA\eclipse-workspace\PythonFull\PythonProjects\Betax\venv\lib\site-packages\pyttsx3\engine.py", line 52, in __init__
    self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
  File "C:\Users\DJETHA\eclipse-workspace\PythonFull\PythonProjects\Betax\venv\lib\site-packages\pyttsx3\driver.py", line 75, in __init__
    self._module = importlib.import_module(name)
  File "C:\Users\DJETHA\eclipse-workspace\PythonFull\PythonProjects\Betax\venv\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\DJETHA\eclipse-workspace\PythonFull\PythonProjects\Betax\venv\lib\site-packages\pyttsx3\drivers\sapi5.py", line 3, in <module>
    import win32com.client
  File "C:\Users\DJETHA\eclipse-workspace\PythonFull\PythonProjects\Betax\venv\lib\site-packages\win32com\__init__.py", line 5, in <module>
    import win32api, sys, os

Upon doing my research I found out that using pyttsx3.init("dummy") wont generate any error. The next issue though is that when I run

engine =pyttsx3.init("dummy")
engine.say("hey")
engine.runAndWait()

I dont hear anything or see any error

I should note that if i used the above code without the dummy in the pyttsx3.init outside the virtual env, everything works fine.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Udendu Abasili
  • 1,163
  • 2
  • 13
  • 29

2 Answers2

0

Try this:

import pyttsx3
from pyttsx3.drivers import sapi5

engine = pyttsx3.init('sapi5')
engine.say('hey')
engine.runAndWait()
Itsjul1an
  • 301
  • 1
  • 2
  • 12
0

i got same error 1 month back. the mistake i have done is i initially installed python X36 version. that is the cause. to check the python architecture use below code

src\4-4-project>python
>>import platform
>>platform.architecture()

if output shows 32bit instead of 64bit then uninstall python X36bit and freshly install python X64. don't worry about preinstalled packages though. you simply can save all packages by following code

pip freeze > packages.txt
#or
python -m pip freeze> packages.txt

you can reinstall all packages after installing python x64bit version by following code

python -m pip install -r packages.txt

after setting up the python x64bit version and setting the path the following code is enough. don't forgot to install packages again.

import pyttsx3
engine = pyttsx3.init()
engine.say("hello world")
engine.runAndWait()

hope it works.

HarshaBlaze
  • 1
  • 1
  • 2