Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better #18

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
huggingface-hub==0.24.6
gradio
11 changes: 10 additions & 1 deletion server_opus.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from websockets.server import serve

from huggingface_hub import hf_hub_download
from gradio import networking

import msh

Expand Down Expand Up @@ -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")
Expand All @@ -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")

Expand All @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we would want to make this the default, though I like testlapin. Maybe put it behind a command line flag?

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
Expand Down