File size: 1,236 Bytes
7dbdc08
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import pipeline

# Load the speech recognition pipeline
pipe = pipeline("automatic-speech-recognition", model="AqeelShafy7/AudioSangraha-Audio_to_Text")

# Streamlit app layout
st.title("Speech to Text Transcription")

# Sidebar layout for uploading audio and processing it
st.sidebar.title("Upload Audio for Transcription")

# File uploader widget for the audio file in the sidebar
audio_file = st.sidebar.file_uploader("Upload Audio File (MP3 format)", type=["mp3"])

# Button to process the audio file
if st.sidebar.button("Process Audio"):
    if audio_file is not None:
        # Define a path for the uploaded file (within the app's directory)
        upload_path = "uploaded_audio.mp3"

        # Save the uploaded file to the defined path
        with open(upload_path, "wb") as f:
            f.write(audio_file.getbuffer())

        # Provide the file path to the pipeline
        result = pipe(upload_path)

        # Display the transcription result in the main area
        transcribed_text = result['text']
        st.text_area("Transcribed Text", transcribed_text, height=300)
    else:
        st.error("Please upload an audio file to process.")