Jordy02 commited on
Commit
41fb2f1
·
1 Parent(s): 0acc83a

Testing on server

Browse files
Files changed (1) hide show
  1. app.py +62 -2
app.py CHANGED
@@ -1,5 +1,65 @@
1
  import streamlit as st
 
 
 
 
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import noisereduce as nr
3
+ import soundfile as sf
4
+ from pedalboard import NoiseGate, Compressor
5
+ import numpy as np
6
+ from io import BytesIO
7
 
8
+ # Function to remove background noise and process audio
 
9
 
10
+
11
+ def process_audio(input_file):
12
+ # Load the audio file
13
+ data, sr = sf.read(input_file)
14
+
15
+ # Reduce stationary noise using noisereduce
16
+ reduced_noise = nr.reduce_noise(y=data, sr=sr)
17
+
18
+ # Create a noise gate to further reduce noise using pedalboard
19
+ noise_gate = NoiseGate(threshold=0.02, attack=10, release=100)
20
+ # Create a compressor to enhance the audio
21
+ compressor = Compressor(threshold_db=-25, ratio=3,
22
+ attack_ms=10, release_ms=200)
23
+
24
+ # Create a pedalboard and add the noise gate and compressor to it
25
+ board = noise_gate >> compressor
26
+
27
+ # Process the audio through the pedalboard
28
+ processed_audio = board(np.array([reduced_noise]))
29
+
30
+ return processed_audio, sr
31
+
32
+
33
+ def main():
34
+ st.title("Background Noise Reduction")
35
+
36
+ # Upload audio file
37
+ uploaded_file = st.file_uploader("Upload audio file", type=["wav"])
38
+
39
+ if uploaded_file is not None:
40
+ # Process the audio
41
+ st.write("Processing audio...")
42
+ processed_audio, sr = process_audio(uploaded_file)
43
+
44
+ # Display processing progress
45
+ with st.spinner('Processing audio...'):
46
+ processed_audio_bytes = BytesIO()
47
+ sf.write(processed_audio_bytes,
48
+ processed_audio[0], sr, format='wav')
49
+ st.write("Audio processed successfully!")
50
+
51
+ # Allow user to play original and edited audio
52
+ st.subheader("Play Audio")
53
+ st.audio(uploaded_file, format='audio/wav',
54
+ start_time=0, caption='Original Audio')
55
+ st.audio(processed_audio_bytes, format='audio/wav',
56
+ start_time=0, caption='Processed Audio')
57
+
58
+ # Allow user to download processed audio
59
+ st.subheader("Download Processed Audio")
60
+ st.download_button("Download", processed_audio_bytes.getvalue(
61
+ ), file_name="processed_audio.wav", mime='audio/wav')
62
+
63
+
64
+ if __name__ == "__main__":
65
+ main()