Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import os
|
2 |
import numpy as np
|
|
|
3 |
from pydub import AudioSegment
|
4 |
import streamlit as st
|
5 |
from io import BytesIO
|
@@ -108,24 +109,35 @@ def main():
|
|
108 |
# Process and save files
|
109 |
if st.button("Process Audio"):
|
110 |
if uploaded_files:
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
|
|
|
|
|
|
|
|
129 |
else:
|
130 |
st.warning("Please upload at least one audio file.")
|
131 |
|
|
|
1 |
import os
|
2 |
import numpy as np
|
3 |
+
import zipfile
|
4 |
from pydub import AudioSegment
|
5 |
import streamlit as st
|
6 |
from io import BytesIO
|
|
|
109 |
# Process and save files
|
110 |
if st.button("Process Audio"):
|
111 |
if uploaded_files:
|
112 |
+
zip_buffer = BytesIO()
|
113 |
+
with zipfile.ZipFile(zip_buffer, "w") as zf:
|
114 |
+
for uploaded_file in uploaded_files:
|
115 |
+
st.write(f"Processing {uploaded_file.name}...")
|
116 |
+
audio_data = BytesIO(uploaded_file.read())
|
117 |
+
|
118 |
+
noisy_audio = add_noise(audio_data, noise_type, noise_level, start_time, end_time)
|
119 |
+
if noisy_audio:
|
120 |
+
# Rename file based on noise type
|
121 |
+
base_name, ext = os.path.splitext(uploaded_file.name)
|
122 |
+
output_name = f"{noise_type}_{base_name}.wav"
|
123 |
+
|
124 |
+
# Save to in-memory buffer
|
125 |
+
buffer = BytesIO()
|
126 |
+
noisy_audio.export(buffer, format="wav")
|
127 |
+
buffer.seek(0)
|
128 |
+
|
129 |
+
# Add to zip archive
|
130 |
+
zf.writestr(output_name, buffer.read())
|
131 |
+
st.success(f"Added {noise_type} noise to {uploaded_file.name}.")
|
132 |
|
133 |
+
zip_buffer.seek(0)
|
134 |
+
st.write("### Download All Processed Files")
|
135 |
+
st.download_button(
|
136 |
+
label="Download All as ZIP",
|
137 |
+
data=zip_buffer,
|
138 |
+
file_name="processed_audio_files.zip",
|
139 |
+
mime="application/zip"
|
140 |
+
)
|
141 |
else:
|
142 |
st.warning("Please upload at least one audio file.")
|
143 |
|