import FSM import JuliusProxy import subprocess import searchword import webbrowser searcher = searchword.Search("database.pickle") nobrowser = True def showresult(inp): if searcher.find(unicode(inp[1]["WORD"], "utf-8")): print searcher.showTEXT() fh = open("result.html", "w") fh.writelines(searcher.showHTML().encode("utf-8")) fh.close() global nobrowser if nobrowser: webbrowser.open("result.html") nobrowser = False else: print unicode(inp[1]["WORD"], "utf-8"), "not found." def getClassID(inp): return inp[1]["CLASSID"] # construct and add transition rules wait = FSM.State() search = FSM.State() echo = "python python/echo.py " wait.setTransition(getClassID, [0,7], search, echo + "search start") search.setTransition(getClassID, [7], search, showresult) search.setTransition(getClassID, [3], wait, echo + "search end") # construct Finite State Machine and register the states. fsm = FSM.FSM() fsm.setState(wait) fsm.setState(search) # connect to julius print "Connecting Julius...", proxy = JuliusProxy.JuliusProxy() print "done" while 1: proxy.getResult() # get ASR result result = proxy.parseResult() # parse ASR result if result == []: continue for r in result: for key in r.keys(): if key == "WORD": print key, ":", unicode(r[key], "utf-8"), ",", else: print key, ":", r[key], ",", print # give the result to FSM fsm.feed(result)