speech-text / app.py
Ra-Is's picture
Update app.py
65f9ac9 verified
raw
history blame
765 Bytes
import requests
import json
import gradio as gr
import os
def send_audio_to_laravel(audio):
url = os.getenv("BASE_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'
}
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="file"),
outputs="text",
title="Speech Translation",
description="Record speech and send to Laravel for processing"
)
iface.launch()