File size: 1,332 Bytes
0889db8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import whisper
import tempfile
import os

st.title("🎙️ Audio to SRT Transcription App (Whisper)")

uploaded_file = st.file_uploader("Upload an audio file", type=["mp3", "wav", "m4a"])

if uploaded_file is not None:
    with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmpfile:
        file_path = tmpfile.name
        tmpfile.write(uploaded_file.read())

    st.audio(uploaded_file, format="audio/wav")

    # Load Whisper model
    model = whisper.load_model("large")  # Change to "medium" or "large" for better accuracy

    # Transcribe
    result = model.transcribe(file_path)

    # Save as SRT
    srt_path = file_path.replace(".wav", ".srt")
    with open(srt_path, "w") as srt_file:
        for i, segment in enumerate(result["segments"]):
            start = segment["start"]
            end = segment["end"]
            text = segment["text"]
            srt_file.write(f"{i+1}\n{start:.3f} --> {end:.3f}\n{text}\n\n")

    st.success("✅ Transcription Complete!")
    st.text_area("Transcribed Text:", result["text"], height=200)

    with open(srt_path, "rb") as srt_file:
        st.download_button("📥 Download SRT File", srt_file, file_name="transcription.srt", mime="text/plain")

    os.remove(file_path)
    os.remove(srt_path)