Skip to content

Commit 2e015d4

Browse files
ronwcopybara-github
authored andcommitted
Expose sample_rate (in Hertz) metadata to audio datasets.
This is pretty critical metadata to know when designing (e.g. spectrogram) feature extraction parameters or simply listening to audio samples. Exposing it in the DatasetInfo allows users to avoid having to look it up and specify it manually. Had to fix the BeamMetadataDict constructor to pass args through to the base dict constructor in order to make this work. PiperOrigin-RevId: 296499129
1 parent 9851dff commit 2e015d4

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

tensorflow_datasets/audio/librispeech.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ def _info(self):
139139
supervised_keys=("speech", "text"),
140140
homepage=_URL,
141141
citation=_CITATION,
142+
metadata=tfds.core.MetadataDict(sample_rate=16000,),
142143
)
143144

144145
def _vocab_text_gen(self, dirs):

tensorflow_datasets/audio/nsynth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def _info(self):
178178
features=tfds.features.FeaturesDict(features),
179179
homepage="https://g.co/magenta/nsynth-dataset",
180180
citation=_CITATION,
181-
metadata=tfds.core.BeamMetadataDict(),
181+
metadata=tfds.core.BeamMetadataDict(sample_rate=_AUDIO_RATE,),
182182
)
183183

184184
def _split_generators(self, dl_manager):

tensorflow_datasets/core/dataset_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,8 @@ def load_metadata(self, data_dir):
673673
class BeamMetadataDict(MetadataDict):
674674
"""A `tfds.core.Metadata` object supporting Beam-generated datasets."""
675675

676-
def __init__(self):
677-
super(BeamMetadataDict, self).__init__()
676+
def __init__(self, *args, **kwargs):
677+
super(BeamMetadataDict, self).__init__(*args, **kwargs)
678678
self._tempdir = tempfile.mkdtemp("tfds_beam_metadata")
679679

680680
def _temp_filepath(self, key):

0 commit comments

Comments
 (0)