Create a real time voice translator using Python
In this article, we are going to create a real-time voice translator in Python.
- playsound: This module is used to play sound in Python
pip install playsound
- Speech Recognition Module: It is a library with the help of which Python can recognize the command given. We have to use pip for Speech Recognition.
pip install SpeechRecognition
- googletrans: Googletrans is a free and unlimited python library that implemented Google Translate API
pip install googletrans
- gTTs: The gTTS API supports several languages including English, Hindi, Tamil, French, German and many more.
pip install gTTs pip install gTTS-token
A real-time voice translator that can translate voice input and give translated voice output generated from it. It is created using google’s googleTrans API and speech_recognition library of python. It converts text from one language to another language and saves its mp3 recorded file. The playsound module is then used to play the generated mp3 file, After that, the generated mp3 file is deleted using the os module.
Step 1: Importing Necessary Modules
Step 2: A tuple of all the languages mapped with their code
Step 3: Taking voice commands from the user
Step 4: Taking voice input from the user
Step 5: Input destination language from the user, Mapping user input with the language code
Step 6: Invoking Translator
Step 7: Translating from src to dest
Step 8: Saving Translated files and deleting them after playing
Below is the full implementation: