mirror of
https://github.com/shirayu/whispering.git
synced 2024-11-29 04:21:07 +00:00
Use different context for each connection
This commit is contained in:
parent
b1f98f86ff
commit
e44d1ef13d
1 changed files with 9 additions and 2 deletions
|
@ -5,6 +5,7 @@ from logging import getLogger
|
|||
|
||||
import numpy as np
|
||||
import websockets
|
||||
from websockets.exceptions import ConnectionClosedOK
|
||||
|
||||
from whispering.transcriber import Context, WhisperStreamingTranscriber
|
||||
|
||||
|
@ -15,10 +16,16 @@ async def serve_with_websocket_main(websocket):
|
|||
global g_wsp
|
||||
global g_ctx
|
||||
idx: int = 0
|
||||
ctx: Context = g_ctx.copy(
|
||||
deep=True,
|
||||
)
|
||||
|
||||
while True:
|
||||
logger.debug(f"Segment #: {idx}")
|
||||
message = await websocket.recv()
|
||||
try:
|
||||
message = await websocket.recv()
|
||||
except ConnectionClosedOK:
|
||||
break
|
||||
|
||||
if isinstance(message, str):
|
||||
logger.debug(f"Got str: {message}")
|
||||
|
@ -28,7 +35,7 @@ async def serve_with_websocket_main(websocket):
|
|||
segment = np.frombuffer(message, dtype=np.float32)
|
||||
for chunk in g_wsp.transcribe(
|
||||
segment=segment, # type: ignore
|
||||
ctx=g_ctx,
|
||||
ctx=ctx,
|
||||
):
|
||||
await websocket.send(chunk.json())
|
||||
idx += 1
|
||||
|
|
Loading…
Reference in a new issue