Skip to content
Related Articles

Related Articles

Improve Article
Speech Recognition in Hindi using Python
  • Difficulty Level : Hard
  • Last Updated : 26 Nov, 2020

We can use Python for Speech Recognition, it is mostly used to recognize English words. However, in this article, we are going to use Python so that it can also recognize Hindi words with the help of the Speech Recognition module. 


  • 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
  • PyAudio Module: It is a set of Python bindings for PortAudio, a cross-platform C++ library interfacing with audio drivers. We need to also install Pyaudio as the Speech Recognition module is dependent on it.
pip install PyAudio

If the above command doesn’t work in windows then use the below commands in the windows command prompt:

pip install pipwin
pipwin install pyaudio

We will use Google Speech Recognition API for letting the software understand Hindi. We will assign language as hn-IN.

Below is the complete Python program to take input commands in Hindi and to recognize them:


# import required module
import speech_recognition as sr
# explicit function to take input commands 
# and recognize them
def takeCommandHindi():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        # seconds of non-speaking audio before 
        # a phrase is considered complete
        r.pause_threshold = 0.7  
        audio = r.listen(source)  
            Query = r.recognize_google(audio, language='hi-In')
            # for listening the command in indian english
            print("the query is printed='", Query, "'")
        # handling the exception, so that assistant can 
        # ask for telling again the command
        except Exception as e:
            print("Say that again sir")
            return "None"
        return Query
# Driver Code
# call the function


 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :