AliJabbarpour commited on
Commit
180c071
·
verified ·
1 Parent(s): ddd907b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -3
app.py CHANGED
@@ -268,9 +268,19 @@ async def transcribe(websocket: WebSocket):
268
 
269
  try:
270
  await websocket.send_json({"status": "receiving", "detail": "در انتظار دریافت فایل..."})
271
- print("Step 1: waiting for bytes")
272
- audio_bytes = await websocket.receive_bytes()
273
- print(f"Step 2: received {len(audio_bytes)} bytes")
 
 
 
 
 
 
 
 
 
 
274
  size_mb = len(audio_bytes) / (1024 * 1024)
275
  await websocket.send_json({"status": "receiving", "detail": f"{size_mb:.1f} مگابایت دریافت شد"})
276
 
 
268
 
269
  try:
270
  await websocket.send_json({"status": "receiving", "detail": "در انتظار دریافت فایل..."})
271
+ print("Step 1: waiting for chunks")
272
+ chunks = []
273
+ total_bytes = 0
274
+ while True:
275
+ message = await websocket.receive()
276
+ if "bytes" in message and message["bytes"] is not None:
277
+ chunk = message["bytes"]
278
+ chunks.append(chunk)
279
+ total_bytes += len(chunk)
280
+ elif "text" in message and message["text"] == "__END__":
281
+ break
282
+ audio_bytes = b"".join(chunks)
283
+ print(f"Step 2: received {total_bytes} bytes in {len(chunks)} chunks")
284
  size_mb = len(audio_bytes) / (1024 * 1024)
285
  await websocket.send_json({"status": "receiving", "detail": f"{size_mb:.1f} مگابایت دریافت شد"})
286