def doYouWantToContinue(): playAudio("addmore.wav") chck = None speechToText=None speechToText = recognize() print(speechToText) if speechToText == "unknown error occured": doYouWantToContinue() speechToText = None else: tranlatedText = trans(speechToText) temp = tranlatedText.upper() if len(temp) != 0: x1 = temp.split() regex = re.compile("YES|NO|SURE|SURELY|OFCOURSE|CERTAINLY|SOMETIMES|NEVER|NOT|NOPE|ABSOLUTELY|NOTHING|NAI") word = regex.findall(temp) if len(word) != 0: if (word[0] == 'YES' or word[0] == "SOMETIMES" or word[0] == "SURE" or word[0] == "SURELY" or word[0] == "CERTAINLY" or word[0] == "ABSOLUTELY"): audioFile = 'afteraddmore.wav' playAudio(audioFile) speechToText = recognize() print(speechToText) if speechToText == "unknown error occured": audioFile = 'afteraddmore.wav' speechToText = None else: from Product import identifyProduct translatedText = trans(speechToText) identifyProduct(translatedText) elif (word[0] == 'NO' or word[0] == "NEVER" or word[0] == "NOT" or word[0] == "NOPE" or word[0] == "NOTHING"): print('Thank You your Order is Placed') else: doYouWantToContinue()
def acceptQuantityKg(prd): quantity = None playAudio('audiokg.wav') quantity = recognize() print(quantity) if quantity == "unknown error occured": acceptQuantityKg(prd) else: identifyQuantity(quantity, prd)
def acceptQuantityLt(prd): quantity = None playAudio('audiolit.wav') quantity = recognize() if quantity == "unknown error occured": acceptQuantityLt(prd) else: identifyQuantity(quantity, prd)
def identifyProduct(translatedText): finalProduct = str(number) flg = None product = translatedText.upper() temp = product if len(temp) != 0: x1 = temp.split() if len(x1) != 0: f1 = open('productkg.csv') csv_f1 = csv.reader(f1) prd = None for column in csv_f1: for y in x1: y = y.capitalize() if y == column[0]: prd = y flg = 1 finalProduct = finalProduct + "" + prd f1 = open('productlit.csv') csv_f1 = csv.reader(f1) if flg == None: for column in csv_f1: for y in x1: y = y.capitalize() if y == column[0]: prd = y flg = 2 finalProduct = finalProduct + "" + prd f1 = open('productpc.csv') csv_f1 = csv.reader(f1) if flg == None: for column in csv_f1: for y in x1: y = y.capitalize() if y == column[0]: prd = y flg = 3 finalProduct = finalProduct + "" + prd if (flg == 1): acceptQuantityKg(finalProduct) elif (flg == 2): acceptQuantityLt(finalProduct) elif (flg == 3): acceptQuantityPc(finalProduct) else: playAudio("notinlist.wav") import onlineOrder onlineOrder.orderStart(1)
def orderStart(flg): if flg == 0: audioFile = 'ordertitle.wav' elif flg == 1: audioFile = 'afteraddmore.wav' playAudio(audioFile) speechToText = recognize() print(speechToText) if speechToText == "unknown error occured": orderStart(0) speechToText = None else: translatedText = trans(speechToText) identifyProduct(translatedText)
def recognize(): r = sr.Recognizer() try: with sr.Microphone() as source2: print("say Something....") playAudio('beep.wav') audio2 = r.listen(source2, timeout=8) MyText = r.recognize_google(audio2) x = MyText except sr.RequestError as e: print("Could not request results; {0}".format(e)) x = "Could not request results; {0}".format(e) except sr.UnknownValueError: x= "unknown error occured" return x