如果用户第一次不理解,如何在语音识别中重复该问题?蟒蛇

问题描述

我正在为语音聊天机器人使用Speech_recognition模块。以下是我的代码

import pyttsx3
import speech_recognition as sr 
import os

engine = pyttsx3.init('sapi5') 
voices = engine.getProperty('voices') 
engine.setProperty('voice',voices[0].id)

def speak(audio):
    engine.say(audio)
    engine.runAndWait() 

def takeCommand(): 
      
    r = sr.Recognizer() 
      
    with sr.Microphone() as source: 
          
        print("Listening...") 
        r.pause_threshold = 1
        r.adjust_for_ambient_noise(source)
        audio = r.listen(source)
        print(audio)
   
    try: 
        print("Recognizing...")     
        query = r.recognize_google(audio,language ='en-in') 
        print("User said:",query) 
   
    except Exception as e: 
        print(e)     
        print("Unable to Recognizing your voice.")   
        return "None"
      
    return query 

if __name__ == '__main__': 
    clear = lambda: os.system('cls')
    while True: 
          
        query = takeCommand().lower() 

        if 'how are you' in query: 
            speak("I am fine,Thank you") 
            speak("How are you,Sir") 
  
        elif ......

如果用户说出[对不起/请原谅/请重复/我没有得到你/再来一次-重复问题等],而不是回答你怎么样,那么我该如何做才能使其再重复一次同样的问题? 谢谢。我是使用Speech_recognition的新手

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)