update the ws asr response, final_result to result, test=doc

pull/1784/head
xiongxinlei 3 years ago
parent 7007b0ecac
commit 9125cb076d

@ -93,7 +93,7 @@
function parseResult(data) { function parseResult(data) {
var data = JSON.parse(data) var data = JSON.parse(data)
var result = data.asr_results var result = data.result
console.log(result) console.log(result)
$("#resultPanel").html(result) $("#resultPanel").html(result)
} }
@ -152,4 +152,4 @@
</script> </script>
</body> </body>
</html> </html>

@ -387,7 +387,7 @@ class ASRClientExecutor(BaseExecutor):
punc_server_port=punc_server_port) punc_server_port=punc_server_port)
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
res = loop.run_until_complete(handler.run(input)) res = loop.run_until_complete(handler.run(input))
res = res['final_result'] res = res['result']
logger.info("asr websocket client finished") logger.info("asr websocket client finished")
else: else:
logger.error(f"Sorry, we have not support protocol: {protocol}," logger.error(f"Sorry, we have not support protocol: {protocol},"

@ -54,8 +54,6 @@ class TextHttpHandler:
str: punctuation text str: punctuation text
""" """
if self.server_ip is None or self.port is None: if self.server_ip is None or self.port is None:
logger.warning(
"No punctuation server, please input valid ip and port")
return text return text
request = { request = {
"text": text, "text": text,
@ -141,7 +139,7 @@ class ASRWsAudioHandler:
if self.url is None: if self.url is None:
logger.error( logger.error(
"No punctuation server, please input valid ip and port") "No asr server, please input valid ip and port")
return "" return ""
# 1. send websocket handshake protocal # 1. send websocket handshake protocal
@ -166,9 +164,9 @@ class ASRWsAudioHandler:
await ws.send(chunk_data.tobytes()) await ws.send(chunk_data.tobytes())
msg = await ws.recv() msg = await ws.recv()
msg = json.loads(msg) msg = json.loads(msg)
if self.punc_server and len(msg["partial_result"]) > 0: if self.punc_server and len(msg["result"]) > 0:
msg["partial_result"] = self.punc_server.run( msg["result"] = self.punc_server.run(
msg["partial_result"]) msg["result"])
logger.info("receive msg={}".format(msg)) logger.info("receive msg={}".format(msg))
# 4. we must send finished signal to the server # 4. we must send finished signal to the server
@ -187,7 +185,7 @@ class ASRWsAudioHandler:
# 5. decode the bytes to str # 5. decode the bytes to str
msg = json.loads(msg) msg = json.loads(msg)
if self.punc_server: if self.punc_server:
msg["final_result"] = self.punc_server.run(msg["final_result"]) msg["result"] = self.punc_server.run(msg["result"])
logger.info("final receive msg={}".format(msg)) logger.info("final receive msg={}".format(msg))
result = msg result = msg

@ -83,7 +83,7 @@ async def websocket_endpoint(websocket: WebSocket):
resp = { resp = {
"status": "ok", "status": "ok",
"signal": "finished", "signal": "finished",
'final_result': asr_results 'result': asr_results
} }
await websocket.send_json(resp) await websocket.send_json(resp)
break break
@ -102,7 +102,7 @@ async def websocket_endpoint(websocket: WebSocket):
# return the current period result # return the current period result
# if the engine create the vad instance, this connection will have many period results # if the engine create the vad instance, this connection will have many period results
resp = {'partial_result': asr_results} resp = {'result': asr_results}
await websocket.send_json(resp) await websocket.send_json(resp)
except WebSocketDisconnect: except WebSocketDisconnect:
pass pass

Loading…
Cancel
Save