Using pyttsx3 in Anvil

Hello,

Has anyone successfully used pyttsx3 module in their Anvil app?
I tried doing a simple test from their examples page after installing the pyttsx3 module, however I get an error:

OSError: libespeak.so.1: cannot open shared object file: No such file or directory

My code (in server module):

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

It seems “espeak” is a dependency of this library? I tried adding “espeak” package to the app, however the closest thing available was “espeakng”. Unfortunately the error did not get resolved.

The error seems to be a runtime error, that is the modules are installed and imported correctly, but it fails to do its job at runtime.

Judging by the message, it looks like it’s looking for a file that doesn’t exist.

Have you tried running the same function locally?

Locally meaning in client-side code? Yes, but then I got an error that “not on all modules can be run in client-side code” or something like that.

No, locally making in your computer.

What you are doing here will only be able to play the speech on server side. Instead, you will have to save the output as a audio file and then return it on client side.

There is a similar example that uses gtts instead of pyttsx3

1 Like

This would likely be more effectively completed with JavaScript on the client side.