Using Python is fun. In a matter of minutes, I was able to build a rudimentary speech to text recognition app, for Tamil. And after that, in reverse, that is, to speak out loud a sentence of given Tamil text.

Speech to Text:

I got the base code from here. You need to install SpeechRecognition package (available through PIP) and PyAudio (available through PIP in Linux, but on Windows, you need to install appropriate package from here).

# Speech To Text — Python
# pip install SpeechRecognition
# Download PyAudio from https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio
# pip install PyAudio-0.2.11-cp37-cp37m-win_amd64.whl and NOT pip install PyAudio (Works only in Linux)

import speech_recognition as sr 
r = sr.Recognizer()
with sr.Microphone() as source:
    print ("Say Something in Tamil and pause, no need to press any key")
    audio = r.listen (source)
    print ("Got you")
try:
    WhatUSpoke = r.recognize_google (audio, language="ta-IN")
    print ("What you spoke (Google):", WhatUSpoke)
except:
    pass

Text to Speech:

When I posted the above code, I got a reader request for a code that does the reverse – to speak out loud a sentence of given Tamil text. I have given this below. I got the base code from here. You need to install gTTS package (available through PIP). The code uses os.system to play the output audio file, this command works out of the box in Windows, in Linux you may need a command-line player like MPG321 (which can be installed using sudo apt-get install mpg321)

#Reference: https://www.thecrazyprogrammer.com/2018/05/python-text-to-speech.html 
#pip  install gTTS 

import gtts as gt 
import os      

TamilText="வணக்கம்.அறம் செய விரும்பு, ஆறுவது சினம், இயல்வது கரவேல், ஈவது விலக்கேல், உடையது விளம்பேல். நன்றி!"
tts = gt.gTTS(text=TamilText, lang='ta')
tts.save("Tamil-Audio.mp3")
os.system("Tamil-Audio.mp3")

You can listen to the output audio that’s produced by the code above, below:

The above was possible, thanks, to the numerous readymade packages that are available for free, and, the magic of cloud – in these two cases I am using Google Cloud, which required no configuration or key for trial runs. You may use Bing if you have an Azure API key.

Speech to Text in Python and its output
Speech to Text in Python and its output
Tamil Text to Speech in Python
Tamil Text to Speech in Python

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.