Rhueue commited on
Commit
389dca4
·
1 Parent(s): 85fb218

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -13
app.py CHANGED
@@ -6,7 +6,7 @@ import numpy as np
6
  from pydub import AudioSegment
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"])
@@ -20,25 +20,22 @@ if uploaded_audio is not None:
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 reduced audio to an AudioSegment for further processing
25
- audio_segment = AudioSegment(
26
  reduced_audio.tobytes(),
27
  frame_rate=sample_rate,
28
- sample_width=2, # Set frame width to 2 (16-bit audio)
29
  channels=1 # Assuming mono audio
30
  )
31
-
32
- # Slow down the audio
33
- st.write("Slowing down audio...")
34
- slowed_audio = audio_segment.speedup(playback_speed=0.7) # Adjust the speed factor as needed
35
 
36
- # Export the slowed audio to a WAV 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 slow down the audio.")
 
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"])
 
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.")