88from datasets .features import Audio , Features , Sequence , Value
99
1010from ..utils import (
11+ require_librosa ,
1112 require_sndfile ,
1213)
1314
@@ -57,6 +58,7 @@ def test_audio_feature_type_to_arrow():
5758 assert features .arrow_schema == pa .schema ({"sequence_of_audios" : pa .list_ (Audio ().pa_type )})
5859
5960
61+ @require_librosa
6062@pytest .mark .parametrize (
6163 "build_example" ,
6264 [
@@ -81,6 +83,7 @@ def test_audio_feature_encode_example(shared_datadir, build_example):
8183 assert decoded_example .keys () == {"path" , "array" , "sampling_rate" }
8284
8385
86+ @require_librosa
8487@pytest .mark .parametrize (
8588 "build_example" ,
8689 [
@@ -101,6 +104,7 @@ def test_audio_feature_encode_example_pcm(shared_datadir, build_example):
101104 assert decoded_example .keys () == {"path" , "array" , "sampling_rate" }
102105
103106
107+ @require_librosa
104108@require_sndfile
105109def test_audio_decode_example (shared_datadir ):
106110 audio_path = str (shared_datadir / "test_audio_44100.wav" )
@@ -115,6 +119,7 @@ def test_audio_decode_example(shared_datadir):
115119 Audio (decode = False ).decode_example (audio_path )
116120
117121
122+ @require_librosa
118123@require_sndfile
119124def test_audio_resampling (shared_datadir ):
120125 audio_path = str (shared_datadir / "test_audio_44100.wav" )
@@ -126,6 +131,7 @@ def test_audio_resampling(shared_datadir):
126131 assert decoded_example ["sampling_rate" ] == 16000
127132
128133
134+ @require_librosa
129135@require_sndfile
130136def test_audio_decode_example_mp3 (shared_datadir ):
131137 audio_path = str (shared_datadir / "test_audio_44100.mp3" )
@@ -137,6 +143,7 @@ def test_audio_decode_example_mp3(shared_datadir):
137143 assert decoded_example ["sampling_rate" ] == 44100
138144
139145
146+ @require_librosa
140147@require_sndfile
141148def test_audio_decode_example_opus (shared_datadir ):
142149 audio_path = str (shared_datadir / "test_audio_48000.opus" )
@@ -148,6 +155,7 @@ def test_audio_decode_example_opus(shared_datadir):
148155 assert decoded_example ["sampling_rate" ] == 48000
149156
150157
158+ @require_librosa
151159@pytest .mark .parametrize ("sampling_rate" , [16_000 , 48_000 ])
152160def test_audio_decode_example_pcm (shared_datadir , sampling_rate ):
153161 audio_path = str (shared_datadir / "test_audio_16000.pcm" )
@@ -160,6 +168,7 @@ def test_audio_decode_example_pcm(shared_datadir, sampling_rate):
160168 assert decoded_example ["sampling_rate" ] == sampling_rate
161169
162170
171+ @require_librosa
163172@require_sndfile
164173def test_audio_resampling_mp3_different_sampling_rates (shared_datadir ):
165174 audio_path = str (shared_datadir / "test_audio_44100.mp3" )
@@ -179,6 +188,7 @@ def test_audio_resampling_mp3_different_sampling_rates(shared_datadir):
179188 assert decoded_example ["sampling_rate" ] == 48000
180189
181190
191+ @require_librosa
182192@require_sndfile
183193def test_dataset_with_audio_feature (shared_datadir ):
184194 audio_path = str (shared_datadir / "test_audio_44100.wav" )
@@ -206,6 +216,7 @@ def test_dataset_with_audio_feature(shared_datadir):
206216 assert column [0 ]["sampling_rate" ] == 44100
207217
208218
219+ @require_librosa
209220@require_sndfile
210221def test_dataset_with_audio_feature_tar_wav (tar_wav_path ):
211222 audio_filename = "test_audio_44100.wav"
@@ -236,6 +247,7 @@ def test_dataset_with_audio_feature_tar_wav(tar_wav_path):
236247 assert column [0 ]["sampling_rate" ] == 44100
237248
238249
250+ @require_librosa
239251@require_sndfile
240252def test_dataset_with_audio_feature_tar_mp3 (tar_mp3_path ):
241253 audio_filename = "test_audio_44100.mp3"
@@ -300,6 +312,7 @@ def test_dataset_with_audio_feature_with_none():
300312 assert item ["nested" ]["audio" ] is None
301313
302314
315+ @require_librosa
303316@require_sndfile
304317def test_resampling_at_loading_dataset_with_audio_feature (shared_datadir ):
305318 audio_path = str (shared_datadir / "test_audio_44100.wav" )
@@ -327,6 +340,7 @@ def test_resampling_at_loading_dataset_with_audio_feature(shared_datadir):
327340 assert column [0 ]["sampling_rate" ] == 16000
328341
329342
343+ @require_librosa
330344@require_sndfile
331345def test_resampling_at_loading_dataset_with_audio_feature_mp3 (shared_datadir ):
332346 audio_path = str (shared_datadir / "test_audio_44100.mp3" )
@@ -354,6 +368,7 @@ def test_resampling_at_loading_dataset_with_audio_feature_mp3(shared_datadir):
354368 assert column [0 ]["sampling_rate" ] == 16000
355369
356370
371+ @require_librosa
357372@require_sndfile
358373def test_resampling_after_loading_dataset_with_audio_feature (shared_datadir ):
359374 audio_path = str (shared_datadir / "test_audio_44100.wav" )
@@ -384,6 +399,7 @@ def test_resampling_after_loading_dataset_with_audio_feature(shared_datadir):
384399 assert column [0 ]["sampling_rate" ] == 16000
385400
386401
402+ @require_librosa
387403@require_sndfile
388404def test_resampling_after_loading_dataset_with_audio_feature_mp3 (shared_datadir ):
389405 audio_path = str (shared_datadir / "test_audio_44100.mp3" )
@@ -414,6 +430,7 @@ def test_resampling_after_loading_dataset_with_audio_feature_mp3(shared_datadir)
414430 assert column [0 ]["sampling_rate" ] == 16000
415431
416432
433+ @require_librosa
417434@pytest .mark .parametrize (
418435 "build_data" ,
419436 [
@@ -438,6 +455,7 @@ def test_dataset_cast_to_audio_features(shared_datadir, build_data):
438455 assert item ["audio" ].keys () == {"path" , "array" , "sampling_rate" }
439456
440457
458+ @require_librosa
441459def test_dataset_concatenate_audio_features (shared_datadir ):
442460 # we use a different data structure between 1 and 2 to make sure they are compatible with each other
443461 audio_path = str (shared_datadir / "test_audio_44100.wav" )
@@ -451,6 +469,7 @@ def test_dataset_concatenate_audio_features(shared_datadir):
451469 assert concatenated_dataset [1 ]["audio" ]["array" ].shape == dset2 [0 ]["audio" ]["array" ].shape
452470
453471
472+ @require_librosa
454473def test_dataset_concatenate_nested_audio_features (shared_datadir ):
455474 # we use a different data structure between 1 and 2 to make sure they are compatible with each other
456475 audio_path = str (shared_datadir / "test_audio_44100.wav" )
@@ -493,6 +512,7 @@ def process_text(example):
493512 assert item == {"audio" : expected_audio , "text" : "Hello World!" }
494513
495514
515+ @require_librosa
496516@require_sndfile
497517def test_dataset_with_audio_feature_map_is_decoded (shared_datadir ):
498518 audio_path = str (shared_datadir / "test_audio_44100.wav" )
@@ -522,6 +542,7 @@ def process_audio_sampling_rate_by_batch(batch):
522542 assert item ["double_sampling_rate" ] == 88200
523543
524544
545+ @require_librosa
525546@require_sndfile
526547def test_formatted_dataset_with_audio_feature (shared_datadir ):
527548 audio_path = str (shared_datadir / "test_audio_44100.wav" )
@@ -585,6 +606,7 @@ def jsonl_audio_dataset_path(shared_datadir, tmp_path_factory):
585606 return path
586607
587608
609+ @require_librosa
588610@require_sndfile
589611@pytest .mark .parametrize ("streaming" , [False , True ])
590612def test_load_dataset_with_audio_feature (streaming , jsonl_audio_dataset_path , shared_datadir ):
0 commit comments