Ra-Is commited on
Commit
b9995a0
·
verified ·
1 Parent(s): 867fbf0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -3,10 +3,17 @@ import requests
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 = {
@@ -22,10 +29,10 @@ def send_audio_to_laravel(audio):
22
  # Gradio interface for recording speech
23
  iface = gr.Interface(
24
  fn=send_audio_to_laravel,
25
- inputs=gr.Audio("microphone"),
26
  outputs="text",
27
  title="Speech Translation",
28
- description="Record speech and send it for processing.",
29
  )
30
 
31
- iface.launch()
 
3
  import os
4
 
5
  def send_audio_to_laravel(audio):
6
+ url = os.getenv("BASE_URL")
7
 
8
+ # Save audio to a temporary file if `audio` is a file-like object
9
+ if isinstance(audio, str):
10
+ # If the audio is a file path (string), use it directly
11
+ audio_path = audio
12
+ else:
13
+ # Handle cases where `audio` is a file-like object
14
+ with open("temp_audio.wav", "wb") as f:
15
+ f.write(audio.read())
16
+ audio_path = "temp_audio.wav"
17
 
18
  # Prepare form data for request
19
  files = {
 
29
  # Gradio interface for recording speech
30
  iface = gr.Interface(
31
  fn=send_audio_to_laravel,
32
+ inputs=gr.Audio(type="filepath"), # Expect a file path as input
33
  outputs="text",
34
  title="Speech Translation",
35
+ description="Record speech and send it to Laravel for processing.",
36
  )
37
 
38
+ iface.launch()