使用Python进行印地语语音识别
我们可以使用Python进行语音识别,它主要用于识别英语单词。但是,在本文中,我们将使用Python以便它也可以在语音识别模块的帮助下识别印地语单词。
要求:
- 语音识别模块:它是一个库, Python可以借助它来识别给定的命令。我们必须使用 pip 进行语音识别。
pip install SpeechRecognition
- PyAudio 模块:它是 PortAudio 的一组Python绑定, PortAudio是一个与音频驱动程序接口的跨平台 C++ 库。我们还需要安装Pyaudio ,因为语音识别模块依赖于它。
pip install PyAudio
如果上述命令在 windows 中不起作用,则在 windows 命令提示符下使用以下命令:
pip install pipwin
pipwin install pyaudio
我们将使用Google Speech Recognition API让软件理解印地语。我们将语言指定为hn-IN。
下面是完整的Python程序,用于获取印地语中的输入命令并识别它们:
Python3
# 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
print('Listening')
r.pause_threshold = 0.7
audio = r.listen(source)
try:
print("Recognizing")
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(e)
print("Say that again sir")
return "None"
return Query
# Driver Code
# call the function
takeCommandHindi()
输出: