diff --git a/beetsplug/autobpm.py b/beetsplug/autobpm.py index 66f61cfa9..7a7074482 100644 --- a/beetsplug/autobpm.py +++ b/beetsplug/autobpm.py @@ -15,7 +15,7 @@ from typing import Iterable -from librosa import beat, load +import librosa from soundfile import LibsndfileError from beets import ui, util @@ -63,7 +63,9 @@ class AutoBPMPlugin(BeetsPlugin): continue try: - y, sr = load(util.syspath(item.path), res_type="kaiser_fast") + y, sr = librosa.load( + util.syspath(item.path), res_type="kaiser_fast" + ) except LibsndfileError as exc: self._log.error( "LibsndfileError: failed to load {0} {1}", @@ -80,7 +82,7 @@ class AutoBPMPlugin(BeetsPlugin): continue kwargs = self.config["beat_track_kwargs"].flatten() - tempo, _ = beat.beat_track(y=y, sr=sr, **kwargs) + tempo, _ = librosa.beat.beat_track(y=y, sr=sr, **kwargs) bpm = round(tempo[0] if isinstance(tempo, Iterable) else tempo) item["bpm"] = bpm self._log.info( diff --git a/docs/changelog.rst b/docs/changelog.rst index 838e9044d..c1ee6c0d2 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -60,6 +60,10 @@ Other changes: * :doc:`plugins/autobpm`: Add plugin dependencies to `pyproject.toml` under the `autobpm` extra and update the plugin installation instructions in the docs. + Since importing the bpm calculation functionality from ``librosa`` takes + around 4 seconds, update the plugin to only do so when it actually needs to + calculate the bpm. Previously this import was being done immediately, so + every ``beet`` invocation was being delayed by a couple of seconds. :bug:`5185` 2.0.0 (May 30, 2024)