|
import streamlit as st |
|
import logging |
|
from transformers import pipeline |
|
|
|
|
|
logging.basicConfig(level=logging.INFO) |
|
|
|
|
|
asr = pipeline(task="automatic-speech-recognition", |
|
model="distil-whisper/distil-small.en") |
|
|
|
|
|
def transcribe_speech(audio_file): |
|
if not audio_file: |
|
logging.error("No audio file provided.") |
|
return "No audio found, please retry." |
|
try: |
|
logging.info(f"Processing file: {audio_file.name}") |
|
output = asr(audio_file.name) |
|
return output[0]["transcription"] |
|
except Exception as e: |
|
logging.error(f"Error during transcription: {str(e)}") |
|
return f"Error processing the audio file: {str(e)}" |
|
|
|
|
|
st.title("Speech Recognition") |
|
|
|
uploaded_file = st.file_uploader("Upload audio file", type=["wav", "mp3"]) |
|
|
|
if uploaded_file: |
|
st.audio(uploaded_file, format='audio/wav') |
|
|
|
if st.button("Transcribe Audio"): |
|
transcription = transcribe_speech(uploaded_file) |
|
st.write("Transcription:") |
|
st.write(transcription) |
|
|
|
|