Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,43 @@
|
|
1 |
import streamlit as st
|
2 |
-
|
3 |
-
|
4 |
import io
|
|
|
5 |
|
6 |
# Define a Streamlit app
|
7 |
-
st.title("Audio
|
8 |
|
9 |
# Upload the input audio file
|
10 |
uploaded_audio = st.file_uploader("Upload an audio file", type=["mp3", "wav", "ogg", "flac", "wma", "m4a"])
|
11 |
|
|
|
|
|
|
|
12 |
if uploaded_audio is not None:
|
13 |
audio_bytes = uploaded_audio.read()
|
14 |
|
15 |
-
# Convert audio file to
|
16 |
-
audio =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
# Slow down the audio
|
19 |
-
st.write("Slowing down audio...")
|
20 |
-
|
21 |
-
slowed_audio = audio.speedup(playback_speed=1/speed_change_ratio)
|
22 |
|
23 |
-
#
|
24 |
-
|
25 |
|
26 |
# Run the Streamlit app
|
27 |
if __name__ == "__main__":
|
28 |
-
st.write("Upload an audio file
|
|
|
1 |
import streamlit as st
|
2 |
+
import noisereduce as nr
|
3 |
+
import soundfile as sf
|
4 |
import io
|
5 |
+
from pydub import AudioSegment
|
6 |
|
7 |
# Define a Streamlit app
|
8 |
+
st.title("Audio Processing App")
|
9 |
|
10 |
# Upload the input audio file
|
11 |
uploaded_audio = st.file_uploader("Upload an audio file", type=["mp3", "wav", "ogg", "flac", "wma", "m4a"])
|
12 |
|
13 |
+
# Speed factor input
|
14 |
+
speed_factor = st.slider("Playback Speed", min_value=0.1, max_value=2.0, step=0.1, value=1.0)
|
15 |
+
|
16 |
if uploaded_audio is not None:
|
17 |
audio_bytes = uploaded_audio.read()
|
18 |
|
19 |
+
# Convert audio file to numpy array
|
20 |
+
audio, sample_rate = sf.read(io.BytesIO(audio_bytes))
|
21 |
+
|
22 |
+
# Apply noise reduction
|
23 |
+
st.write("Applying noise reduction...")
|
24 |
+
reduced_audio_data = nr.reduce_noise(y=audio, sr=sample_rate)
|
25 |
+
|
26 |
+
# Create an AudioSegment from the reduced audio data
|
27 |
+
reduced_audio = AudioSegment(
|
28 |
+
reduced_audio_data.tobytes(),
|
29 |
+
frame_rate=sample_rate,
|
30 |
+
sample_width=reduced_audio_data.dtype.itemsize,
|
31 |
+
channels=1
|
32 |
+
)
|
33 |
|
34 |
+
# Slow down the audio based on the user's input speed factor
|
35 |
+
st.write(f"Slowing down audio to {speed_factor}x speed...")
|
36 |
+
slowed_audio = reduced_audio.speedup(playback_speed=1/speed_factor)
|
|
|
37 |
|
38 |
+
# Provide a link to download the processed audio
|
39 |
+
st.audio(slowed_audio.export(format="wav").read(), format="audio/wav")
|
40 |
|
41 |
# Run the Streamlit app
|
42 |
if __name__ == "__main__":
|
43 |
+
st.write("Upload an audio file, set the playback speed, and apply noise reduction.")
|