File size: 1,188 Bytes
1b95475 6447be5 136ed2d ff25f09 6447be5 1b95475 6447be5 1b95475 ff25f09 6447be5 ef02f31 6447be5 ef02f31 6447be5 ef02f31 6447be5 1b95475 ff25f09 ef02f31 1b95475 6447be5 1b95475 ff25f09 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
import streamlit as st
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))
# Convert the audio to 16-bit to avoid unsupported 24-bit formats
audio = (audio * 32767).astype(np.int16)
# Create an AudioSegment from the audio data
audio_segment = AudioSegment(
audio.tobytes(),
frame_rate=sample_rate,
sample_width=2,
channels=1
)
# Slow down the audio based on user's input speed factor
st.write("Slowing down audio...")
slowed_audio = audio_segment.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.")
|