ayushkanha commited on
Commit
0889db8
·
verified ·
1 Parent(s): 5499c02

Upload speach_text.py

Browse files
Files changed (1) hide show
  1. speach_text.py +39 -0
speach_text.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import whisper
3
+ import tempfile
4
+ import os
5
+
6
+ st.title("🎙️ Audio to SRT Transcription App (Whisper)")
7
+
8
+ uploaded_file = st.file_uploader("Upload an audio file", type=["mp3", "wav", "m4a"])
9
+
10
+ if uploaded_file is not None:
11
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmpfile:
12
+ file_path = tmpfile.name
13
+ tmpfile.write(uploaded_file.read())
14
+
15
+ st.audio(uploaded_file, format="audio/wav")
16
+
17
+ # Load Whisper model
18
+ model = whisper.load_model("large") # Change to "medium" or "large" for better accuracy
19
+
20
+ # Transcribe
21
+ result = model.transcribe(file_path)
22
+
23
+ # Save as SRT
24
+ srt_path = file_path.replace(".wav", ".srt")
25
+ with open(srt_path, "w") as srt_file:
26
+ for i, segment in enumerate(result["segments"]):
27
+ start = segment["start"]
28
+ end = segment["end"]
29
+ text = segment["text"]
30
+ srt_file.write(f"{i+1}\n{start:.3f} --> {end:.3f}\n{text}\n\n")
31
+
32
+ st.success("✅ Transcription Complete!")
33
+ st.text_area("Transcribed Text:", result["text"], height=200)
34
+
35
+ with open(srt_path, "rb") as srt_file:
36
+ st.download_button("📥 Download SRT File", srt_file, file_name="transcription.srt", mime="text/plain")
37
+
38
+ os.remove(file_path)
39
+ os.remove(srt_path)