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

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

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

@ -83,7 +83,7 @@ async def websocket_endpoint(websocket: WebSocket):
resp = {
"status": "ok",
"signal": "finished",
'final_result': asr_results
'result': asr_results
}
await websocket.send_json(resp)
break
@ -102,7 +102,7 @@ async def websocket_endpoint(websocket: WebSocket):
# return the current period result
# 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)
except WebSocketDisconnect:
pass

Loading…
Cancel
Save