Spaces:
Running
Running
File size: 3,955 Bytes
3f16dbd |
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
import gradio as gr
from gen import FILTER_LOWER_BOUND, FILTER_UPPER_BOUND, analyze_audio
with gr.Blocks() as app:
gr.Markdown(
"""
# Audio Feature Visualization
Upload an audio file to visualize its features and optionally apply filters. Each visualization helps in understanding different aspects of the audio signal.
"""
)
with gr.Row():
audio = gr.Audio(
sources=["upload", "microphone"],
type="filepath",
label="Audio File",
)
with gr.Row():
highpass = gr.Slider(
FILTER_LOWER_BOUND - 1,
FILTER_UPPER_BOUND,
step=1,
label="High-pass filter cutoff frequency (Hz).",
info="Frequency above which signals are allowed to pass through.",
value=FILTER_LOWER_BOUND - 1,
)
lowpass = gr.Slider(
FILTER_LOWER_BOUND - 1,
FILTER_UPPER_BOUND,
step=1,
label="Low-pass filter cutoff frequency (Hz).",
info="Frequency below which signals are allowed to pass through.",
value=FILTER_LOWER_BOUND - 1,
)
with gr.Row():
bandpass_low = gr.Slider(
FILTER_LOWER_BOUND - 1,
FILTER_UPPER_BOUND,
step=1,
label="Band-pass filter low cutoff frequency (Hz).",
info="Lower frequency bound for band-pass filter.",
value=FILTER_LOWER_BOUND - 1,
)
bandpass_high = gr.Slider(
FILTER_LOWER_BOUND - 1,
FILTER_UPPER_BOUND,
step=1,
label="Band-pass filter high cutoff frequency (Hz).",
info="Higher frequency bound for band-pass filter.",
value=FILTER_LOWER_BOUND - 1,
)
btn = gr.Button("Visualize Features", variant="primary")
with gr.Row():
waveform = gr.Image(
label="Waveform: Visual representation of the audio signal over time."
)
with gr.Row():
spectrogram = gr.Image(
label="Spectrogram: Graphical representation of the spectrum of frequencies in a sound signal as they vary with time."
)
mfcc = gr.Image(
label="MFCC: Mel-frequency cepstral coefficients, representing the short-term power spectrum of a sound."
)
with gr.Row():
rms_energy = gr.Image(
label="RMS Energy: Root Mean Square energy of the audio signal."
)
zero_crossing_rate = gr.Image(
label="Zero Crossing Rate: Rate at which the signal changes from positive to negative or back."
)
with gr.Row():
spectral_centroid = gr.Image(
label="Spectral Centroid: Indicates where the center of mass of the spectrum is located."
)
spectral_bandwidth = gr.Image(
label="Spectral Bandwidth: The width of a range of frequencies."
)
with gr.Row():
spectral_rolloff = gr.Image(
label="Spectral Rolloff: Frequency below which a specified percentage of the total spectral energy lies."
)
spectral_contrast = gr.Image(
label="Spectral Contrast: Difference in amplitude between peaks and valleys in a sound spectrum."
)
with gr.Row():
tempo = gr.Image(label="Tempo: Estimated tempo of the audio signal.")
tempogram = gr.Image(
label="Tempogram: Localized autocorrelation of the onset strength envelope."
)
btn.click(
fn=analyze_audio,
inputs=[audio, highpass, lowpass, bandpass_low, bandpass_high],
outputs=[
waveform,
spectrogram,
mfcc,
zero_crossing_rate,
spectral_centroid,
spectral_bandwidth,
rms_energy,
spectral_contrast,
spectral_rolloff,
tempo,
tempogram,
],
)
|