|
import streamlit as st |
|
import noisereduce as nr |
|
import soundfile as sf |
|
import io |
|
from pydub import AudioSegment |
|
|
|
|
|
st.title("Audio Processing App") |
|
|
|
|
|
uploaded_audio = st.file_uploader("Upload an audio file", type=["mp3", "wav", "ogg", "flac", "wma", "m4a"]) |
|
|
|
|
|
speed_factor = st.slider("Playback Speed", min_value=0.1, max_value=2.0, step=0.1, value=1.0) |
|
|
|
if uploaded_audio is not None: |
|
audio_bytes = uploaded_audio.read() |
|
|
|
|
|
audio, sample_rate = sf.read(io.BytesIO(audio_bytes)) |
|
|
|
|
|
st.write("Applying noise reduction...") |
|
reduced_audio_data = nr.reduce_noise(y=audio, sr=sample_rate) |
|
|
|
|
|
reduced_audio = AudioSegment( |
|
reduced_audio_data.tobytes(), |
|
frame_rate=sample_rate, |
|
sample_width=reduced_audio_data.dtype.itemsize, |
|
channels=1 |
|
) |
|
|
|
|
|
st.write(f"Slowing down audio to {speed_factor}x speed...") |
|
slowed_audio = reduced_audio.speedup(playback_speed=1/speed_factor) |
|
|
|
|
|
st.audio(slowed_audio.export(format="wav").read(), format="audio/wav") |
|
|
|
|
|
if __name__ == "__main__": |
|
st.write("Upload an audio file, set the playback speed, and apply noise reduction.") |
|
|