【问题标题】:How to make custom speech recognition in python?如何在python中进行自定义语音识别?
【发布时间】:2020-04-24 09:14:10
【问题描述】:
我尝试了以下代码:
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source)
print("Say something!")
audio = r.listen(source)
try:
text = r.recognize_google(audio)
print("You said: {}".format(text))
except:
print("Sorry")
这段代码运行良好,可以打印我所说的任何内容。
但我想要类似的东西:
If someone says: i want to create a new article / create a new article /create article....
类似的东西
然后我想得到如下输出:
create a new article
基本上我想知道如何做到这一点(步骤)或哪些模块可以帮助我。
感谢任何帮助
【问题讨论】:
标签:
python
nlp
artificial-intelligence
speech-recognition
【解决方案1】:
这是更新后的代码@Nitin Singhal
import speech_recognition as sr
#Speech Recognition Module
r = sr.Recognizer()
#Initializing r as a Recognizer()
with sr.Microphone() as source:
r.adjust_for_ambient_noise
print("Say Something")
audio = r.listen(source)
#Gets the Audio Input
try:
text = r.recognize_google(audio)
text = text.lower()
print("You said: {}".format(text))
#Recognizes the speech(Intenet required)
if text == "i want to create a new article" or "create a new article" or "create article":
print("Create new article")
#Displays the desired output
except:
print("Sorry")
#In case any error, prints this
您可以像我在if 语句中给出的那样给出尽可能多的语句。这给出了所需的输出。