asr_farhang/test/test.py
2025-11-17 14:15:20 +03:30

28 lines
799 B
Python

import asyncio
import websockets
import json
AUDIO_FILE = "./khabar_1_5.wav" # Replace with your audio file path
WS_URL = "ws://127.0.0.1:8000/asr"
async def send_audio():
async with websockets.connect(WS_URL) as ws:
print("Connected to ASR WebSocket")
# Read the audio file in chunks
with open(AUDIO_FILE, "rb") as f:
chunk_size = 21920
while chunk := f.read(chunk_size):
await ws.send(chunk)
try:
while True:
message = await ws.recv()
data = json.loads(message)
print("Received:", data)
except websockets.exceptions.ConnectionClosed:
print("WebSocket closed by server")
# Run the async client
asyncio.run(send_audio())