File size: 1,306 Bytes
4655d57
0105482
 
 
 
4655d57
 
 
 
 
0105482
 
aba0e7d
 
 
 
 
 
 
0105482
aba0e7d
 
4655d57
0105482
aba0e7d
 
 
 
0105482
 
 
 
 
4655d57
 
 
0105482
 
 
 
 
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 whisper  # Ensure 'openai-whisper' is installed
import gradio as gr
import subprocess

# Load the Whisper model
try:
    model = whisper.load_model("large")  # Official Whisper model
except Exception as e:
    print(f"Error loading Whisper model: {e}")
    raise e

def transcribe_video(video_path):
    try:
        # Extract audio from the uploaded video
        audio_path = "audio.wav"
        subprocess.run(
            ["ffmpeg", "-i", video_path, "-ar", "16000", "-ac", "1", "-c:a", "pcm_s16le", audio_path],
            check=True
        )

        # Transcribe the audio in Urdu
        result = model.transcribe(audio_path, task="transcribe", language="ur")
        return result["text"]

    except FileNotFoundError:
        return "Error: ffmpeg is not installed or not found in the environment."
    except Exception as e:
        return f"An error occurred: {e}"

# Create the Gradio interface
interface = gr.Interface(
    fn=transcribe_video,
    inputs=gr.Video(label="Upload your Urdu-speaking video"),
    outputs=gr.Textbox(label="Transcribed Text"),
    title="Urdu Video Transcription App",
    description="Upload a video file in Urdu, and this app will transcribe the speech into text using Whisper.",
)

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