From 8f0e03de7f8a8e16a79d25710ac48891a4843bd2 Mon Sep 17 00:00:00 2001 From: Yuta Hayashibe Date: Sun, 2 Oct 2022 22:08:22 +0900 Subject: [PATCH] Check error --- whispering/websocket_client.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/whispering/websocket_client.py b/whispering/websocket_client.py index 1bcbe26..f3d5018 100644 --- a/whispering/websocket_client.py +++ b/whispering/websocket_client.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 import asyncio +import json +import sys from logging import getLogger from typing import Optional, Union @@ -64,11 +66,14 @@ async def transcribe_from_mic_and_send( while True: try: c = await asyncio.wait_for(recv(), timeout=0.5) - chunk = ParsedChunk.parse_raw(c) + c_json = json.loads(c) + if (err := c_json.get("error")) is not None: + print(f"Error: {err}") + sys.exit(1) + chunk = ParsedChunk.parse_obj(c_json) print(f"{chunk.start:.2f}->{chunk.end:.2f}\t{chunk.text}") except asyncio.TimeoutError: break - idx += 1