mirror of
https://github.com/alphacep/vosk-server.git
synced 2026-03-09 00:10:18 +08:00
27 lines
701 B
Python
Executable File
27 lines
701 B
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import asyncio
|
|
import websockets
|
|
import sys
|
|
import wave
|
|
|
|
async def run_test(uri):
|
|
async with websockets.connect(uri) as websocket:
|
|
|
|
wf = wave.open(sys.argv[1], "rb")
|
|
await websocket.send('{ "config" : { "sample_rate" : %d } }' % (wf.getframerate()))
|
|
buffer_size = int(wf.getframerate() * 0.2) # 0.2 seconds of audio
|
|
while True:
|
|
data = wf.readframes(buffer_size)
|
|
|
|
if len(data) == 0:
|
|
break
|
|
|
|
await websocket.send(data)
|
|
print (await websocket.recv())
|
|
|
|
await websocket.send('{"eof" : 1}')
|
|
print (await websocket.recv())
|
|
|
|
asyncio.run(run_test('ws://localhost:2700'))
|