File size: 1,176 Bytes
eb91cf4
5ca36ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71f3eaf
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
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)