Spaces:
Sleeping
Sleeping
j-tobias
commited on
Commit
·
16d4314
1
Parent(s):
81de4d2
small updates on plots
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ import os
|
|
9 |
example_dir = "Examples"
|
10 |
example_files = [os.path.join(example_dir, f) for f in os.listdir(example_dir) if f.endswith(('.wav', '.mp3', '.ogg'))]
|
11 |
example_pairs = [list(pair) for pair in itertools.combinations(example_files, 2)][:25] # Limit to 5 pairs
|
12 |
-
|
13 |
# GENERAL HELPER FUNCTIONS
|
14 |
def getaudiodata(audio:gr.Audio)->tuple[int,np.ndarray]:
|
15 |
# Extract audio data and sample rate
|
@@ -160,12 +160,12 @@ def analyze_double(audio1:gr.Audio, audio2:gr.Audio):
|
|
160 |
def plotCombineddouble(audiodata1, sr1, audiodata2, sr2):
|
161 |
# Create subplots
|
162 |
fig = make_subplots(rows=2, cols=2, shared_xaxes=True, vertical_spacing=0.1,
|
163 |
-
subplot_titles=
|
164 |
|
165 |
# Waveform plot
|
166 |
time = (np.arange(0, len(audiodata1)) / sr1)*2
|
167 |
fig.add_trace(
|
168 |
-
go.Scatter(x=time, y=audiodata1, mode='lines',
|
169 |
row=1, col=1
|
170 |
)
|
171 |
|
@@ -177,14 +177,14 @@ def plotCombineddouble(audiodata1, sr1, audiodata2, sr2):
|
|
177 |
|
178 |
fig.add_trace(
|
179 |
go.Heatmap(z=S_db, x=times, y=freqs, colorscale='Viridis',
|
180 |
-
zmin=S_db.min(), zmax=S_db.max(), colorbar=dict(title='Magnitude (dB)')),
|
181 |
row=2, col=1
|
182 |
)
|
183 |
|
184 |
# Waveform plot
|
185 |
time = (np.arange(0, len(audiodata2)) / sr2)*2
|
186 |
fig.add_trace(
|
187 |
-
go.Scatter(x=time, y=audiodata2, mode='lines',
|
188 |
row=1, col=2
|
189 |
)
|
190 |
|
@@ -196,7 +196,7 @@ def plotCombineddouble(audiodata1, sr1, audiodata2, sr2):
|
|
196 |
|
197 |
fig.add_trace(
|
198 |
go.Heatmap(z=S_db, x=times, y=freqs, colorscale='Viridis',
|
199 |
-
zmin=S_db.min(), zmax=S_db.max(), colorbar=dict(title='Magnitude (dB)')),
|
200 |
row=2, col=2
|
201 |
)
|
202 |
|
@@ -208,6 +208,7 @@ def plotCombineddouble(audiodata1, sr1, audiodata2, sr2):
|
|
208 |
fig.update_layout(
|
209 |
height=800, width=1200,
|
210 |
title_text="Audio Analysis",
|
|
|
211 |
)
|
212 |
|
213 |
fig.update_xaxes(title_text="Time (s)", row=2, col=1)
|
|
|
9 |
example_dir = "Examples"
|
10 |
example_files = [os.path.join(example_dir, f) for f in os.listdir(example_dir) if f.endswith(('.wav', '.mp3', '.ogg'))]
|
11 |
example_pairs = [list(pair) for pair in itertools.combinations(example_files, 2)][:25] # Limit to 5 pairs
|
12 |
+
|
13 |
# GENERAL HELPER FUNCTIONS
|
14 |
def getaudiodata(audio:gr.Audio)->tuple[int,np.ndarray]:
|
15 |
# Extract audio data and sample rate
|
|
|
160 |
def plotCombineddouble(audiodata1, sr1, audiodata2, sr2):
|
161 |
# Create subplots
|
162 |
fig = make_subplots(rows=2, cols=2, shared_xaxes=True, vertical_spacing=0.1,
|
163 |
+
subplot_titles=['Audio 1 Waveform','Audio 2 Audio Waveform', 'Audio 1 Spectrogram', 'Audio 2 Spectrogram'])
|
164 |
|
165 |
# Waveform plot
|
166 |
time = (np.arange(0, len(audiodata1)) / sr1)*2
|
167 |
fig.add_trace(
|
168 |
+
go.Scatter(x=time, y=audiodata1, mode='lines', line=dict(color='blue', width=1), showlegend=False),
|
169 |
row=1, col=1
|
170 |
)
|
171 |
|
|
|
177 |
|
178 |
fig.add_trace(
|
179 |
go.Heatmap(z=S_db, x=times, y=freqs, colorscale='Viridis',
|
180 |
+
zmin=S_db.min(), zmax=S_db.max(), showlegend=False),#, colorbar=dict(title='Magnitude (dB)')),
|
181 |
row=2, col=1
|
182 |
)
|
183 |
|
184 |
# Waveform plot
|
185 |
time = (np.arange(0, len(audiodata2)) / sr2)*2
|
186 |
fig.add_trace(
|
187 |
+
go.Scatter(x=time, y=audiodata2, mode='lines', line=dict(color='blue', width=1), showlegend=False),
|
188 |
row=1, col=2
|
189 |
)
|
190 |
|
|
|
196 |
|
197 |
fig.add_trace(
|
198 |
go.Heatmap(z=S_db, x=times, y=freqs, colorscale='Viridis',
|
199 |
+
zmin=S_db.min(), zmax=S_db.max(), showlegend=False),#, colorbar=dict(title='Magnitude (dB)')),
|
200 |
row=2, col=2
|
201 |
)
|
202 |
|
|
|
208 |
fig.update_layout(
|
209 |
height=800, width=1200,
|
210 |
title_text="Audio Analysis",
|
211 |
+
showlegend=False
|
212 |
)
|
213 |
|
214 |
fig.update_xaxes(title_text="Time (s)", row=2, col=1)
|