Browse Source

fix: transcribe temp file delete on Windows

Brin 1 month ago
parent
commit
3ae28bd381
1 changed files with 7 additions and 3 deletions
  1. 7 3
      konan_client.py

+ 7 - 3
konan_client.py

@@ -57,9 +57,13 @@ def record_until_release():
 
 def transcribe(audio):
     with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as f:
-        wav.write(f.name, SAMPLE_RATE, audio)
-        result = model.transcribe(f.name, language="fr")
-        os.unlink(f.name)
+        tmp_path = f.name
+        wav.write(tmp_path, SAMPLE_RATE, audio)
+    result = model.transcribe(tmp_path, language="fr")
+    try:
+        os.unlink(tmp_path)
+    except Exception:
+        pass
     return result["text"].strip()
 
 def ask_konan(text):