Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
import noisereduce as nr
|
3 |
from pydub import AudioSegment
|
|
|
4 |
|
5 |
# Define a Streamlit app
|
6 |
st.title("Audio Processing App")
|
@@ -9,25 +10,35 @@ st.title("Audio Processing App")
|
|
9 |
uploaded_audio = st.file_uploader("Upload an audio file", type=["mp3", "wav"])
|
10 |
|
11 |
if uploaded_audio is not None:
|
12 |
-
#
|
13 |
-
# You may need to adjust the parameters for your specific audio
|
14 |
-
st.write("Cleaning audio...")
|
15 |
-
# Load the audio file
|
16 |
audio = AudioSegment.from_file(uploaded_audio)
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
# Slow down the audio
|
23 |
st.write("Slowing down audio...")
|
24 |
-
slowed_audio =
|
25 |
|
26 |
# Generate a new audio file
|
27 |
st.write("Generating output audio...")
|
|
|
|
|
28 |
slowed_audio.export("output_audio.wav", format="wav")
|
29 |
|
30 |
-
# Provide the download link for the
|
31 |
st.audio("output_audio.wav")
|
32 |
|
33 |
# Run the Streamlit app
|
|
|
1 |
import streamlit as st
|
2 |
import noisereduce as nr
|
3 |
from pydub import AudioSegment
|
4 |
+
import numpy as np
|
5 |
|
6 |
# Define a Streamlit app
|
7 |
st.title("Audio Processing App")
|
|
|
10 |
uploaded_audio = st.file_uploader("Upload an audio file", type=["mp3", "wav"])
|
11 |
|
12 |
if uploaded_audio is not None:
|
13 |
+
# Load the input audio
|
|
|
|
|
|
|
14 |
audio = AudioSegment.from_file(uploaded_audio)
|
15 |
+
|
16 |
+
# Convert audio to numpy array
|
17 |
+
audio_data = np.array(audio.get_array_of_samples())
|
18 |
+
|
19 |
+
# Apply noise reduction using noisereduce
|
20 |
+
st.write("Applying noise reduction...")
|
21 |
+
reduced_audio_data = nr.reduce_noise(y=audio_data, sr=audio.frame_rate)
|
22 |
+
|
23 |
+
# Convert the processed audio data back to AudioSegment
|
24 |
+
reduced_audio = AudioSegment(
|
25 |
+
reduced_audio_data.tobytes(),
|
26 |
+
frame_rate=audio.frame_rate,
|
27 |
+
sample_width=reduced_audio_data.dtype.itemsize,
|
28 |
+
channels=1 # Assuming mono audio
|
29 |
+
)
|
30 |
|
31 |
# Slow down the audio
|
32 |
st.write("Slowing down audio...")
|
33 |
+
slowed_audio = reduced_audio.speedup(playback_speed=0.7) # Adjust the speed factor as needed
|
34 |
|
35 |
# Generate a new audio file
|
36 |
st.write("Generating output audio...")
|
37 |
+
|
38 |
+
# Export the slowed audio to a file
|
39 |
slowed_audio.export("output_audio.wav", format="wav")
|
40 |
|
41 |
+
# Provide the download link for the processed audio
|
42 |
st.audio("output_audio.wav")
|
43 |
|
44 |
# Run the Streamlit app
|