import streamlit as st import noisereduce as nr import soundfile as sf import io import numpy as np from pydub import AudioSegment # Define a Streamlit app st.title("Audio Processing App") # Upload the input audio file uploaded_audio = st.file_uploader("Upload an audio file", type=["mp3", "wav", "ogg", "flac", "wma", "m4a"]) if uploaded_audio is not None: audio_bytes = uploaded_audio.read() # Convert audio file to numpy array using soundfile audio, sample_rate = sf.read(io.BytesIO(audio_bytes)) # Apply noise reduction st.write("Applying noise reduction...") reduced_audio_data = nr.reduce_noise(y=audio, sr=sample_rate) # Create an AudioSegment from the reduced audio data reduced_audio = AudioSegment( reduced_audio_data.tobytes(), frame_rate=sample_rate, sample_width=2, # Change this to 1 or 4 if necessary channels=1 ) # Slow down the audio based on user's input speed factor st.write("Slowing down audio...") slowed_audio = reduced_audio.speedup(playback_speed=0.7) # Provide a link to download the processed audio st.audio(slowed_audio.export(format="wav").read(), format="audio/wav") # Run the Streamlit app if __name__ == "__main__": st.write("Upload an audio file to process.")