diff --git a/requirements.txt b/requirements.txt index 1909e3e..ddc90c4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,5 @@ soundfile==0.12.1 sphn==0.1.3 torch==2.2.0 websockets>=11.0.3, <13.1 -huggingface-hub==0.24.6 \ No newline at end of file +huggingface-hub==0.24.6 +gradio diff --git a/server_opus.py b/server_opus.py index 8d8206f..7a367c8 100644 --- a/server_opus.py +++ b/server_opus.py @@ -16,6 +16,7 @@ from websockets.server import serve from huggingface_hub import hf_hub_download +from gradio import networking import msh @@ -169,13 +170,18 @@ async def opus_loop(): log("info", f"frame handled in {1000 * (time.time() - be):.1f}ms") async def send_loop(): + buf = [] while True: if close: return await asyncio.sleep(0.001) msg = opus_writer.read_bytes() if len(msg) > 0: - await websocket.send(b"\x01" + msg) + if msg[:4] == b'OggS': + if buf: + await websocket.send(b"\x01" + b''.join(buf)) + buf.clear() + buf.append(msg) log("info", "accepted connection") @@ -185,6 +191,7 @@ async def send_loop(): opus_reader = sphn.OpusStreamReader(self.ec.sample_rate) self.ec.reset_streaming() self.lm_gen.reset_streaming() + await websocket.send(b'\x00') await asyncio.gather(opus_loop(), recv_loop(), send_loop()) log("info", "done with connection") @@ -193,6 +200,8 @@ async def main(): state = ServerState() log("info", "warming up the model") state.warmup() + tunnel = networking.setup_tunnel('127.0.0.1', args.port, 'testlapin', None) + print("Tunnel", tunnel) log("info", f"listening to ws://{args.host}:{args.port}") async with serve(state.handle_conn, args.host, args.port): await asyncio.Future() # run forever