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.
Requirements:
- 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:
Python3
import speech_recognition as sr
def takeCommandHindi():
r = sr.Recognizer()
with sr.Microphone() as source:
print ( 'Listening' )
r.pause_threshold = 0.7
audio = r.listen(source)
try :
print ( "Recognizing" )
Query = r.recognize_google(audio, language = 'hi-In' )
print ( "the query is printed='" , Query, "'" )
except Exception as e:
print (e)
print ( "Say that again sir" )
return "None"
return Query
takeCommandHindi()
|
Output: