Rhueue commited on
Commit
bfc8ade
·
1 Parent(s): 55714c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -28
app.py CHANGED
@@ -1,44 +1,29 @@
1
- from pydub import AudioSegment
2
- from pydub.playback import _play_with_simpleaudio as play_sound
3
- import audio_effects as ae
4
  import streamlit as st
5
- import noisereduce as nr
6
- import soundfile as sf
7
  import io
8
- import numpy as np
9
 
10
  # Define a Streamlit app
11
- st.title("Audio Processing App")
12
 
13
  # Upload the input audio file
14
- uploaded_audio = st.file_uploader("Upload an audio file", type=["mp3", "wav"])
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 using the speed_down function from audio_effects
35
  st.write("Slowing down audio...")
36
- speed_change_ratio = 0.7
37
- slowed_audio = ae.speed_down(reduced_audio, speed_change_ratio)
 
 
38
 
39
- # Play the slowed down audio
40
- play_sound(slowed_audio)
41
 
42
  # Run the Streamlit app
43
  if __name__ == "__main__":
44
- st.write("Upload an audio file to process.")
 
 
 
 
1
  import streamlit as st
2
+ from pydub import AudioSegment
 
3
  import io
 
4
 
5
  # Define a Streamlit app
6
+ st.title("Audio Speed Reduction App")
7
 
8
  # Upload the input audio file
9
+ uploaded_audio = st.file_uploader("Upload an audio file", type=["mp3", "wav", "ogg", "flac", "wma", "m4a"])
10
 
11
  if uploaded_audio is not None:
12
  audio_bytes = uploaded_audio.read()
13
 
14
+ # Convert audio file to AudioSegment
15
+ audio = AudioSegment.from_file(io.BytesIO(audio_bytes))
 
 
 
 
16
 
17
+ # Slow down the audio by changing the playback speed
 
 
 
 
 
 
 
 
18
  st.write("Slowing down audio...")
19
+ slowed_audio = audio.speedup(playback_speed=0.5)
20
+
21
+ # Convert the slowed audio to bytes
22
+ slowed_audio_bytes = slowed_audio.export(format="wav").read()
23
 
24
+ # Provide a link to download the processed audio
25
+ st.audio(slowed_audio_bytes, format="audio/wav")
26
 
27
  # Run the Streamlit app
28
  if __name__ == "__main__":
29
+ st.write("Upload an audio file to apply speed reduction.")