autobpm: Add a new beat_track_kwargs configuration option to autobpm

This commit is contained in:
Šarūnas Nejus 2024-08-15 17:19:39 +01:00
parent 49cae5ca23
commit 5b5c564a69
No known key found for this signature in database
GPG key ID: DD28F6704DBE3435
3 changed files with 18 additions and 2 deletions

View file

@ -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}",

View file

@ -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:

View file

@ -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