|
|
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", |
|
|
"-ac", "1", |
|
|
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() |
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
status.write("Loading ASR model…") |
|
|
progress.progress(30) |
|
|
|
|
|
model = whisper.load_model("turbo") |
|
|
|
|
|
time.sleep(0.2) |
|
|
|
|
|
|
|
|
status.write("Converting audio to 16kHz WAV…") |
|
|
progress.progress(50) |
|
|
|
|
|
wav_path = convert_to_wav(audio_path) |
|
|
|
|
|
time.sleep(0.2) |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
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"]) |
|
|
|
|
|
|
|
|
os.remove(audio_path) |
|
|
os.remove(wav_path) |
|
|
|