Ra-Is commited on
Commit
7ed2ac6
·
verified ·
1 Parent(s): 68b4b10

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -3,30 +3,29 @@ import requests
3
  import os
4
 
5
  def send_audio_to_laravel(audio):
6
- url = os.getenv("BASE_URL") # Make sure to set this environment variable or replace with the actual URL
7
 
8
- # Save audio to a temporary file
9
- temp_audio_path = "temp_audio.wav"
10
- audio.save(temp_audio_path)
11
 
12
  # Prepare form data for request
13
  files = {
14
- 'file': open(temp_audio_path, 'rb'),
15
  }
16
  data = {
17
- 'lang': 'english-twi' # You can adjust this based on your needs
18
  }
19
-
20
  response = requests.post(url, files=files, data=data)
21
  return response.json()
22
 
23
  # Gradio interface for recording speech
24
  iface = gr.Interface(
25
  fn=send_audio_to_laravel,
26
- inputs=gr.Audio("microphone"),
27
  outputs="text",
28
  title="Speech Translation",
29
- description="Record speech and send it to Laravel for processing.",
30
  )
31
 
32
- iface.launch()
 
3
  import os
4
 
5
  def send_audio_to_laravel(audio):
6
+ url = os.getenv("BASE_URL")
7
 
8
+ # audio is now a tuple (file_path, sampling_rate)
9
+ audio_path, sampling_rate = audio
 
10
 
11
  # Prepare form data for request
12
  files = {
13
+ 'file': open(audio_path, 'rb'),
14
  }
15
  data = {
16
+ 'lang': 'english-twi'
17
  }
18
+
19
  response = requests.post(url, files=files, data=data)
20
  return response.json()
21
 
22
  # Gradio interface for recording speech
23
  iface = gr.Interface(
24
  fn=send_audio_to_laravel,
25
+ inputs=gr.Audio(source="microphone", type="filepath"),
26
  outputs="text",
27
  title="Speech Translation",
28
+ description="Record speech and send it for processing.",
29
  )
30
 
31
+ iface.launch()