summaryrefslogtreecommitdiff
path: root/animism-align
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2021-03-10 14:00:54 +0100
committerJules Laplace <julescarbon@gmail.com>2021-03-10 14:00:54 +0100
commite86e0a2f710d28c26a7457ab3fd35c88d2f937b1 (patch)
tree55a4225dca892bbf509f37584e90a96fb4db49f6 /animism-align
parent0e849395aab06b3c05b609740ebc94cf3a5cd258 (diff)
fix nav. thinking about peaks
Diffstat (limited to 'animism-align')
-rw-r--r--animism-align/cli/commands/peaks/parse.py32
-rw-r--r--animism-align/frontend/app/views/editor/editor.gate.js6
2 files changed, 9 insertions, 29 deletions
diff --git a/animism-align/cli/commands/peaks/parse.py b/animism-align/cli/commands/peaks/parse.py
index da183f4..4fd6378 100644
--- a/animism-align/cli/commands/peaks/parse.py
+++ b/animism-align/cli/commands/peaks/parse.py
@@ -9,37 +9,13 @@ import click
help='Input file')
@click.pass_context
def cli(ctx, fp_in):
- """Extract peaks from an MP3 file.
+ """Extract peaks from an audio file.
"""
- 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())
+ from app.peaks import extract_peaks
+ peaks = extract_peaks(fp_in)
with open(os.path.join(app_cfg.DIR_DATA_STORE, 'peaks/peaks.json'), 'w') as fp_out:
- json.dump(peaks.tolist(), fp_out, separators=(',', ':'))
+ json.dump(peaks, fp_out, separators=(',', ':'))
print("Wrote peaks.json")
diff --git a/animism-align/frontend/app/views/editor/editor.gate.js b/animism-align/frontend/app/views/editor/editor.gate.js
index 87ca367..1524b53 100644
--- a/animism-align/frontend/app/views/editor/editor.gate.js
+++ b/animism-align/frontend/app/views/editor/editor.gate.js
@@ -15,7 +15,11 @@ class EditorGate extends Component {
}
componentDidMount() {
- this.load()
+ if (parseInt(this.props.episode_id) === parseInt(this.props.current_episode_id)) {
+ this.setState({ ready: true })
+ } else {
+ this.load()
+ }
}
componentDidUpdate(prevProps) {