unijoh commited on
Commit
2071c0b
·
verified ·
1 Parent(s): bfbbaac

Update asr.py

Browse files
Files changed (1) hide show
  1. asr.py +15 -2
asr.py CHANGED
@@ -20,10 +20,23 @@ def transcribe(audio):
20
  return "ERROR: You have to either use the microphone or upload an audio file"
21
 
22
  logging.info(f"Loading audio file: {audio}")
23
- audio_samples, _ = librosa.load(audio, sr=ASR_SAMPLING_RATE, mono=True)
 
 
 
 
 
 
 
 
 
24
 
25
  # Process the audio with the pipeline
26
- transcription = pipe(audio_samples, sampling_rate=ASR_SAMPLING_RATE)["text"]
 
 
 
 
27
 
28
  logging.info("Transcription completed successfully.")
29
  return transcription
 
20
  return "ERROR: You have to either use the microphone or upload an audio file"
21
 
22
  logging.info(f"Loading audio file: {audio}")
23
+
24
+ # Try loading the audio file with librosa
25
+ try:
26
+ audio_samples, _ = librosa.load(audio, sr=ASR_SAMPLING_RATE, mono=True)
27
+ except FileNotFoundError:
28
+ logging.error("Audio file not found")
29
+ return "ERROR: Audio file not found"
30
+ except Exception as e:
31
+ logging.error(f"Error loading audio file with librosa: {e}")
32
+ return f"ERROR: Unable to load audio file - {e}"
33
 
34
  # Process the audio with the pipeline
35
+ try:
36
+ transcription = pipe(audio_samples, sampling_rate=ASR_SAMPLING_RATE)["text"]
37
+ except Exception as e:
38
+ logging.error(f"Error during transcription with pipeline: {e}")
39
+ return f"ERROR: Transcription failed - {e}"
40
 
41
  logging.info("Transcription completed successfully.")
42
  return transcription