imorcillo commited on
Commit
769531c
·
verified ·
1 Parent(s): b841d1b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -11
app.py CHANGED
@@ -12,23 +12,17 @@ def start_app():
12
  return gr.update(visible=False), gr.update(visible=True)
13
 
14
  def audio_to_bytes(audio):
15
- try:
16
- data, sr = sf.read(audio)
17
- audio_bytes = io.BytesIO()
18
- sf.write(audio_bytes, data, sr, format='WAV')
19
- audio_bytes.seek(0)
20
- return audio_bytes
21
- except TypeError as e:
22
- print("TypeError caught in audio_to_bytes:", e)
23
- return None
24
 
25
  def langswitch_API_call(audio, language):
26
  audio_bytes = audio_to_bytes(audio)
27
  files = {'file': (f'audio_chunk.wav', audio_bytes, 'audio/wav')}
28
  api_url = os.getenv("api_url")
29
  response = requests.post(f"{api_url}/online/http?language={language}", files=files)
30
- if audio_bytes is None:
31
- raise Exception("Invalid audio input")
32
  if response.status_code != 200:
33
  print(response)
34
  raise Exception("API error")
 
12
  return gr.update(visible=False), gr.update(visible=True)
13
 
14
  def audio_to_bytes(audio):
15
+ data, sr = sf.read(audio)
16
+ audio_bytes = io.BytesIO()
17
+ sf.write(audio_bytes, data, sr, format='WAV')
18
+ audio_bytes.seek(0)
19
+ return audio_bytes
 
 
 
 
20
 
21
  def langswitch_API_call(audio, language):
22
  audio_bytes = audio_to_bytes(audio)
23
  files = {'file': (f'audio_chunk.wav', audio_bytes, 'audio/wav')}
24
  api_url = os.getenv("api_url")
25
  response = requests.post(f"{api_url}/online/http?language={language}", files=files)
 
 
26
  if response.status_code != 200:
27
  print(response)
28
  raise Exception("API error")