From 5b5c564a698fdec7085be6a0bb7f0972e1fccc8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Thu, 15 Aug 2024 17:19:39 +0100 Subject: [PATCH] autobpm: Add a new beat_track_kwargs configuration option to autobpm --- beetsplug/autobpm.py | 8 ++++++-- docs/changelog.rst | 3 +++ docs/plugins/autobpm.rst | 9 +++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/beetsplug/autobpm.py b/beetsplug/autobpm.py index fa08a12cb..66f61cfa9 100644 --- a/beetsplug/autobpm.py +++ b/beetsplug/autobpm.py @@ -13,6 +13,8 @@ """Uses Librosa to calculate the `bpm` field.""" +from typing import Iterable + from librosa import beat, load from soundfile import LibsndfileError @@ -27,6 +29,7 @@ class AutoBPMPlugin(BeetsPlugin): { "auto": True, "overwrite": False, + "beat_track_kwargs": {}, } ) @@ -76,8 +79,9 @@ class AutoBPMPlugin(BeetsPlugin): ) continue - (tempo, *_), _ = beat.beat_track(y=y, sr=sr) - bpm = round(tempo) + kwargs = self.config["beat_track_kwargs"].flatten() + tempo, _ = beat.beat_track(y=y, sr=sr, **kwargs) + bpm = round(tempo[0] if isinstance(tempo, Iterable) else tempo) item["bpm"] = bpm self._log.info( "added computed bpm {0} for {1}", diff --git a/docs/changelog.rst b/docs/changelog.rst index bf880dbda..838e9044d 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -12,6 +12,9 @@ New features: `beet list -a title:something` or `beet list artpath:cover`. Consequently album queries involving `path` field have been sped up, like `beet list -a path:/path/`. +* :doc:`plugins/autobpm`: Add new configuration option ``beat_track_kwargs`` + which enables adjusting keyword arguments supplied to librosa's + ``beat_track`` function call. Bug fixes: diff --git a/docs/plugins/autobpm.rst b/docs/plugins/autobpm.rst index 97efaba14..53908c517 100644 --- a/docs/plugins/autobpm.rst +++ b/docs/plugins/autobpm.rst @@ -28,5 +28,14 @@ configuration file. The available options are: - **overwrite**: Calculate a BPM even for files that already have a `bpm` value. Default: ``no``. +- **beat_track_kwargs**: Any extra keyword arguments that you would like to + provide to librosa's `beat_track`_ function call, for example: + +.. code-block:: yaml + + autobpm: + beat_track_kwargs: + start_bpm: 160 .. _Librosa: https://github.com/librosa/librosa/ +.. _beat_track: https://librosa.org/doc/latest/generated/librosa.beat.beat_track.html