Rhueue commited on
Commit
180e0b3
·
1 Parent(s): 3df02ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -31
app.py CHANGED
@@ -1,45 +1,28 @@
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")
7
 
8
  # Upload the input audio file
9
  uploaded_audio = st.file_uploader("Upload an audio file", type=["mp3", "wav"])
10
 
11
  if uploaded_audio is not None:
12
- # Load the input audio
13
- audio = AudioSegment.from_file(uploaded_audio)
14
-
15
- # Apply noise reduction using noisereduce
16
- st.write("Applying noise reduction...")
17
 
18
- # Convert audio to numpy array
19
- audio_data = audio.get_array_of_samples()
20
- reduced_audio_data = nr.reduce_noise(y=audio_data, sr=audio.frame_rate)
21
-
22
- # Create a new AudioSegment from the reduced audio data
23
- reduced_audio = AudioSegment(
24
- reduced_audio_data.tobytes(),
25
- frame_rate=audio.frame_rate,
26
- sample_width=reduced_audio_data.dtype.itemsize,
27
- channels=1 # Assuming mono audio
28
- )
29
-
30
- # Slow down the audio
31
- st.write("Slowing down audio...")
32
- slowed_audio = reduced_audio.speedup(playback_speed=0.7) # Adjust the speed factor as needed
33
-
34
- # Generate a new audio file
35
- st.write("Generating output audio...")
36
-
37
- # Export the slowed audio to a file
38
- slowed_audio.export("output_audio.wav", format="wav")
39
 
40
- # Provide the download link for the processed audio
41
- st.audio("output_audio.wav")
42
 
43
  # Run the Streamlit app
44
  if __name__ == "__main__":
45
- st.write("Upload an audio file to get started.")
 
1
  import streamlit as st
2
  import noisereduce as nr
3
+ import soundfile as sf
4
+ import io
5
+ import numpy as np
6
 
7
  # Define a Streamlit app
8
+ st.title("Audio Noise Reduction App")
9
 
10
  # Upload the input audio file
11
  uploaded_audio = st.file_uploader("Upload an audio file", type=["mp3", "wav"])
12
 
13
  if uploaded_audio is not None:
14
+ audio_bytes = uploaded_audio.read()
 
 
 
 
15
 
16
+ # Convert audio file to numpy array
17
+ audio, sample_rate = sf.read(io.BytesIO(audio_bytes))
18
+
19
+ # Apply noise reduction
20
+ st.write("Applying noise reduction...")
21
+ reduced_audio = nr.reduce_noise(y=audio, sr=sample_rate)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
+ # Provide a link to download the processed audio
24
+ st.audio(reduced_audio, format="audio/wav")
25
 
26
  # Run the Streamlit app
27
  if __name__ == "__main__":
28
+ st.write("Upload an audio file to apply noise reduction.")