File size: 1,431 Bytes
5034d88
bd01872
180e0b3
 
4eef1ea
4b24336
5034d88
bd01872
4eef1ea
5034d88
bd01872
 
7cd88dd
 
180e0b3
00faab9
180e0b3
 
c29f44b
180e0b3
 
a1e51b2
4eef1ea
a1e51b2
4eef1ea
a1e51b2
39b822e
a1e51b2
 
39b822e
 
c29f44b
 
 
 
 
 
4eef1ea
a1e51b2
 
39b822e
a1e51b2
4eef1ea
bd01872
 
 
a1e51b2
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
41
42
43
44
45
46
47
48
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.")