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
Related
I have been trying to create a desktop assistant and trying to get it to speak. How can this error be fixed?
I have also tried commands like:
pip3 install pyttsx3
pip3 uninstall pyttsx3
pip3 install pyttsx3=.6
pip3 install pypiwin32
but nothing seemed to work
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyttsx3/__init__.py", line 20, in init
eng = _activeEngines[driverName]
~~~~~~~~~~~~~~^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/weakref.py", line 136, in __getitem__
o = self.data[key]()
~~~~~~~~~^^^^^
KeyError: 'sapi5'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/simrankataria/Desktop/test.py", line 2, in <module>
Assistant= pyttsx3.init('sapi5')
^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyttsx3/__init__.py", line 22, in init
eng = Engine(driverName, debug)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyttsx3/engine.py", line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyttsx3/driver.py", line 50, in __init__
self._module = importlib.import_module(name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pyttsx3/drivers/sapi5.py", line 1, in <module>
import comtypes.client # Importing comtypes.client will make the gen subpackage
^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/comtypes/__init__.py", line 28, in <module>
from _ctypes import COMError
ImportError: cannot import name 'COMError' from '_ctypes' (/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/lib-dynload/_ctypes.cpython-311-darwin.so)
I am trying to create an AI but I am stuck with this error.
my code:
import pyttsx3
Assistant= pyttsx3.init('sapi5')
voices = Assistant.getProperty('voices')
print(voices)
Assistant.setProperty('voices',voices[1].id)
def Speak(audio):
print(" ")
Assistant.say(audio)
print(" ")
Assistant.runAndWait()
Speak("Blah")
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.
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)
I was trying to do a basic voice script in Python, but it gives me an error and I think it is because of pyttsx3. Can someone help me?
Code:
def speak(text):
engine = pyttsx3.init()
engine.say(text)
engine.runAndWait()
Error:
Traceback (most recent call last):
File "main.py", line 153, in <module>
speak("Repita")
File "main.py", line 23, in speak
engine = pyttsx3.init()
File "/usr/local/lib/python3.8/dist-packages/pyttsx3/__init__.py", line 22, in init
eng = Engine(driverName, debug)
File "/usr/local/lib/python3.8/dist-packages/pyttsx3/engine.py", line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "/usr/local/lib/python3.8/dist-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 "/usr/local/lib/python3.8/dist-packages/pyttsx3/drivers/espeak.py", line 9, in <module>
from . import _espeak, toUtf8, fromUtf8
File "/usr/local/lib/python3.8/dist-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
It's because you don't have espeak installed on your system. That's why it is giving error
libespeak.so.1 error: no such file or directory found.
Try to install espeak using:
sudo apt-get update && sudo apt-get install espeak
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