Spaces:
Running
Running
import streamlit as st | |
import librosa # Library for audio processing | |
def main(): | |
""" | |
This function creates a Streamlit app for uploading an audio file and processing it. | |
""" | |
# Title and description | |
st.title("Audio Uploader and Processor") | |
st.write("Upload your audio file below:") | |
# File uploader with specific file types allowed | |
uploaded_file = st.file_uploader("Choose an audio file", type=["mp3", "wav"]) | |
if uploaded_file is not None: | |
# Display uploaded file details | |
st.write("Uploaded file details:") | |
st.write(" - Name:", uploaded_file.name) | |
st.write(" - Type:", uploaded_file.type) | |
st.write(" - Size:", uploaded_file.size, "bytes") | |
# Read the audio bytes | |
audio_bytes = uploaded_file.read() | |
# Load audio as NumPy array using librosa | |
try: | |
audio, sample_rate = librosa.load(audio_bytes, sr=None) # Load without resampling | |
except Exception as e: | |
st.error(f"Error loading audio: {e}") | |
return | |
# Get the first 15 seconds of audio (assuming sample rate is available) | |
if sample_rate: | |
duration = 15 | |
first_15_seconds = audio[:int(sample_rate * duration)] | |
# Display the NumPy array (optional) | |
# st.write("First 15 seconds as NumPy array:", first_15_seconds) | |
# You can now perform further processing on the 'first_15_seconds' array | |
# ... | |
else: | |
st.warning("Could not determine sample rate. Skipping 15-second extraction.") | |
if __name__ == "__main__": | |
main() | |