litagin commited on
Commit
3f63243
·
1 Parent(s): d50db7b

Use pydub for error file

Browse files
Files changed (1) hide show
  1. app.py +10 -1
app.py CHANGED
@@ -52,7 +52,16 @@ def transcribe_common(audio: str, model: str) -> str:
52
  logger.info(f"Model: {model}")
53
  logger.info(f"Audio: {filename}")
54
  # Read and resample audio to 16kHz
55
- y, sr = librosa.load(audio, mono=True, sr=16000)
 
 
 
 
 
 
 
 
 
56
  # Get duration of audio
57
  duration = librosa.get_duration(y=y, sr=sr)
58
  logger.info(f"Duration: {duration:.2f}s")
 
52
  logger.info(f"Model: {model}")
53
  logger.info(f"Audio: {filename}")
54
  # Read and resample audio to 16kHz
55
+ try:
56
+ y, sr = librosa.load(audio, mono=True, sr=16000)
57
+ except Exception as e:
58
+ # First convert to wav if librosa cannot read the file
59
+ logger.error(f"Error reading file: {e}")
60
+ from pydub import AudioSegment
61
+
62
+ audio = AudioSegment.from_file(audio)
63
+ audio.export("temp.wav", format="wav")
64
+ y, sr = librosa.load("temp.wav", mono=True, sr=16000)
65
  # Get duration of audio
66
  duration = librosa.get_duration(y=y, sr=sr)
67
  logger.info(f"Duration: {duration:.2f}s")