From 1ebef74d3a86dfbb227c046725402abd6ac38273 Mon Sep 17 00:00:00 2001 From: Yuta Hayashibe Date: Sat, 24 Sep 2022 21:50:04 +0900 Subject: [PATCH] Changed --- whisper_streaming/websocket_client.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/whisper_streaming/websocket_client.py b/whisper_streaming/websocket_client.py index afbaf18..c54d540 100644 --- a/whisper_streaming/websocket_client.py +++ b/whisper_streaming/websocket_client.py @@ -44,22 +44,28 @@ async def transcribe_from_mic_and_send( async def g(): return await q.get() - logger.debug(f"Segment #: {idx}") + logger.debug(f"Loop #: {idx}") + segment = None try: - segment = await asyncio.wait_for(g(), timeout=3.0) + segment = await asyncio.wait_for(g(), timeout=0.5) except asyncio.TimeoutError: - continue + pass + if segment is not None: + logger.debug(f"Segment size: {len(segment)}") + await ws.send(segment) + logger.debug("Sent") - logger.debug(f"Segment size: {len(segment)}") - await ws.send(segment) - logger.debug("Sent") + async def recv(): + return await ws.recv() while True: - c = await ws.recv() - if len(c) == 0: + try: + c = await asyncio.wait_for(recv(), timeout=0.5) + chunk = ParsedChunk.parse_raw(c) + print(f"{chunk.start:.2f}->{chunk.end:.2f}\t{chunk.text}") + except asyncio.TimeoutError: break - chunk = ParsedChunk.parse_raw(c) - print(f"{chunk.start:.2f}->{chunk.end:.2f}\t{chunk.text}") + idx += 1