Audio Book Generation and Translation using Python

Audio Book Generation and Translation using Python

The blog is divided into 2 parts:

  1. How to convert a pdf file into an audio file using python pyttsx3 library
  2. How to translate and convert the pdf file written in Spanish to English using google trans

Let's start with pyttsx3 is a text-to-speech conversion library in Python. Unlike alternative libraries, it works offline and is compatible with both Python 2 and 3.

Installation

pip install pyttsx3

If you receive errors such as No module named win32com.client, No module named win32, or No module named win32api, you will need to additionally install pypiwin32.

Usage :

import pyttsx3
engine = pyttsx3.init()
engine.say("I will speak this text")
engine.runAndWait()
No alt text provided for this image

This is the snippet of the code with the comments, you can find the code on my https://github.com/isheegattani

Isn't it cool? Whenever we feel lazy to read a book or an article we can just paste the link of it in our code and execute our program, python will read out loud for you as ur helper.

Now, let's try to read a Spanish story.

Oops how will I understand, I don't know Spanish, are you in the same boat, don't worry ur python code will help you here using GoogleTrans

Google trans is a free and unlimited python library that implemented Google Translate API. This uses the Google Translate Ajax API to make calls to such methods as detecting and translate.

Compatible with Python 3.6+.

For details refer to the API Documentation.

Features

  • Fast and reliable - it uses the same servers that translate.google.com uses
  • Auto language detection
  • Bulk translations
  • Customizable service URL
  • HTTP/2 support

Installation

To install, either use things like pip with the package “googletrans” or download the package and put the “googletrans” directory into your python path.

$ pip install googletrans

Now that we have the package, we are ready to import it into our python script.

from googletrans import Translator

Here is the code snippet of how to make the translation easy.

No alt text provided for this image

This is how the conversion is done. You can play around with the library and explore more features and even make use of Python GUI using Tkinter. This is all about creating a Translator using Python. That's it! simple, isn't it? Hope this tutorial has helped.

You can find all the code on my Github Repo

Thank you for reading, I would love to connect with you on LinkedIn.

Do share your valuable feedback and suggestions!

Resources:


To view or add a comment, sign in

More articles by Ishee Gattani

  • YouTube Downloader with Python

    If you don't have youtube premium but know how to code in python then you can easily download the videos on your local…

    2 Comments

Others also viewed

Explore content categories