rendered paste bodyimport asyncore, os, re, sgmllib, socket, string, subprocess, sys, time, xml.dom.minidomjulius_home=os.getenv("JULIUS_HOME", "/usr/lib/julius")julius_model=julius_home + "/model/julian.jconf"julius_port=""#Startif julius_port == "": julius_port = 10500julius_cmd="julius -input mic -quiet -nolog -C "+julius_model+" -module "+str(julius_port)juli_proc = subprocess.Popen([julius_cmd], shell=True, stdin=subprocess.PIPE, stderr=subprocess.PIPE, stdout=subprocess.PIPE)(child_stdin, child_stderr, child_stdout) = (juli_proc.stdin, juli_proc.stderr, juli_proc.stdout)#Wait and Connecttime.sleep(5)#Client Definitionclass juli_client(asyncore.dispatcher): def __init__(self, host="127.0.0.1", port=julius_port): asyncore.dispatcher.__init__(self) self.create_socket(socket.AF_INET, socket.SOCK_STREAM) self.bufsize=8192 while self.connect((host, port)): pass self.xmlstr='' def handle_connect(self): pass def handle_close(self): self.close() def on_startproc(self, node): pass def on_startrecog(self, node): pass def on_endrecog(self, node): pass def on_input(self, node): pass def on_inputparam(self, node): pass def on_recogout(self, node): for shypo in node.childNodes: for whypo in shypo.childNodes: print whypo.attributes; def on_recogfail(self, node): pass def on_unknown(self, node): print "Unable to recognize: "+node.localName pass def handle_xml(self): #Sanitize XML self.xmlstr=re.sub('/>',' />',self.xmlstr) self.xmlstr=re.sub('<s>','<s>',self.xmlstr) self.xmlstr=re.sub('</s>','</s>',self.xmlstr) try: self.julidom = xml.dom.minidom.parseString(self.xmlstr) for node in self.julidom.childNodes: if node.localName == "STARTPROC": self.on_startproc(node) elif node.localName == "STARTRECOG": self.on_startrecog(node) elif node.localName == "ENDRECOG": self.on_endrecog(node) elif node.localName == "INPUT": self.on_input(node) elif node.localName == "INPUTPARAM": self.on_inputparam(node) elif node.localName == "RECOGOUT": self.on_recogout(node) elif node.localName == "RECOGFAIL": self.on_recogfail(node) else: self.on_unknown(node) except: print "Error in: {"+self.xmlstr+"}"; print sys.exc_info() def handle_read(self): self.buffer=self.recv(self.bufsize) self.messages= string.split(self.buffer, "\n") for message in self.messages: if message == '.': if self.xmlstr != '': self.handle_xml() self.xmlstr='' elif message == '': pass else: self.xmlstr+=message#Run Clientjuli_cli=juli_client()asyncore.loop()#Close Processjuli_proc.wait()