Rhueue commited on
Commit
4eef1ea
·
1 Parent(s): 389dca4

Update app.py

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