Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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")
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
audio.save(temp_audio_path)
|
| 11 |
|
| 12 |
# Prepare form data for request
|
| 13 |
files = {
|
| 14 |
-
'file': open(
|
| 15 |
}
|
| 16 |
data = {
|
| 17 |
-
'lang': 'english-twi'
|
| 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
|
| 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()
|