Add non-streaming websocket server for python (#259)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user