Trim / app.py
Rhueue's picture
Update app.py
c29f44b
raw
history blame
1.43 kB
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"])
if uploaded_audio is not None:
audio_bytes = uploaded_audio.read()
# Convert audio file to numpy array
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=reduced_audio_data.dtype.itemsize,
channels=1
)
# Save the reduced audio as a 16-bit wave file
reduced_audio.export("reduced_audio.wav", format="wav")
# Load the 16-bit wave file and slow it down
slowed_audio = AudioSegment.from_wav("reduced_audio.wav")
slowed_audio = slowed_audio.speedup(playback_speed=0.7)
# Export the slowed audio to a file
slowed_audio.export("output_audio.wav", format="wav")
# Provide the download link for the processed audio
st.audio("output_audio.wav")
# Run the Streamlit app
if __name__ == "__main__":
st.write("Upload an audio file to process.")