Can't initialize the pyttsx3 module - python

When I am using this in my program :
import pyttsx3
engine = pyttsx3.init("sapi5")
I am getting a error which says:
Traceback (most recent call last):
File "C:\Python38\lib\site-packages\pyttsx3\__init__.py", line 20, in init
eng = _activeEngines[driverName]
File "C:\Python38\lib\weakref.py", line 131, in __getitem__
o = self.data[key]()
KeyError: 'sapi5'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python38\lib\site-packages\pyttsx3\__init__.py", line 22, in init
eng = Engine(driverName, debug)
File "C:\Python38\lib\site-packages\pyttsx3\engine.py", line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "C:\Python38\lib\site-packages\pyttsx3\driver.py", line 50, in __init__
self._module = importlib.import_module(name)
File "C:\Python38\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Python38\lib\site-packages\pyttsx3\drivers\sapi5.py", line 10, in <module>
import pythoncom
File "C:\Python38\lib\site-packages\pythoncom.py", line 2, in <module>
import pywintypes
File "C:\Users\User name\AppData\Roaming\Python\Python38\site-packages\pywintypes.py", line 124, in <module>
__import_pywin32_system_module__("pywintypes", globals())
File "C:\Users\User name\AppData\Roaming\Python\Python38\site-packages\pywintypes.py", line 98, in __import_pywin32_system_module__
raise ImportError("No system module '%s' (%s)" % (modname, filename))
ImportError: No system module 'pywintypes' (pywintypes38.dll)
Please tell me how can I solve this problem.
I searched it on internet and I saw a answer saying that instead of 'sapi5' you can write 'dummy' but after writing dummy my program is not speaking and that's my main motive
Packages:
pyttsx3 - 2.87
python - 3.8.2
Thanks in advance.

On the last line, it says No system module 'pywintypes'. Try installing that with pip or your package manager. It may fix the problem

Related

pyttsx3 module is not giving any output

I'm having some troubles with the pyttsx3 module. At first I couldn't even initialize it and I got this error:
File "/home/emanuele/.local/lib/python3.9/site-packages/pyttsx3/__init__.py", line 20, in init
eng = _activeEngines[driverName]
File "/usr/lib/python3.9/weakref.py", line 137, in __getitem__
o = self.data[key]()
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/emanuele/AllInOneApp.py", line 3, in <module>
engine = pyttsx3.init()
File "/home/emanuele/.local/lib/python3.9/site-packages/pyttsx3/__init__.py", line 22, in init
eng = Engine(driverName, debug)
File "/home/emanuele/.local/lib/python3.9/site-packages/pyttsx3/engine.py", line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "/home/emanuele/.local/lib/python3.9/site-packages/pyttsx3/driver.py", line 50, in __init__
self._module = importlib.import_module(name)
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/home/emanuele/.local/lib/python3.9/site-packages/pyttsx3/drivers/espeak.py", line 3, in <module>
import ctypes
File "/usr/lib/python3.9/ctypes/__init__.py", line 8, in <module>
from _ctypes import Union, Structure, Array
ImportError: libffi.so.8: cannot open shared object file: No such file or directory
Then I solved it by running this two commands
pip uninstall pyttsx3
and
pip install pyttsx3==2.71
and adding to the init function the argument 'dummy'.
The problem is that now it runs without errors, but I don't get any output from the module
I finally got the solution. Refer below for the fix.
Run: sudo apt install libespeak1
Explanation: libspeak1 package is needed for running pyttsx3 in ubuntu.

Error in using text to speech engine(NSSpeechSynthesizer on Mac OS) pyttsx3

I am doing a tutorial on voice-based assistant. But I keep getting error while compiling the code. I am using M1 mac.
my code:
import pyttsx3
engine = pyttsx3.init('nsss')
engine.say('Hello sir, how may I help you, sir.')
engine.runAndWait()
code error:
I also installed pyobjc module as some other answers suggested on StackOverflow. Still not working.
Stacktrace with Python 3.9.7:
Traceback (most recent call last):
File "/opt/homebrew/lib/python3.9/site-packages/pyttsx3/__init__.py", line 20, in init
eng = _activeEngines[driverName]
File "/opt/homebrew/Cellar/python#3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/weakref.py", line 137, in __getitem__
o = self.data[key]()
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/homebrew/lib/python3.9/site-packages/pyttsx3/__init__.py", line 22, in init
eng = Engine(driverName, debug)
File "/opt/homebrew/lib/python3.9/site-packages/pyttsx3/engine.py", line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "/opt/homebrew/lib/python3.9/site-packages/pyttsx3/driver.py", line 50, in __init__
self._module = importlib.import_module(name)
File "/opt/homebrew/Cellar/python#3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/opt/homebrew/lib/python3.9/site-packages/pyttsx3/drivers/nsss.py", line 4, in <module>
from PyObjCTools import AppHelper
File "/opt/homebrew/lib/python3.9/site-packages/PyObjCTools/AppHelper.py", line 32, in <module>
from Foundation import (
ImportError: cannot import name 'NSAutoreleasePool' from 'Foundation' (unknown location)

Microphone driver in VM Ubuntu

I have installed pyttsx3 for my speech recognition project and even after successfully recording my audio terminal sends back a exception calling init.py.
With the help of SpeechRecognition I tried to build this program and it gives some error.
Traceback (most recent call last):
File "/home/cyclo97/trial/Translator/trans/lib/python3.8/site-packages/pyttsx3/__init__.py", line 20, in init
eng = _activeEngines[driverName]
File "/usr/lib/python3.8/weakref.py", line 131, in __getitem__
o = self.data[key]()
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "main.py", line 23, in <module>
speak_text(My_text)
File "main.py", line 8, in speak_text
engine = pyttsx3.init()
File "/home/cyclo97/trial/Translator/trans/lib/python3.8/site-packages/pyttsx3/__init__.py", line 22, in init
eng = Engine(driverName, debug)
File "/home/cyclo97/trial/Translator/trans/lib/python3.8/site-packages/pyttsx3/engine.py", line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "/home/cyclo97/trial/Translator/trans/lib/python3.8/site-packages/pyttsx3/driver.py", line 50, in __init__
self._module = importlib.import_module(name)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/cyclo97/trial/Translator/trans/lib/python3.8/site-packages/pyttsx3/drivers/espeak.py", line 9, in <module>
from . import _espeak, toUtf8, fromUtf8
File "/home/cyclo97/trial/Translator/trans/lib/python3.8/site-packages/pyttsx3/drivers/_espeak.py", line 18, in <module>
dll = cdll.LoadLibrary('libespeak.so.1')
File "/usr/lib/python3.8/ctypes/__init__.py", line 451, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python3.8/ctypes/__init__.py", line 373, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libespeak.so.1: cannot open shared object file: No such file or directory
This is the error but before that my program had executed fine.

ImportError: No system module 'pywintypes' (pywintypes38.dll)

I was making a python friend using pyttsx3, but I see the following error
raise ImportError("No system module '%s' (%s)" % (modname, filename))
ImportError: No system module 'pywintypes' (pywintypes38.dll)
Am using windows and python 3.Any help s quick as possible
the code is here
import pyttsx3
friend = pyttsx3.init()
speech = input ("Say Something: ")
friend.say(speech)
friend.runAndWait()
**error in vscterminal **
C:\Users\user\Desktop\Clive-main>C:/Users/user/AppData/Local/Programs/Python/Python38-32/python.exe c:/Users/user/Desktop/Clive-main/Clive-main/friend.py
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\__init__.py", line 20, in init
eng = _activeEngines[driverName]
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\weakref.py", line 131, in __getitem__
o = self.data[key]()
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:/Users/user/Desktop/Clive-main/Clive-main/friend.py", line 2, in <module>
friend = pyttsx3.init()
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\__init__.py", line 22, in init
eng = Engine(driverName, debug)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\engine.py", line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\driver.py", line 50, in __init__
self._module = importlib.import_module(name)
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\drivers\sapi5.py", line 10, in <module>
import pythoncom
File "C:\Users\user\AppData\Roaming\Python\Python38\site-packages\pythoncom.py", line 2, in <module>
import pywintypes
File "C:\Users\user\AppData\Roaming\Python\Python38\site-packages\win32\lib\pywintypes.py", line 136, in <module>
__import_pywin32_system_module__("pywintypes", globals())
File "C:\Users\user\AppData\Roaming\Python\Python38\site-packages\win32\lib\pywintypes.py", line 110, in __import_pywin32_system_module__
raise ImportError("No system module '%s' (%s)" % (modname, filename))
ImportError: No system module 'pywintypes' (pywintypes38.dll)
Just copy the 'pythoncom39.dll' and 'pywintypes39.dll' from this path (usually these files are located here)
C:\Users\yourUser\AppData\Roaming\Python\Python39\site-packages\pywin32_system32
to:
C:\Users\yourUser\AppData\Roaming\Python\Python39\site-packages\win32\lib
It worked for me. I hope this has been helpful.

pyttsx error (mac): cannot find module named foundation

This is my debut in programming, I searched extensively through stakoverflow in order to get an answer but I am kinda lost on this one.
I am trying to get pyttsx to work on my mac.
When i run the following code on python:
import pyttsx3
engine = pyttsx3.init()
engine.say("hello")
engine.runAndWait()
I get the following error message:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyttsx3/__init__.py", line 44, in init
eng = _activeEngines[driverName]
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/weakref.py", line 137, in __getitem__
o = self.data[key]()
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/philippedulbecco/Documents/Untitled.py", line 2, in <module>
engine = pyttsx3.init()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyttsx3/__init__.py", line 46, in init
eng = Engine(driverName, debug)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyttsx3/engine.py", line 52, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyttsx3/driver.py", line 75, in __init__
self._module = importlib.import_module(name)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/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 "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pyttsx3/drivers/nsss.py", line 2, in <module>
from Foundation import *
ModuleNotFoundError: No module named 'Foundation'
Any ideas how to fix this one?
Thanks in advance!
I can confirm devius's link helped. I had the exact same issue with pyttsx3 on osx. Installing PyObjC solved the problem for me.
pip install -U pyobjc
https://pythonhosted.org/pyobjc/install.html

Categories

Resources