AliJabbarpour commited on
Commit
1a51f42
·
verified ·
1 Parent(s): 76c80ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -13
app.py CHANGED
@@ -28,18 +28,18 @@ async def transcribe(websocket: WebSocket):
28
  tmp_path = None
29
 
30
  try:
31
- print("Step 1: waiting for bytes")
32
  audio_bytes = await websocket.receive_bytes()
33
- print(f"Step 2: received {len(audio_bytes)} bytes")
 
34
  await websocket.send_json({"status": "receiving"})
35
 
36
  with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp:
37
  tmp.write(audio_bytes)
38
  tmp_path = tmp.name
39
- print(f"Step 4: saved to {tmp_path}")
40
 
41
  await websocket.send_json({"status": "transcribing"})
42
- print("Step 5: starting transcription")
43
 
44
  segments_raw, info = model.transcribe(
45
  tmp_path,
@@ -47,7 +47,6 @@ async def transcribe(websocket: WebSocket):
47
  word_timestamps=True,
48
  vad_filter=True,
49
  )
50
- print("Step 6: transcription generator ready")
51
 
52
  await websocket.send_json({"status": "processing"})
53
 
@@ -60,15 +59,11 @@ async def transcribe(websocket: WebSocket):
60
  "text": seg.text.strip(),
61
  "start": words[0].start,
62
  "end": words[-1].end,
63
- "words": [
64
- {"word": w.word, "start": w.start, "end": w.end}
65
- for w in words
66
- ],
67
  })
68
- print(f"Step 7: got {len(segments)} segments")
69
 
70
  srt_content = process(segments)
71
- print(f"Step 8: SRT built, length={len(srt_content)}")
72
 
73
  await websocket.send_json({
74
  "status": "done",
@@ -76,10 +71,10 @@ async def transcribe(websocket: WebSocket):
76
  "language": info.language,
77
  "duration": info.duration,
78
  })
79
- print("Step 9: 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
 
28
  tmp_path = None
29
 
30
  try:
31
+ print("Waiting for audio bytes...")
32
  audio_bytes = await websocket.receive_bytes()
33
+ print(f"Received {len(audio_bytes)} bytes")
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("Starting transcription...")
43
 
44
  segments_raw, info = model.transcribe(
45
  tmp_path,
 
47
  word_timestamps=True,
48
  vad_filter=True,
49
  )
 
50
 
51
  await websocket.send_json({"status": "processing"})
52
 
 
59
  "text": seg.text.strip(),
60
  "start": words[0].start,
61
  "end": words[-1].end,
62
+ "words": [{"word": w.word, "start": w.start, "end": w.end} for w in words],
 
 
 
63
  })
64
+ print(f"Got {len(segments)} segments")
65
 
66
  srt_content = process(segments)
 
67
 
68
  await websocket.send_json({
69
  "status": "done",
 
71
  "language": info.language,
72
  "duration": info.duration,
73
  })
74
+ print("Done!")
75
 
76
  except WebSocketDisconnect:
77
+ print("Client disconnected")
78
  except Exception as e:
79
  print(f"ERROR: {type(e).__name__}: {e}")
80
  import traceback