Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ 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
|
@@ -10,13 +11,10 @@ st.title("Audio Processing App")
|
|
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
|
@@ -27,17 +25,17 @@ if uploaded_audio is not None:
|
|
27 |
reduced_audio = AudioSegment(
|
28 |
reduced_audio_data.tobytes(),
|
29 |
frame_rate=sample_rate,
|
30 |
-
sample_width=
|
31 |
channels=1
|
32 |
)
|
33 |
|
34 |
-
# Slow down the audio based on
|
35 |
-
st.write(
|
36 |
-
slowed_audio = reduced_audio.speedup(playback_speed=
|
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
|
|
|
2 |
import noisereduce as nr
|
3 |
import soundfile as sf
|
4 |
import io
|
5 |
+
import numpy as np
|
6 |
from pydub import AudioSegment
|
7 |
|
8 |
# Define a Streamlit app
|
|
|
11 |
# Upload the input audio file
|
12 |
uploaded_audio = st.file_uploader("Upload an audio file", type=["mp3", "wav", "ogg", "flac", "wma", "m4a"])
|
13 |
|
|
|
|
|
|
|
14 |
if uploaded_audio is not None:
|
15 |
audio_bytes = uploaded_audio.read()
|
16 |
|
17 |
+
# Convert audio file to numpy array using soundfile
|
18 |
audio, sample_rate = sf.read(io.BytesIO(audio_bytes))
|
19 |
|
20 |
# Apply noise reduction
|
|
|
25 |
reduced_audio = AudioSegment(
|
26 |
reduced_audio_data.tobytes(),
|
27 |
frame_rate=sample_rate,
|
28 |
+
sample_width=2, # Change this to 1 or 4 if necessary
|
29 |
channels=1
|
30 |
)
|
31 |
|
32 |
+
# Slow down the audio based on user's input speed factor
|
33 |
+
st.write("Slowing down audio...")
|
34 |
+
slowed_audio = reduced_audio.speedup(playback_speed=0.7)
|
35 |
|
36 |
# Provide a link to download the processed audio
|
37 |
st.audio(slowed_audio.export(format="wav").read(), format="audio/wav")
|
38 |
|
39 |
# Run the Streamlit app
|
40 |
if __name__ == "__main__":
|
41 |
+
st.write("Upload an audio file to process.")
|