Ra-Is commited on
Commit
65f9ac9
1 Parent(s): b18bc7f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py CHANGED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import json
3
+ import gradio as gr
4
+ import os
5
+
6
+ def send_audio_to_laravel(audio):
7
+ url = os.getenv("BASE_URL")
8
+
9
+ # Save audio to a temporary file
10
+ temp_audio_path = "temp_audio.wav"
11
+ audio.save(temp_audio_path)
12
+
13
+ # Prepare form data for request
14
+ files = {
15
+ 'file': open(temp_audio_path, 'rb'),
16
+ }
17
+ data = {
18
+ 'lang': 'english-twi'
19
+ }
20
+
21
+ response = requests.post(url, files=files, data=data)
22
+ return response.json()
23
+
24
+ # Gradio interface for recording speech
25
+ iface = gr.Interface(
26
+ fn=send_audio_to_laravel,
27
+ inputs=gr.Audio(source="microphone", type="file"),
28
+ outputs="text",
29
+ title="Speech Translation",
30
+ description="Record speech and send to Laravel for processing"
31
+ )
32
+
33
+ iface.launch()