diff options
Diffstat (limited to 'animism-align/cli/commands/peaks')
| -rw-r--r-- | animism-align/cli/commands/peaks/parse.py | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/animism-align/cli/commands/peaks/parse.py b/animism-align/cli/commands/peaks/parse.py index 4fd6378..1740c44 100644 --- a/animism-align/cli/commands/peaks/parse.py +++ b/animism-align/cli/commands/peaks/parse.py @@ -11,11 +11,38 @@ import click def cli(ctx, fp_in): """Extract peaks from an audio file. """ + print("This script is deprecated. Extract peaks using the web UI!") + return - from app.peaks import extract_peaks - peaks = extract_peaks(fp_in) + import os + import math + import librosa + import numpy + import json + + from app.settings import app_cfg + + if not os.path.exists(fp_in): + print(f"fp_in does not exist: {fp_in}") + return + + print(f"Loading {fp_in}") + y, sr = librosa.load(fp_in, sr=None) + + sr_10 = sr / 10 + steps = math.ceil(y.shape[0] / sr_10) + + peaks = numpy.ndarray(steps) + + for i in range(steps): + offset_start = math.floor(i * sr_10) + offset_end = math.ceil((i + 1) * sr_10) + slice = y[offset_start:offset_end] + peak = max(abs(slice.min()), slice.max()) + peaks[i] = float('%.3f' % peak) + # peaks[i * 2 + 1] = float('%.3f' % slice.max()) with open(os.path.join(app_cfg.DIR_DATA_STORE, 'peaks/peaks.json'), 'w') as fp_out: - json.dump(peaks, fp_out, separators=(',', ':')) + json.dump(peaks.tolist(), fp_out, separators=(',', ':')) print("Wrote peaks.json") |
