62 lines
1.6 KiB
Markdown
62 lines
1.6 KiB
Markdown
## ASR SERVICE
|
|
|
|
### A FASTAPI client for receieving audio data from font and sending audio to a Triton ASR service using WebSocket streaming. It yields real-time transcription results as JSON-like events.
|
|
|
|
|
|
## Test
|
|
|
|
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())
|
|
|
|
|
|
## How to run
|
|
|
|
### SET ENVIRONMENT
|
|
|
|
1-create a file .env and set TRITON_URL
|
|
|
|
### 1-DEVELOPMENT
|
|
#### Run the system : Uvicorn and Fastapi
|
|
.venv/bin/uvicorn src.main:app --host 0.0.0.0 --port 7200
|
|
|
|
### 2-DEPLOYMENT
|
|
#### Docker Build
|
|
docker build -t asr_farhang:latest .
|
|
|
|
|
|
#### Docker Run (port = 7200)
|
|
docker run -d --network host --restart unless-stopped asr_farhang:latest
|
|
|
|
|
|
|
|
there was a problem in installing ast_client package :
|
|
pip couldnot find a versaion for perf-analyzer==2.59.1 : so i removed it |