我正在构建一个可以讲故事的语音助手。当机器人在讲故事时,我想在中间打断它,要求它停止或倒退或结束故事。我尝试了几种方法,但它们都不起作用,我不能在说话的时候听,因为在说话的部分结束后,它进入了听的部分。
提前感谢
以下是我的代码
while True:
r = sr.Recognizer()
with sr.Microphone() as source:
print("Talk")
audio_text = r.listen(source)
print("Time over, thanks")
try:
inp=r.recognize_google(audio_text, language = "en-IN")
print("Text: "+inp)
except:
inp="sorry"
print("Sorry, I did not get that")
if inp.lower() == "quit":
bot_voice("Ok bye see you later")
break
if inp.lower() == "sorry":
bot_voice("Sorry, I did not get that")
if (deter==0):
y=-1
deter=1
for x in stories:
m=x
y=m.find(inp)
if(y>-1):
filename = 'Stories/data/'+x+'.txt'
with open(filename) as f_in:
for line in f_in:
bot_voice(line)
break
else:
results = model.predict([bag_of_words(inp, words)])
results_index = numpy.argmax(results)
tag = labels[results_index]
for tg in data["intents"]:
if tg['tag'] == tag:
responses = tg['responses']
reply=random.choice(responses)
if(reply=='7417'):
filename = "Stories/list.txt"
bot_voice("I know quite a few stories, they are")
with open(filename) as f_in:
for x,line in enumerate(f_in):
bot_voice(line)
bot_voice("which one you want")
deter=0
else:
print("bot:",reply)
bot_voice(reply)发布于 2021-03-08 11:20:56
对于您正在使用的语音识别,这是不可能的。这种语音识别接受输入,不提供输出。使用您的输出系统,我假设它是类似pyttsx的东西,就像它被告知的那样。您将需要一个停止系统,并且您需要使用一个基于机器学习的程序来完成此操作,该程序能够进行对话,并且可以在被告知停止时停止,并将关键字作为命令。
我推荐Pytorch作为Python机器学习的入门工具。这是一篇关于会话人工智能的文章。
https://stackoverflow.com/questions/66413414
复制相似问题