Rhueue commited on
Commit
6447be5
1 Parent(s): 581e69d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -12
app.py CHANGED
@@ -1,28 +1,43 @@
1
  import streamlit as st
2
- from pydub import AudioSegment
3
- from pydub.playback import _play_with_simpleaudio as play_sound
4
  import io
 
5
 
6
  # Define a Streamlit app
7
- st.title("Audio Speed Reduction App")
8
 
9
  # Upload the input audio file
10
  uploaded_audio = st.file_uploader("Upload an audio file", type=["mp3", "wav", "ogg", "flac", "wma", "m4a"])
11
 
 
 
 
12
  if uploaded_audio is not None:
13
  audio_bytes = uploaded_audio.read()
14
 
15
- # Convert audio file to AudioSegment
16
- audio = AudioSegment.from_file(io.BytesIO(audio_bytes))
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
- # Slow down the audio using the speed_change_ratio
19
- st.write("Slowing down audio...")
20
- speed_change_ratio = 0.7
21
- slowed_audio = audio.speedup(playback_speed=1/speed_change_ratio)
22
 
23
- # Play the slowed down audio
24
- play_sound(slowed_audio)
25
 
26
  # Run the Streamlit app
27
  if __name__ == "__main__":
28
- st.write("Upload an audio file to apply speed reduction.")
 
1
  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
8
+ st.title("Audio Processing App")
9
 
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
23
+ st.write("Applying noise reduction...")
24
+ reduced_audio_data = nr.reduce_noise(y=audio, sr=sample_rate)
25
+
26
+ # Create an AudioSegment from the reduced audio data
27
+ reduced_audio = AudioSegment(
28
+ reduced_audio_data.tobytes(),
29
+ frame_rate=sample_rate,
30
+ sample_width=reduced_audio_data.dtype.itemsize,
31
+ channels=1
32
+ )
33
 
34
+ # Slow down the audio based on the user's input speed factor
35
+ st.write(f"Slowing down audio to {speed_factor}x speed...")
36
+ slowed_audio = reduced_audio.speedup(playback_speed=1/speed_factor)
 
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, set the playback speed, and apply noise reduction.")