0

I just began learning about text to speech in python but faced this error

Traceback (most recent call last):
  File "/home/mc_aidin/.var/app/com.jetbrains.PyCharm-Community/data/virtualenvs/TTS-D2o8uR9j/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 "/home/mc_aidin/PycharmProjects/TTS/TTS.py", line 2, in <module>
    speaker = pyttsx3.init()
  File "/home/mc_aidin/.var/app/com.jetbrains.PyCharm-Community/data/virtualenvs/TTS-D2o8uR9j/lib/python3.8/site-packages/pyttsx3/__init__.py", line 22, in init
    eng = Engine(driverName, debug)
  File "/home/mc_aidin/.var/app/com.jetbrains.PyCharm-Community/data/virtualenvs/TTS-D2o8uR9j/lib/python3.8/site-packages/pyttsx3/engine.py", line 30, in __init__
    self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
  File "/home/mc_aidin/.var/app/com.jetbrains.PyCharm-Community/data/virtualenvs/TTS-D2o8uR9j/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/mc_aidin/.var/app/com.jetbrains.PyCharm-Community/data/virtualenvs/TTS-D2o8uR9j/lib/python3.8/site-packages/pyttsx3/drivers/espeak.py", line 9, in <module>
    from . import _espeak, toUtf8, fromUtf8
  File "/home/mc_aidin/.var/app/com.jetbrains.PyCharm-Community/data/virtualenvs/TTS-D2o8uR9j/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

Process finished with exit code 1

I do have espeak installed but for some reason, I still get this error I'm using Python 3.8.2 and my operating system is Pop os 20.04 (it's ubuntu based so ubuntu fixes should work)

EDIT: The code I'm trying to run is:

import pyttsx3
speaker = pyttsx3.init()
  • Can you provide the code that throws this error? We can't not find the core problem from the Exception solely. – Darkborderman Sep 26 '20 at 18:41
  • The code won't really help -- we need to know if the C library is installed, and if so, _how_ the OP installed it; and similarly, how they installed the Python library that's trying to use that C library. – Charles Duffy Sep 26 '20 at 18:58
  • @AidinShaikhi, ...note that if you're installing Ubuntu packages on an Ubuntu-derivative OS, they need to be built _for the same version of Ubuntu that your derivative distro is built from_ (assuming that said derivative distro does in fact have a policy of maintaining ABI compatibility; if it doesn't, all bets are off). – Charles Duffy Sep 26 '20 at 19:00
  • @AidinShaikhi, ...alternately, you could use a completely different package manager to set up your Python install with libespeak. If you were willing to use [Nix](https://nixos.org/) on top of Ubuntu or PopOS, f/e, I'd be glad to build you a Nix derivation that builds both pyttsx3 and its dependencies (including espeak). – Charles Duffy Sep 26 '20 at 19:06
  • 1
    See https://stackoverflow.com/a/36227264/11667949 – Shivam Jha Sep 26 '20 at 19:13
  • @ShivamJha I've done everything instructed in that page – Aidin Shaikhi Sep 26 '20 at 19:20
  • @AidinShaikhi, that information needs to be included in the question, as well as further specifics: Exactly which version of `libespeak.so.1` was installed by following those steps, _where_ it's installed; and which version of `libespeak.so.1` your Python module is looking for. – Charles Duffy Sep 26 '20 at 19:21
  • @AidinShaikhi, ...one place to start in answering the "where" question is `dpkg -L libespeak1`, which will show you all the files that package installed. (If it tells you that `libespeak1` _isn't_ installed, that would be evidence that the steps described by the answers to the linked question _were not_ in fact followed). – Charles Duffy Sep 26 '20 at 19:21
  • @CharlesDuffy I don't think the problem is the os. I can run espeak in the terminal. I suspect that the library can't find or access the files needed properly. – Aidin Shaikhi Sep 26 '20 at 19:22
  • @AidinShaikhi, here's the thing: The copy of `espeak` you run in the terminal was built alongside your copy of `libespeak` that it was linked against. That's potentially different from the version of `libespeak` that your Python library needs, so having a working `/usr/bin/espeak` does not prove that you have a working `libespeak1`; it could instead be linked against `libespeakng` or something else. – Charles Duffy Sep 26 '20 at 19:23
  • @AidinShaikhi, ...you can run `ldd /usr/bin/espeak` (adjusting the path as appropriate to have the location of your real espeak binary) to find out which version of `libespeak` your `espeak` terminal command uses (if any; if it was statically built it may not use or include any copy of `libespeak` at all). – Charles Duffy Sep 26 '20 at 19:23
  • @CharlesDuffy /usr/lib/x86_64-linux-gnu/libespeak.so.1.1.48 – Aidin Shaikhi Sep 26 '20 at 19:24
  • Hmm. Is there a symlink to it called `/usr/lib/x86_64-linux-gnu/libespeak.so.1`? If not, does creating such a symlink fix your problem? If creating the symlink doesn't fix the problem, does running `export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu` before starting your Python interpreter in the same window make any difference? – Charles Duffy Sep 26 '20 at 19:26
  • BTW, if that symlink doesn't exist, I'd report it as a bug to your distro (or whoever else made the espeak package you installed). – Charles Duffy Sep 26 '20 at 19:29
  • @CharlesDuffy Looks like my IDE was causing this problem I changed it and the code runs fine now. Thank you and sorry I've wasted your time – Aidin Shaikhi Sep 26 '20 at 19:41

0 Answers0