File size: 1,180 Bytes
3ea5efb
 
71cfe0a
3ea5efb
 
71cfe0a
 
3ea5efb
71cfe0a
 
079e633
71cfe0a
 
 
 
 
079e633
ae64426
 
 
 
 
 
 
0e8b210
 
079e633
71cfe0a
3ea5efb
71cfe0a
 
 
0b4231e
3ea5efb
71cfe0a
f106e32
3ea5efb
 
 
71cfe0a
 
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
35
36
37
38
39
40
41
42
import openai
import gradio as gr
from dotenv import load_dotenv
import os

# Load environment variables from .env file
load_dotenv()

# Set up OpenAI API key
openai.api_key = os.getenv("OPENAI_API_KEY")

def speech_to_text(audio):
    # Check if the audio input is received correctly
    if audio is None:
        return "No audio file uploaded."
    
    try:
        # Transcribe the audio to text using OpenAI's Whisper API via the new method
        with open(audio, "rb") as audio_file:
            response = openai.Audio.transcribe(
                model="whisper-1",  # Use the appropriate model for transcription
                file=audio_file,
                language="ta"  # Specify the language as Tamil
            )
        text = response['text']
        return text
    except Exception as e:
        return f"Error during transcription: {str(e)}"

# Set up the Gradio interface
interface = gr.Interface(
    fn=speech_to_text,
    inputs=gr.Audio(type="filepath"),
    outputs="text",
    title="Speech to Text Transcription",
    description="Transcribe speech to Tamil text using."
)

# Launch the interface
if __name__ == "__main__":
    interface.launch()