Talking Python Logging Handler

Barnabás Nagy
1 min readDec 12, 2020

If your python scripts runs on a machine with a speaker to you, the scripts don’t need to be silent during the run. Besides the boring command line and log file output of logging messages, let’s make it interesting!

The idea is simple: let’s combine a text-to-speech engine with the logging of Python. We will use a free and offline tts engine, the pyttsx3. This is offline, so no internet traffic will need it to be used. The cons are, it is only in English and there are much better tts voices out there at the cloud service providers.

Anyway, let’s install the package via pip first:

Create a custom handler for logging using the talking engine. It initiates with the second (female) voice, but you can change it if you prefer hearing mail machine voice. Also, my usual logging format contains some extra info in each messages with added with tab delimiters, but we need to hear only the core part of the logging message.

Then add the new handler to the list of logging (next to the stdout — the command line out one):

That’s it, now your script talks when there is a logging message!

--

--

Barnabás Nagy

I’m an intl PM in localization, BI Developer and a certified Google Professional Data Engineer. My hobby projects: Data apps, open source apps and DIY stuffs