Spaces:
Edmond98
/
Running on A100

Afrinetwork7 commited on
Commit
7228faf
1 Parent(s): 3cf82c2

Update asr.py

Browse files
Files changed (1) hide show
  1. asr.py +8 -6
asr.py CHANGED
@@ -68,8 +68,7 @@ model = Wav2Vec2ForCTC.from_pretrained(MODEL_ID)
68
 
69
 
70
  def transcribe(audio_data=None, lang="eng (English)"):
71
-
72
- if not audio_data:
73
  return "<<ERROR: Empty Audio Input>>"
74
 
75
  if isinstance(audio_data, tuple):
@@ -80,11 +79,14 @@ def transcribe(audio_data=None, lang="eng (English)"):
80
  audio_samples = librosa.resample(
81
  audio_samples, orig_sr=sr, target_sr=ASR_SAMPLING_RATE
82
  )
83
- else:
 
 
 
84
  # file upload
85
-
86
- if not isinstance(audio_data, str):
87
- return "<<ERROR: Invalid Audio Input Instance: {}>>".format(type(audio_data))
88
  audio_samples = librosa.load(audio_data, sr=ASR_SAMPLING_RATE, mono=True)[0]
89
 
90
  lang_code = lang.split()[0]
 
68
 
69
 
70
  def transcribe(audio_data=None, lang="eng (English)"):
71
+ if audio_data is None or (isinstance(audio_data, np.ndarray) and audio_data.size == 0):
 
72
  return "<<ERROR: Empty Audio Input>>"
73
 
74
  if isinstance(audio_data, tuple):
 
79
  audio_samples = librosa.resample(
80
  audio_samples, orig_sr=sr, target_sr=ASR_SAMPLING_RATE
81
  )
82
+ elif isinstance(audio_data, np.ndarray):
83
+ # Assuming audio_data is already in the correct format
84
+ audio_samples = audio_data
85
+ elif isinstance(audio_data, str):
86
  # file upload
87
+ audio_samples = librosa.load(audio_data, sr=ASR_SAMPLING_RATE, mono=True)[0]
88
+ else:
89
+ return f"<<ERROR: Invalid Audio Input Instance: {type(audio_data)}>>"
90
  audio_samples = librosa.load(audio_data, sr=ASR_SAMPLING_RATE, mono=True)[0]
91
 
92
  lang_code = lang.split()[0]