imorcillo commited on
Commit
3828e6f
·
verified ·
1 Parent(s): da042e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -0
app.py CHANGED
@@ -17,10 +17,12 @@ def audio_to_bytes(audio):
17
  sf.write(audio_bytes, data, sr, format='WAV')
18
  audio_bytes.seek(0)
19
  print(len(data), sr, len(data)/sr)
 
20
  return audio_bytes
21
 
22
  def langswitch_API_call(audio, language):
23
  audio_bytes = audio_to_bytes(audio)
 
24
  files = {'file': (f'audio_chunk.wav', audio_bytes, 'audio/wav')}
25
  api_url = os.getenv("api_url")
26
  response = requests.post(f"{api_url}/online/http?language={language}", files=files)
@@ -34,6 +36,7 @@ def transcribe_base(audio, language):
34
  try:
35
  response = langswitch_API_call(audio, language)
36
  print(response)
 
37
  except Exception as e:
38
  if "Invalid file: None" in str(e):
39
  return "⚠️ Check that you have clicked the stop button or wait for the audio to load completely."
 
17
  sf.write(audio_bytes, data, sr, format='WAV')
18
  audio_bytes.seek(0)
19
  print(len(data), sr, len(data)/sr)
20
+ if len(data)/sr >= 960000: return None
21
  return audio_bytes
22
 
23
  def langswitch_API_call(audio, language):
24
  audio_bytes = audio_to_bytes(audio)
25
+ if audio_bytes == None: return None
26
  files = {'file': (f'audio_chunk.wav', audio_bytes, 'audio/wav')}
27
  api_url = os.getenv("api_url")
28
  response = requests.post(f"{api_url}/online/http?language={language}", files=files)
 
36
  try:
37
  response = langswitch_API_call(audio, language)
38
  print(response)
39
+ if response == None: return "Audio file should be shorter than 1 minute."
40
  except Exception as e:
41
  if "Invalid file: None" in str(e):
42
  return "⚠️ Check that you have clicked the stop button or wait for the audio to load completely."