Parcourir la source

fail on ffmpeg errors

subDesTagesMitExtraKaese il y a 2 ans
Parent
commit
f3a6a33a23
1 fichiers modifiés avec 4 ajouts et 1 suppressions
  1. 4 1
      speech_recognition.py

+ 4 - 1
speech_recognition.py

@@ -13,12 +13,15 @@ def convert_audio(data: bytes, out_filename: str):
       file.flush()
       print(f"Converting media {file.name} to {out_filename}")
 
-      out, _ = (
+      out, err = (
         ffmpeg.input(file.name, threads=0)
         .output(out_filename, format="wav", acodec="pcm_s16le", ac=1, ar=SAMPLE_RATE)
         .overwrite_output()
         .run(cmd="ffmpeg", capture_stdout=True, capture_stderr=True, input=data)
       )
+    if os.path.getsize(out_filename) == 0:
+      print(str(err, "utf-8"))
+      raise Exception("Converted file is empty")
   except ffmpeg.Error as e:
     raise RuntimeError(f"Failed to load audio: {e.stderr.decode()}") from e