首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在python中中断语音助手

如何在python中中断语音助手
EN

Stack Overflow用户
提问于 2021-03-01 04:11:34
回答 1查看 161关注 0票数 0

我正在构建一个可以讲故事的语音助手。当机器人在讲故事时,我想在中间打断它,要求它停止或倒退或结束故事。我尝试了几种方法,但它们都不起作用,我不能在说话的时候听,因为在说话的部分结束后,它进入了听的部分。

提前感谢

以下是我的代码

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2021-03-08 11:20:56

对于您正在使用的语音识别,这是不可能的。这种语音识别接受输入,不提供输出。使用您的输出系统,我假设它是类似pyttsx的东西,就像它被告知的那样。您将需要一个停止系统,并且您需要使用一个基于机器学习的程序来完成此操作,该程序能够进行对话,并且可以在被告知停止时停止,并将关键字作为命令。

我推荐Pytorch作为Python机器学习的入门工具。这是一篇关于会话人工智能的文章。

Article on Conversational AI with Pytorch

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66413414

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档