File size: 2,416 Bytes
d607889
2768c84
b3e8f66
cf830a1
 
c5b5497
c98847a
cf830a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2768c84
b3e8f66
 
 
2768c84
 
b3e8f66
 
 
 
2768c84
 
 
 
 
b3e8f66
 
 
 
 
2768c84
c5b5497
 
 
 
 
 
 
b3e8f66
 
 
 
c5b5497
 
 
 
 
 
2768c84
b3e8f66
c5b5497
 
 
 
 
 
cf830a1
 
c5b5497
 
 
 
 
 
 
cf830a1
c5b5497
 
 
 
 
 
 
b3e8f66
0e29bce
 
b3e8f66
 
c5b5497
 
 
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import streamlit as st
import whisper
import tempfile
import subprocess
import os
import time


def convert_to_wav(input_path):
    tmp_wav = tempfile.NamedTemporaryFile(delete=False, suffix=".wav")
    tmp_wav.close()

    cmd = [
        "ffmpeg",
        "-y",
        "-i", input_path,
        "-ar", "16000",   # sample rate
        "-ac", "1",       # mono
        tmp_wav.name
    ]

    subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
    return tmp_wav.name


st.set_page_config(
    page_title="IndicASR",
    page_icon="✔️",
    layout="wide",
)

st.markdown(
    '''<h1><center><b><u>IndicASR</u></b></center></h1>''',
    unsafe_allow_html=True
)

activity = ['Select your Language', 'English']
choice = st.selectbox('How you want to proceed?', activity)

if choice == 'English':
    uploaded_file = st.file_uploader(
        "Upload your Audio File",
        type=["mp3", "wav", "m4a"]
    )

    if uploaded_file is not None:
        progress = st.progress(0)
        status = st.empty()

        # Step 1: Save file
        status.write("Uploading audio…")
        progress.progress(10)

        with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
            tmp_file.write(uploaded_file.read())
            audio_path = tmp_file.name

        time.sleep(0.2)

        # Step 2: Load model
        status.write("Loading ASR model…")
        progress.progress(30)

        model = whisper.load_model("turbo")

        time.sleep(0.2)

        # Step 3: Convert audio
        status.write("Converting audio to 16kHz WAV…")
        progress.progress(50)

        wav_path = convert_to_wav(audio_path)

        time.sleep(0.2)

        # Step 4: Transcription
        status.write("Transcribing audio (this may take a while)…")
        progress.progress(80)

        start_time = time.time()
        result = model.transcribe(wav_path, verbose=False)
        end_time = time.time()
        transcription_time = end_time - start_time

        # Step 5: Done
        progress.progress(100)
        status.success("Transcription completed ✅")
        st.info(f"Transcription time: {transcription_time:.2f} seconds")

        st.audio(wav_path, format="audio/mpeg", loop=True)

        st.subheader("Transcript")
        st.write(result["text"])

        # Optional cleanup
        os.remove(audio_path)
        os.remove(wav_path)