Spaces:
Running
Running
ageraustine
commited on
Commit
•
4bc7c2a
1
Parent(s):
1f1c05d
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import librosa # Library for audio processing
|
3 |
+
|
4 |
+
def main():
|
5 |
+
"""
|
6 |
+
This function creates a Streamlit app for uploading an audio file and processing it.
|
7 |
+
"""
|
8 |
+
# Title and description
|
9 |
+
st.title("Audio Uploader and Processor")
|
10 |
+
st.write("Upload your audio file below:")
|
11 |
+
|
12 |
+
# File uploader with specific file types allowed
|
13 |
+
uploaded_file = st.file_uploader("Choose an audio file", type=["mp3", "wav"])
|
14 |
+
|
15 |
+
if uploaded_file is not None:
|
16 |
+
# Display uploaded file details
|
17 |
+
st.write("Uploaded file details:")
|
18 |
+
st.write(" - Name:", uploaded_file.name)
|
19 |
+
st.write(" - Type:", uploaded_file.type)
|
20 |
+
st.write(" - Size:", uploaded_file.size, "bytes")
|
21 |
+
|
22 |
+
# Read the audio bytes
|
23 |
+
audio_bytes = uploaded_file.read()
|
24 |
+
|
25 |
+
# Load audio as NumPy array using librosa
|
26 |
+
try:
|
27 |
+
audio, sample_rate = librosa.load(audio_bytes, sr=None) # Load without resampling
|
28 |
+
except Exception as e:
|
29 |
+
st.error(f"Error loading audio: {e}")
|
30 |
+
return
|
31 |
+
|
32 |
+
# Get the first 15 seconds of audio (assuming sample rate is available)
|
33 |
+
if sample_rate:
|
34 |
+
duration = 15
|
35 |
+
first_15_seconds = audio[:int(sample_rate * duration)]
|
36 |
+
|
37 |
+
# Display the NumPy array (optional)
|
38 |
+
# st.write("First 15 seconds as NumPy array:", first_15_seconds)
|
39 |
+
|
40 |
+
# You can now perform further processing on the 'first_15_seconds' array
|
41 |
+
# ...
|
42 |
+
|
43 |
+
else:
|
44 |
+
st.warning("Could not determine sample rate. Skipping 15-second extraction.")
|
45 |
+
|
46 |
+
if __name__ == "__main__":
|
47 |
+
main()
|