Ra-Is commited on
Commit
aba8804
1 Parent(s): 2227fad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -8
app.py CHANGED
@@ -1,14 +1,32 @@
1
  import gradio as gr
 
 
2
 
3
- def transcribe(audio):
4
- sr, y = audio
5
 
6
- return True
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
- demo = gr.Interface(
9
- transcribe,
10
- gr.Audio(sources="microphone"),
11
- "text",
 
 
 
12
  )
13
 
14
- demo.launch()
 
1
  import gradio as gr
2
+ 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(source="microphone", type="filepath"),
27
+ outputs="text",
28
+ title="Speech Translation",
29
+ description="Record speech and send it to Laravel for processing.",
30
  )
31
 
32
+ iface.launch()