Update app.py
Browse files
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 |
-
#
|
21 |
-
|
22 |
-
reduced_audio_data = nr.reduce_noise(y=audio, sr=sample_rate)
|
23 |
|
24 |
-
# Create an AudioSegment from the
|
25 |
-
|
26 |
-
|
27 |
frame_rate=sample_rate,
|
28 |
-
sample_width=2,
|
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 =
|
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")
|