0

The same code is working on my local machine(Windows) but when running the same on AWS Linux after installing Pyttsx3, it is not working.

    import pyttsx3
    engine = pyttsx3.init() 
    engine.say("I will speak this text")
    engine.runAndWait()

this is the sample code. I am new to AWS and LINUX.

And this is the error:

Traceback (most recent call last):
  File "/home/ec2-user/st_env/env/lib64/python3.6/site-packages/pyttsx3/__init__.py", line 20, in init
    eng = _activeEngines[driverName]
  File "/usr/lib64/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 "<stdin>", line 1, in <module>
  File "/home/ec2-user/st_env/env/lib64/python3.6/site-packages/pyttsx3/__init__.py", line 22, in init
    eng = Engine(driverName, debug)
  File "/home/ec2-user/st_env/env/lib64/python3.6/site-packages/pyttsx3/engine.py", line 30, in __init__
    self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
  File "/home/ec2-user/st_env/env/lib64/python3.6/site-packages/pyttsx3/driver.py", line 50, in __init__
    self._module = importlib.import_module(name)
  File "/usr/lib64/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 "/home/ec2-user/st_env/env/lib64/python3.6/site-packages/pyttsx3/drivers/espeak.py", line 9, in <module>
    from . import _espeak, toUtf8, fromUtf8
  File "/home/ec2-user/st_env/env/lib64/python3.6/site-packages/pyttsx3/drivers/_espeak.py", line 18, in <module>
    dll = cdll.LoadLibrary('libespeak.so.1')
  File "/usr/lib64/python3.6/ctypes/__init__.py", line 421, in LoadLibrary
    return self._dlltype(name)
  File "/usr/lib64/python3.6/ctypes/__init__.py", line 343, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libespeak.so.1: cannot open shared object file: No such file or directory
    

EDIT: this OSError: libespeak.so.1: error is there because the espeak engine is not installed on the machine(as suggested by other Stackoverflow post), is there any way to install espeak than sudo yum install espeak ?

Shivam purbia
  • 228
  • 4
  • 13

1 Answers1

0

I have tested the below commands on the amazon ec2 instance with host os Amazon Linux 2 and also tested your sample python code which runs successfully.

If your host system is Amazon Linux 2 then you can install espeak using the below commands :

   __|  __|_  )
   _|  (     /   Amazon Linux 2 AMI
  ___|\___|___|

[ec2-user@aws ~]$ rpm -E %{rhel}
7                                            --> as you can see here its based on RHEL 7

[ec2-user@aws ~]$ yum list espeak
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Available Packages
espeak.i686                                                            1.47.11-4.amzn2.0.2                                                          amzn2-core
espeak.x86_64                                                          1.47.11-4.amzn2.0.2                                                          amzn2-core

Here you can see the espeak package is available on Amazon Linux. So you need to install it using the below command :

ec2-user@aws ~]$ sudo yum -y install espeak
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Resolving Dependencies
--> Running transaction check
---> Package espeak.x86_64 0:1.47.11-4.amzn2.0.2 will be installed
--> Processing Dependency: libpulse.so.0(PULSE_0)(64bit) for package: espeak-1.47.11-4.amzn2.0.2.x86_64
--> Processing Dependency: libpulse.so.0()(64bit) for package: espeak-1.47.11-4.amzn2.0.2.x86_64
--> Running transaction check
---> Package pulseaudio-libs.x86_64 0:10.0-3.amzn2.0.3 will be installed
--> Processing Dependency: libsndfile.so.1(libsndfile.so.1.0)(64bit) for package: pulseaudio-libs-10.0-3.amzn2.0.3.x86_64
--> Processing Dependency: libxcb.so.1()(64bit) for package: pulseaudio-libs-10.0-3.amzn2.0.3.x86_64
--> Processing Dependency: libsndfile.so.1()(64bit) for package: pulseaudio-libs-10.0-3.amzn2.0.3.x86_64
--> Processing Dependency: libasyncns.so.0()(64bit) for package: pulseaudio-libs-10.0-3.amzn2.0.3.x86_64
--> Processing Dependency: libXtst.so.6()(64bit) for package: pulseaudio-libs-10.0-3.amzn2.0.3.x86_64
--> Processing Dependency: libX11.so.6()(64bit) for package: pulseaudio-libs-10.0-3.amzn2.0.3.x86_64
--> Processing Dependency: libX11-xcb.so.1()(64bit) for package: pulseaudio-libs-10.0-3.amzn2.0.3.x86_64
...

OR

yum localinstall http://mirror.centos.org/centos/7/os/x86_64/Packages/espeak-1.47.11-4.el7.x86_64.rpm

And it will install the package espeak.

Girish
  • 366
  • 3
  • 15
  • No, when I run "sudo yum install espeak". it says No package espeak available. – Shivam purbia Jan 22 '21 at 10:07
  • You can download the `espeak` rpm package from [here](https://centos.pkgs.org/7/centos-x86_64/espeak-1.47.11-4.el7.x86_64.rpm.html) and you can install it directly using `yum install FILE.rpm` – Girish Jan 22 '21 at 10:16
  • Man, there are 2 packages: Binary and Source, which one should I go for? – Shivam purbia Jan 22 '21 at 10:37
  • use binary package. You can also run `yum search espeak` or `yum list *espeak*` to find out if it has some different name available on Amazon Linux. – Girish Jan 22 '21 at 11:20
  • If you download the source package then you first need to compile it and then install it if you are familiar with the `configure-make-make install` method. – Girish Jan 22 '21 at 11:23
  • I Downloaded the Binary and tried to install it but there are two libs/dependencies that need to be installed, and when I am installing those libs using the same method they further require some other libs. :-( – Shivam purbia Jan 22 '21 at 13:52
  • Have you tried searching for the package using `yum`? As per what I know Amazon Linux is based on CentOS and the CentOS/RHEL repo has the package `espeak`. If not try to install dependencies manually as mentioned in the [post](https://centos.pkgs.org/7/centos-x86_64/espeak-1.47.11-4.el7.x86_64.rpm.html). As your code is trying to access some Linux library `.so` file you only need to install `espeak` somehow. – Girish Jan 22 '21 at 14:34
  • I have updated my answer as you are running your code on Amazon Linux. – Girish Jan 22 '21 at 14:53
  • still NO packages available when running yum search espeak or yum list *espeak* , and when checked the version by cat /etc/os-release command it displays (env) [ec2-user@ip-172-31-10-224 ~]$ cat /etc/os-release NAME="Amazon Linux AMI" VERSION="2018.03" ID="amzn" ID_LIKE="rhel fedora" VERSION_ID="2018.03" PRETTY_NAME="Amazon Linux AMI 2018.03" – Shivam purbia Jan 23 '21 at 08:02
  • can you share with me the output of `rpm -E %{rhel}`? – Girish Jan 23 '21 at 09:11
  • also, run `yum repolist` and see if this `!amzn2-core/2/x86_64 ` repo is present on your machine – Girish Jan 23 '21 at 09:41
  • @Shivampurbia, at last, you can try this `yum localinstall http://mirror.centos.org/centos/7/os/x86_64/Packages/espeak-1.47.11-4.el7.x86_64.rpm` hope this will resolve the problem. – Girish Jan 23 '21 at 10:59