import streamlit as st import logging from transformers import pipeline # Setup logging logging.basicConfig(level=logging.INFO) # Load automatic speech recognition (ASR) pipeline asr = pipeline(task="automatic-speech-recognition", model="distil-whisper/distil-small.en") # Function for transcribing speech 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) # Assuming `asr` directly takes a file path 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)}" # Streamlit UI 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)