mirror of
https://github.com/beetbox/beets.git
synced 2025-12-23 17:13:30 +01:00
autobpm: Add a new beat_track_kwargs configuration option to autobpm
This commit is contained in:
parent
49cae5ca23
commit
5b5c564a69
3 changed files with 18 additions and 2 deletions
|
|
@ -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}",
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue