Rhueue commited on
Commit
ef02f31
1 Parent(s): ff25f09

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -10
app.py CHANGED
@@ -1,7 +1,5 @@
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
 
@@ -17,21 +15,20 @@ if uploaded_audio is not None:
17
  # Convert audio file to numpy array using soundfile
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=2, # Change this to 1 or 4 if necessary
29
  channels=1
30
  )
31
 
32
  # Slow down the audio based on user's input speed factor
33
  st.write("Slowing down audio...")
34
- slowed_audio = reduced_audio.speedup(playback_speed=0.7)
35
 
36
  # Provide a link to download the processed audio
37
  st.audio(slowed_audio.export(format="wav").read(), format="audio/wav")
 
1
  import streamlit as st
 
2
  import soundfile as sf
 
3
  import numpy as np
4
  from pydub import AudioSegment
5
 
 
15
  # Convert audio file to numpy array using soundfile
16
  audio, sample_rate = sf.read(io.BytesIO(audio_bytes))
17
 
18
+ # Convert the audio to 16-bit to avoid unsupported 24-bit formats
19
+ audio = (audio * 32767).astype(np.int16)
 
20
 
21
+ # Create an AudioSegment from the audio data
22
+ audio_segment = AudioSegment(
23
+ audio.tobytes(),
24
  frame_rate=sample_rate,
25
+ sample_width=2,
26
  channels=1
27
  )
28
 
29
  # Slow down the audio based on user's input speed factor
30
  st.write("Slowing down audio...")
31
+ slowed_audio = audio_segment.speedup(playback_speed=0.7)
32
 
33
  # Provide a link to download the processed audio
34
  st.audio(slowed_audio.export(format="wav").read(), format="audio/wav")