Update app.py
Browse files
app.py
CHANGED
|
@@ -25,6 +25,8 @@ print("Loading DeepFilterNet model...", flush=True)
|
|
| 25 |
df_model, df_state, _ = init_df()
|
| 26 |
print("DeepFilterNet model ready!")
|
| 27 |
|
|
|
|
|
|
|
| 28 |
@app.get("/health")
|
| 29 |
async def health():
|
| 30 |
return {"status": "ok", "message": "SubFlow backend is running"}
|
|
@@ -50,24 +52,32 @@ async def transcribe(websocket: WebSocket):
|
|
| 50 |
await websocket.send_json({"status": "cleaning"})
|
| 51 |
print("Step 3.5: cleaning audio with DeepFilterNet")
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
await websocket.send_json({"status": "transcribing"})
|
| 60 |
print("Step 4: starting transcription")
|
| 61 |
|
| 62 |
segments_raw, info = model.transcribe(
|
| 63 |
-
|
| 64 |
language="en",
|
| 65 |
word_timestamps=True,
|
| 66 |
vad_filter=True,
|
| 67 |
vad_parameters=dict(
|
| 68 |
min_silence_duration_ms=500,
|
| 69 |
speech_pad_ms=200,
|
| 70 |
-
threshold=0.3,
|
| 71 |
),
|
| 72 |
)
|
| 73 |
|
|
|
|
| 25 |
df_model, df_state, _ = init_df()
|
| 26 |
print("DeepFilterNet model ready!")
|
| 27 |
|
| 28 |
+
USE_DEEPFILTERNET = True # برای تست بدون DeepFilterNet، این رو موقتاً False کن
|
| 29 |
+
|
| 30 |
@app.get("/health")
|
| 31 |
async def health():
|
| 32 |
return {"status": "ok", "message": "SubFlow backend is running"}
|
|
|
|
| 52 |
await websocket.send_json({"status": "cleaning"})
|
| 53 |
print("Step 3.5: cleaning audio with DeepFilterNet")
|
| 54 |
|
| 55 |
+
audio_to_transcribe = tmp_path
|
| 56 |
+
|
| 57 |
+
if USE_DEEPFILTERNET:
|
| 58 |
+
await websocket.send_json({"status": "cleaning"})
|
| 59 |
+
print("Step 3.5: cleaning audio with DeepFilterNet")
|
| 60 |
+
|
| 61 |
+
audio_data, _ = load_audio(tmp_path, sr=df_state.sr())
|
| 62 |
+
enhanced_audio = enhance(df_model, df_state, audio_data, atten_lim_db=20)
|
| 63 |
+
enhanced_path = tmp_path.replace(".wav", "_enhanced.wav")
|
| 64 |
+
save_audio(enhanced_path, enhanced_audio, df_state.sr())
|
| 65 |
+
audio_to_transcribe = enhanced_path
|
| 66 |
+
print(f"Step 3.6: cleaned audio saved to {enhanced_path}")
|
| 67 |
+
else:
|
| 68 |
+
print("Step 3.5: skipping DeepFilterNet (disabled for A/B test)")
|
| 69 |
|
| 70 |
await websocket.send_json({"status": "transcribing"})
|
| 71 |
print("Step 4: starting transcription")
|
| 72 |
|
| 73 |
segments_raw, info = model.transcribe(
|
| 74 |
+
audio_to_transcribe,
|
| 75 |
language="en",
|
| 76 |
word_timestamps=True,
|
| 77 |
vad_filter=True,
|
| 78 |
vad_parameters=dict(
|
| 79 |
min_silence_duration_ms=500,
|
| 80 |
speech_pad_ms=200,
|
|
|
|
| 81 |
),
|
| 82 |
)
|
| 83 |
|