Spaces:
Runtime error
Runtime error
Final Project
Browse files
app.py
CHANGED
|
@@ -6,9 +6,13 @@ import numpy as np
|
|
| 6 |
from io import BytesIO
|
| 7 |
import librosa
|
| 8 |
|
|
|
|
|
|
|
| 9 |
|
| 10 |
def process_audio(input_file):
|
|
|
|
| 11 |
sr = 44100
|
|
|
|
| 12 |
with AudioFile(input_file).resampled_to(sr) as f:
|
| 13 |
audio = f.read(f.frames)
|
| 14 |
|
|
@@ -16,7 +20,7 @@ def process_audio(input_file):
|
|
| 16 |
reduced_noise = nr.reduce_noise(
|
| 17 |
y=audio, sr=sr, stationary=True, prop_decrease=0.75)
|
| 18 |
|
| 19 |
-
# Apply audio effects
|
| 20 |
board = Pedalboard([
|
| 21 |
NoiseGate(threshold_db=-30, ratio=1.5, release_ms=250),
|
| 22 |
Compressor(threshold_db=-16, ratio=2.5),
|
|
@@ -28,6 +32,8 @@ def process_audio(input_file):
|
|
| 28 |
|
| 29 |
return processed_audio, sr
|
| 30 |
|
|
|
|
|
|
|
| 31 |
|
| 32 |
def detect_plosives(audio, sr):
|
| 33 |
# Define frequency bands for plosive detection
|
|
@@ -64,6 +70,8 @@ def detect_plosives(audio, sr):
|
|
| 64 |
|
| 65 |
return plosives
|
| 66 |
|
|
|
|
|
|
|
| 67 |
|
| 68 |
def main():
|
| 69 |
st.title("Audio Enhancement")
|
|
@@ -80,11 +88,7 @@ def main():
|
|
| 80 |
st.write("Audio processed successfully!")
|
| 81 |
|
| 82 |
# Allow user to play original and processed audio
|
| 83 |
-
|
| 84 |
-
# st.audio(uploaded_file, format='audio/wav', start_time=0)
|
| 85 |
-
# st.audio(processed_audio, format='audio/wav',
|
| 86 |
-
# start_time=0, sample_rate=None)
|
| 87 |
-
st.subheader("Play Origional Audio")
|
| 88 |
st.audio(uploaded_file, format='audio/wav', start_time=0)
|
| 89 |
st.subheader("Play Enhanced Audio")
|
| 90 |
st.audio(processed_audio, format='audio/wav',
|
|
@@ -110,5 +114,6 @@ def main():
|
|
| 110 |
st.write("No plosives detected.")
|
| 111 |
|
| 112 |
|
|
|
|
| 113 |
if __name__ == "__main__":
|
| 114 |
main()
|
|
|
|
| 6 |
from io import BytesIO
|
| 7 |
import librosa
|
| 8 |
|
| 9 |
+
# Function to process audio
|
| 10 |
+
|
| 11 |
|
| 12 |
def process_audio(input_file):
|
| 13 |
+
# Set sampling rate
|
| 14 |
sr = 44100
|
| 15 |
+
# Read audio file
|
| 16 |
with AudioFile(input_file).resampled_to(sr) as f:
|
| 17 |
audio = f.read(f.frames)
|
| 18 |
|
|
|
|
| 20 |
reduced_noise = nr.reduce_noise(
|
| 21 |
y=audio, sr=sr, stationary=True, prop_decrease=0.75)
|
| 22 |
|
| 23 |
+
# Apply audio effects using pedalboard
|
| 24 |
board = Pedalboard([
|
| 25 |
NoiseGate(threshold_db=-30, ratio=1.5, release_ms=250),
|
| 26 |
Compressor(threshold_db=-16, ratio=2.5),
|
|
|
|
| 32 |
|
| 33 |
return processed_audio, sr
|
| 34 |
|
| 35 |
+
# Function to detect plosives in audio
|
| 36 |
+
|
| 37 |
|
| 38 |
def detect_plosives(audio, sr):
|
| 39 |
# Define frequency bands for plosive detection
|
|
|
|
| 70 |
|
| 71 |
return plosives
|
| 72 |
|
| 73 |
+
# Main function
|
| 74 |
+
|
| 75 |
|
| 76 |
def main():
|
| 77 |
st.title("Audio Enhancement")
|
|
|
|
| 88 |
st.write("Audio processed successfully!")
|
| 89 |
|
| 90 |
# Allow user to play original and processed audio
|
| 91 |
+
st.subheader("Play Original Audio")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
st.audio(uploaded_file, format='audio/wav', start_time=0)
|
| 93 |
st.subheader("Play Enhanced Audio")
|
| 94 |
st.audio(processed_audio, format='audio/wav',
|
|
|
|
| 114 |
st.write("No plosives detected.")
|
| 115 |
|
| 116 |
|
| 117 |
+
# Entry point of the program
|
| 118 |
if __name__ == "__main__":
|
| 119 |
main()
|