asr_farhang/test/test.py
2025-11-17 15:50:34 +03:30

32 lines
843 B
Python

import asyncio
import websockets
import json
AUDIO_FILE = "./data/khabar_1_5.wav"
WS_URL = "ws://127.0.0.1:7200/asr"
async def send_audio():
async with websockets.connect(WS_URL) as ws:
print("Connected to ASR WebSocket")
# Send audio in chunks
with open(AUDIO_FILE, "rb") as f:
chunk_size = 100000
while chunk := f.read(chunk_size):
await ws.send(chunk)
# Tell server no more audio is coming
await ws.send(json.dumps({"eof": True}))
# Receive results
try:
while True:
message = await ws.recv()
data = json.loads(message)
print("Received:", data)
except websockets.exceptions.ConnectionClosed:
print("WebSocket closed by server")
asyncio.run(send_audio())