Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 22050 Hz as flavor, deprecate 22500 Hz #470

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions audb/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def exists(
format: file format, one of ``'flac'``, ``'wav'``
mixdown: apply mono mix-down
sampling_rate: sampling rate in Hz, one of
``8000``, ``16000``, ``22500``, ``24000``, ``44100``, ``48000``
``8000``, ``16000``, ``22050``, ``24000``, ``44100``, ``48000``
cache_root: cache folder where databases are stored.
If not set :meth:`audb.default_cache_root` is used

Expand Down Expand Up @@ -416,7 +416,7 @@ def flavor_path(
format: file format, one of ``'flac'``, ``'wav'``
mixdown: apply mono mix-down
sampling_rate: sampling rate in Hz, one of
``8000``, ``16000``, ``22500``, ``24000``, ``44100``, ``48000``
``8000``, ``16000``, ``22050``, ``24000``, ``44100``, ``48000``

Returns:
flavor path relative to cache folder
Expand Down
2 changes: 1 addition & 1 deletion audb/core/define.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Format:

FORMATS = [Format.WAV, Format.FLAC]
BIT_DEPTHS = [16, 24, 32]
SAMPLING_RATES = [8000, 16000, 22500, 24000, 44100, 48000]
SAMPLING_RATES = [8000, 16000, 22050, 24000, 44100, 48000]
hagenw marked this conversation as resolved.
Show resolved Hide resolved

# Progress bar
MAXIMUM_REFRESH_TIME = 1 # force progress bar to update every second
12 changes: 10 additions & 2 deletions audb/core/flavor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from collections.abc import Sequence
import os
import shutil
import warnings

import numpy as np

Expand Down Expand Up @@ -41,7 +42,7 @@ class Flavor(audobject.Object):
format: file format, one of ``'flac'``, ``'wav'``
mixdown: apply mono mix-down on selection
sampling_rate: sampling rate in Hz, one of
``8000``, ``16000``, ``22500``, ``24000``, ``44100``, ``48000``
``8000``, ``16000``, ``22050``, ``24000``, ``44100``, ``48000``

Raises:
ValueError: if a non-supported ``bit_depth``,
Expand Down Expand Up @@ -81,7 +82,14 @@ def __init__(

if sampling_rate is not None:
sampling_rate = int(sampling_rate)
if sampling_rate not in define.SAMPLING_RATES:
if sampling_rate == 22500:
message = (
"A sampling rate of 22500 Hz is deprecated "
"and will be removed with version 1.13.0 of audb. "
"Use 22050 Hz instead."
)
warnings.warn(message, category=UserWarning, stacklevel=2)
elif sampling_rate not in define.SAMPLING_RATES:
raise ValueError(
f"Sampling_rate has to be one of "
f"{define.SAMPLING_RATES}, not {sampling_rate}."
Expand Down
4 changes: 2 additions & 2 deletions audb/core/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ def load(
format: file format, one of ``'flac'``, ``'wav'``
mixdown: apply mono mix-down
sampling_rate: sampling rate in Hz, one of
``8000``, ``16000``, ``22500``, ``24000``, ``44100``, ``48000``
``8000``, ``16000``, ``22050``, ``24000``, ``44100``, ``48000``
attachments: load only attachment files
for the attachments
matching the regular expression
Expand Down Expand Up @@ -1521,7 +1521,7 @@ def load_media(
format: file format, one of ``'flac'``, ``'wav'``
mixdown: apply mono mix-down
sampling_rate: sampling rate in Hz, one of
``8000``, ``16000``, ``22500``, ``24000``, ``44100``, ``48000``
``8000``, ``16000``, ``22050``, ``24000``, ``44100``, ``48000``
cache_root: cache folder where databases are stored.
If not set :meth:`audb.default_cache_root` is used
num_workers: number of parallel jobs or 1 for sequential
Expand Down
2 changes: 1 addition & 1 deletion audb/core/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ def stream(
format: file format, one of ``'flac'``, ``'wav'``
mixdown: apply mono mix-down
sampling_rate: sampling rate in Hz, one of
``8000``, ``16000``, ``22500``, ``24000``, ``44100``, ``48000``
``8000``, ``16000``, ``22050``, ``24000``, ``44100``, ``48000``
full_path: replace relative with absolute file paths
cache_root: cache folder where databases are stored.
If not set :meth:`audb.default_cache_root` is used
Expand Down
2 changes: 1 addition & 1 deletion docs/load.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ The following properties can be changed.
sampling_rate:
- 8000
- 16000
- 22500
- 22050
- 24000
- 44100
- 48000
Expand Down
7 changes: 7 additions & 0 deletions tests/test_flavor.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ def test_init(bit_depth, channels, format, mixdown, sampling_rate):
assert flavor.id == flavor_2.id


def test_deprecated_sampling_rate():
"""Test a sampling rate of 22500 Hz raises user warning."""
message = "removed with version 1.13.0"
with pytest.warns(UserWarning, match=message):
audb.Flavor(sampling_rate=22500)


@pytest.mark.parametrize(
"format",
[
Expand Down
Loading