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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -14
app.py CHANGED
@@ -1,10 +1,11 @@
 
 
 
1
  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
- from scipy.io.wavfile import write
8
 
9
  # Define a Streamlit app
10
  st.title("Audio Processing App")
@@ -17,7 +18,7 @@ if uploaded_audio is not None:
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_data = nr.reduce_noise(y=audio, sr=sample_rate)
@@ -30,18 +31,13 @@ if uploaded_audio is not None:
30
  channels=1
31
  )
32
 
33
- # Save the reduced audio as a temporary 16-bit wave file
34
- reduced_audio.export("reduced_audio.wav", format="wav")
35
-
36
- # Load the 16-bit wave file and slow it down
37
- slowed_audio = AudioSegment.from_wav("reduced_audio.wav")
38
- slowed_audio = slowed_audio.speedup(playback_speed=0.7)
39
-
40
- # Save the slowed down audio as a WAV file with 16-bit sample width using scipy
41
- write("output_audio.wav", slowed_audio.frame_rate, slowed_audio.get_array_of_samples())
42
 
43
- # Provide the download link for the processed audio
44
- st.audio("output_audio.wav")
45
 
46
  # Run the Streamlit app
47
  if __name__ == "__main__":
 
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")
 
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)
 
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__":