Rhueue commited on
Commit
a1e51b2
·
1 Parent(s): c0d6538

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -15
app.py CHANGED
@@ -4,7 +4,6 @@ import soundfile as sf
4
  import io
5
  import numpy as np
6
  from pydub import AudioSegment
7
- from pydub import effects
8
 
9
  # Define a Streamlit app
10
  st.title("Audio Processing App")
@@ -14,32 +13,32 @@ uploaded_audio = st.file_uploader("Upload an audio file", type=["mp3", "wav"])
14
 
15
  if uploaded_audio is not None:
16
  audio_bytes = uploaded_audio.read()
17
-
18
  # Convert audio file to numpy array
19
  audio, sample_rate = sf.read(io.BytesIO(audio_bytes))
20
-
21
  # Apply noise reduction
22
  st.write("Applying noise reduction...")
23
- reduced_audio = nr.reduce_noise(y=audio, sr=sample_rate)
24
 
25
- # Convert the numpy array to an AudioSegment
26
  reduced_audio = AudioSegment(
27
- reduced_audio.tobytes(),
28
  frame_rate=sample_rate,
29
- sample_width=reduced_audio.dtype.itemsize,
30
- channels=1 # Assuming mono audio
31
  )
32
 
33
- # Set the speed factor
34
- st.write("Setting speed factor...")
35
- speeded_audio = reduced_audio.speedup(0.76) # Adjust the speed factor as needed
36
 
37
- # Export the modified audio to a file
38
- speeded_audio.export("output_audio.wav", format="wav")
39
 
40
- # Provide a link to download 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 apply noise reduction and set the speed factor.")
 
4
  import io
5
  import numpy as np
6
  from pydub import AudioSegment
 
7
 
8
  # Define a Streamlit app
9
  st.title("Audio Processing App")
 
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_data = nr.reduce_noise(y=audio, sr=sample_rate)
23
 
24
+ # Create an AudioSegment from the reduced audio data
25
  reduced_audio = AudioSegment(
26
+ reduced_audio_data.tobytes(),
27
  frame_rate=sample_rate,
28
+ sample_width=reduced_audio_data.dtype.itemsize,
29
+ channels=1
30
  )
31
 
32
+ # Slow down the audio
33
+ st.write("Slowing down audio...")
34
+ slowed_audio = reduced_audio.speedup(playback_speed=0.7)
35
 
36
+ # Export the slowed audio to a file
37
+ slowed_audio.export("output_audio.wav", format="wav")
38
 
39
+ # Provide the download link for 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 process.")