Add non-streaming websocket server for python (#259)

This commit is contained in:
Fangjun Kuang
2023-08-11 15:56:24 +08:00
committed by GitHub
parent 6c0f002825
commit b094868fb8
24 changed files with 1247 additions and 92 deletions

View File

@@ -116,11 +116,18 @@ async def run(
assert isinstance(sample_rate, int)
assert samples.dtype == np.float32, samples.dtype
assert samples.ndim == 1, samples.dim
buf = sample_rate.to_bytes(4, byteorder="little") # 4 bytes
buf += (samples.size * 4).to_bytes(4, byteorder="little")
buf += samples.tobytes()
await websocket.send(buf)
payload_len = 10240
while len(buf) > payload_len:
await websocket.send(buf[:payload_len])
buf = buf[payload_len:]
if buf:
await websocket.send(buf)
decoding_results = await websocket.recv()
print(decoding_results)