Update app.py
Browse files
app.py
CHANGED
|
@@ -28,18 +28,21 @@ async def transcribe(websocket: WebSocket):
|
|
| 28 |
tmp_path = None
|
| 29 |
|
| 30 |
try:
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
print(
|
| 34 |
|
|
|
|
|
|
|
| 35 |
await websocket.send_json({"status": "receiving"})
|
| 36 |
|
| 37 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp:
|
| 38 |
tmp.write(audio_bytes)
|
| 39 |
tmp_path = tmp.name
|
|
|
|
| 40 |
|
| 41 |
await websocket.send_json({"status": "transcribing"})
|
| 42 |
-
print("
|
| 43 |
|
| 44 |
segments_raw, info = model.transcribe(
|
| 45 |
tmp_path,
|
|
@@ -47,6 +50,7 @@ async def transcribe(websocket: WebSocket):
|
|
| 47 |
word_timestamps=True,
|
| 48 |
vad_filter=True,
|
| 49 |
)
|
|
|
|
| 50 |
|
| 51 |
await websocket.send_json({"status": "processing"})
|
| 52 |
|
|
@@ -61,9 +65,10 @@ async def transcribe(websocket: WebSocket):
|
|
| 61 |
"end": words[-1].end,
|
| 62 |
"words": [{"word": w.word, "start": w.start, "end": w.end} for w in words],
|
| 63 |
})
|
| 64 |
-
print(f"
|
| 65 |
|
| 66 |
srt_content = process(segments)
|
|
|
|
| 67 |
|
| 68 |
await websocket.send_json({
|
| 69 |
"status": "done",
|
|
@@ -71,10 +76,10 @@ async def transcribe(websocket: WebSocket):
|
|
| 71 |
"language": info.language,
|
| 72 |
"duration": info.duration,
|
| 73 |
})
|
| 74 |
-
print("
|
| 75 |
|
| 76 |
except WebSocketDisconnect:
|
| 77 |
-
print("
|
| 78 |
except Exception as e:
|
| 79 |
print(f"ERROR: {type(e).__name__}: {e}")
|
| 80 |
import traceback
|
|
|
|
| 28 |
tmp_path = None
|
| 29 |
|
| 30 |
try:
|
| 31 |
+
# سیگنال به client که اتصال برقره و آماده دریافت فایله
|
| 32 |
+
await websocket.send_json({"status": "connected"})
|
| 33 |
+
print("Step 1: sent connected signal, waiting for bytes")
|
| 34 |
|
| 35 |
+
audio_bytes = await websocket.receive_bytes()
|
| 36 |
+
print(f"Step 2: received {len(audio_bytes)} bytes")
|
| 37 |
await websocket.send_json({"status": "receiving"})
|
| 38 |
|
| 39 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp:
|
| 40 |
tmp.write(audio_bytes)
|
| 41 |
tmp_path = tmp.name
|
| 42 |
+
print(f"Step 3: saved to {tmp_path}")
|
| 43 |
|
| 44 |
await websocket.send_json({"status": "transcribing"})
|
| 45 |
+
print("Step 4: starting transcription")
|
| 46 |
|
| 47 |
segments_raw, info = model.transcribe(
|
| 48 |
tmp_path,
|
|
|
|
| 50 |
word_timestamps=True,
|
| 51 |
vad_filter=True,
|
| 52 |
)
|
| 53 |
+
print("Step 5: transcription done")
|
| 54 |
|
| 55 |
await websocket.send_json({"status": "processing"})
|
| 56 |
|
|
|
|
| 65 |
"end": words[-1].end,
|
| 66 |
"words": [{"word": w.word, "start": w.start, "end": w.end} for w in words],
|
| 67 |
})
|
| 68 |
+
print(f"Step 6: got {len(segments)} segments")
|
| 69 |
|
| 70 |
srt_content = process(segments)
|
| 71 |
+
print(f"Step 7: SRT built")
|
| 72 |
|
| 73 |
await websocket.send_json({
|
| 74 |
"status": "done",
|
|
|
|
| 76 |
"language": info.language,
|
| 77 |
"duration": info.duration,
|
| 78 |
})
|
| 79 |
+
print("Step 8: done sent!")
|
| 80 |
|
| 81 |
except WebSocketDisconnect:
|
| 82 |
+
print("WebSocket disconnected by client")
|
| 83 |
except Exception as e:
|
| 84 |
print(f"ERROR: {type(e).__name__}: {e}")
|
| 85 |
import traceback
|