Skip to content

Commit 54aedee

Browse files
committed
modify
1 parent 8fe9103 commit 54aedee

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

batbot/spectrogram/__init__.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ def generate_waveplot(
245245

246246
def get_waveform_data_ms(waveform, sample_rate, hop_length=16):
247247
"""
248-
Returns time in milliseconds and the raw min/max amplitude values.
248+
Returns a list of (time_ms, min_val, max_val) for each hop, suitable for
249+
drawing a waveform plot in external tools (e.g. JSON-serializable).
249250
"""
250251
# 1. Calculate min/max envelopes
251252
temp = np.pad(waveform, hop_length // 2, mode='edge')
@@ -259,12 +260,10 @@ def get_waveform_data_ms(waveform, sample_rate, hop_length=16):
259260
# (samples / sample_rate) = seconds
260261
# (seconds * 1000) = milliseconds
261262
times_ms = (np.arange(len(bin_mins)) * hop_length) / sample_rate * 1000
262-
# convert into an array
263263
times_ms = np.around(times_ms).astype(float)
264264
bin_mins = np.around(bin_mins).astype(float)
265265
bin_maxs = np.around(bin_maxs).astype(float)
266-
output_array = np.stack((times_ms, bin_mins, bin_maxs), axis=-1)
267-
return output_array
266+
return [(float(t), float(mn), float(mx)) for t, mn, mx in zip(times_ms, bin_mins, bin_maxs)]
268267

269268

270269
# @lp
@@ -1761,12 +1760,10 @@ def compute_wrapper(
17611760
segment_waveplot = waveplot[:, start + trim_begin : start + trim_end]
17621761
segments['waveplot'].append(segment_waveplot)
17631762
if segment_waves:
1764-
segment_waveplot = waveform_ms[:, start + trim_begin : start + trim_end]
1765-
# convert into some JSON serializable
1763+
segment_waveplot = waveform_ms[start + trim_begin : start + trim_end]
1764+
# convert into JSON-serializable list of [time_ms, min_val, max_val]
17661765
segment_waveplot = [
1767-
[
1768-
round(float(val), 3) for val in row
1769-
]
1766+
[round(val, 3) for val in row]
17701767
for row in segment_waveplot
17711768
]
17721769
metadata_waveplot = {

0 commit comments

Comments
 (0)