File size: 765 Bytes
65f9ac9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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()