Using python to solve a old neighbour problem.

Chew Lin Kiat
3 min readApr 2, 2021

My old chinese neighbour has a problem. He can only read chinese. He has a grand daughter studying in Australia and he misses her dearly. While he is able to use whatsapp to do video calls with her, he misses her whenever she is offline. Also, he is afraid to talk to her too much online for fear of affecting her studies.

So, he has requested for her to write to him on email. He will print out and read these emails whenever he misses her. Perhaps, old habits die hard as he has not been comfortable reading news or emails on tablets or in a computer. As these emails werewritten in english, he would prefer to have it written in chinese for him to read. He asked me for help, as he knows I am working in the IT industry. His request is simple. To have a way to convert these emails to chinese, so that he can print it out to read.

He handed me these emails. I thought of copying and pasting it in google translate and print it out in chinese. But, it will not be efficient, as it means manually copy and pasting each letter. Also, at his age, reading with the use of reading glasses will strain his eyes.

I have decided to explore another way. Is it possible to use python coding in this situation.

For privacy considerations, I have used a snippet from an online news article to stimulate the emails to translate. See below for the news article.

News article from Microsoft news: PM Lee on tudung issue: Changes must be carefully considered (msn.com)

I will translate the words in bold from the news article. See below in quotes for the text to translate.

“He also acknowledged social attitudes and norms evolve….religious harmony”

These words will be translated in chinese using python. After that, I will get python to read out the words in chinese using a female voice.

My old neighbour has printed out these emails, so I have to scan or take photos of these emails to put them into the python program. It means these emails are images and not text. Hmm… how to extract texts from images?

Python has a module to read text from image. It is called pytesseract. Python-tesseract is an optical character recognition (OCR) tool for python. It will recognize and “read” the text embedded in images. Please click the link here to read the docs.pytesseract · PyPI

To use pytesseract, you have to do pip install pytesseract.

Also, you have to install Tesseract from the github link here Home · UB-Mannheim/tesseract Wiki (github.com). Do select the appropriate install versions 32bit or 64bit for your computer.

Once completed the installation, its time to work on the image. I have set up the python codes below using the Anaconda notebook. The news article is saved in a png format. After that, I have used the pytesseract module to extract the words in the image to text.

Converting image to text.

To convert the text to chinese, we can use the google translator module. See the output below once the text is converted to chinese. I am pleasantly surprised by its accurate translation.

English text converted to chinese.

How about reading the text in chinese? To do this, you would have to install pyttsx3. Pyttsx3 will read out your text just like google translate, in the language you have specified. Also, you can specify whether its a male or female voice from your computer.

The result was better than I have expected. I have helped to solve this simple problem using python. My old neighbour was glad to have these emails read to him and he need not put on his reading glasses.

I have put the above source code in my github. Click here to get the codes.

Do contact me on linkedin , if you want to connect to me.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response