def readMenu(xmldoc, menu_node): speak("This is the " + menu_node.getAttribute("name") + " menu.") speak(menu_node.getAttribute("value")) time.sleep(1) # the following loop print all the child nodes(which are the current menu) for child in menu_node.childNodes: if isinstance(child,minidom.Element): speak(child.getAttribute("name")) count=clap.listenAndCount(2) if count==1: return child if count==2: return parentNode(xmldoc, menu_node) speak("Menu Over.") speak("Clap to repeat") if menu_node!=xmldoc.firstChild: speak("Or clap twice to go back") claps=clap.waitForClaps() if claps>=2: return parentNode(xmldoc, menu_node) return menu_node
def readDish(xmldoc, dish_node): speak("You have chosen to cook a " + current.getAttribute("name") + " " + current.parentNode.getAttribute("name")) speak("Clap once to start cooking.") speak("Clap twice to hear the ingredients list.") speak("Clap 3 times to return to the menu") claps=clap.listenAndCount(3) while (claps==0): speak("I didn't get it.") speak("Please clap again.") claps=clap.listenAndCount(3) if claps==1: return dish_node.getElementsByTagName('method')[0] elif claps==2: return dish_node.getElementsByTagName('ingredients')[0] # 3+ return parentNode(xmldoc, dish_node)
if claps>1: return parentNode(xmldoc, method_node) time.sleep(1) speak("Clap twice to return to the dish menu") return parentNode(xmldoc, method_node) ##################################### MAIN #################################### time.sleep(1) speak("Good morning sir. I will assist you cooking."); speak("This system is based on clapping.") speak("for start, please clap") while (clap.listenAndCount(3)==0): speak("I didn't get it.") speak("Please clap again.") speak("Great.") speak("From now on, clap when you want to enter a certain menu or dish.") speak("You can clap twice to return to the previous menu.") time.sleep(1) xmldoc = minidom.parse('recipe.xml') current = xmldoc.firstChild # dishes = current.getElementsByTagName('dish'); # for dish in dishes: # if dish.getAttribute("name")=="tomato": # current=dish