Spaces:
Sleeping
Sleeping
import gradio as gr | |
import requests | |
import os | |
def send_audio_to_laravel(audio): | |
url = os.getenv("BASE_URL") # Make sure to set this environment variable or replace with the actual URL | |
# Save audio to a temporary file | |
temp_audio_path = "temp_audio.wav" | |
audio.save(temp_audio_path) | |
# Prepare form data for request | |
files = { | |
'file': open(temp_audio_path, 'rb'), | |
} | |
data = { | |
'lang': 'english-twi' # You can adjust this based on your needs | |
} | |
response = requests.post(url, files=files, data=data) | |
return response.json() | |
# Gradio interface for recording speech | |
iface = gr.Interface( | |
fn=send_audio_to_laravel, | |
inputs=gr.Audio(source="microphone", type="filepath"), | |
outputs="text", | |
title="Speech Translation", | |
description="Record speech and send it to Laravel for processing.", | |
) | |
iface.launch() | |