4545)
4646from transformers .testing_utils import (
4747 is_librosa_available ,
48+ require_audio ,
4849 require_librosa ,
49- require_soundfile ,
50- require_soxr ,
5150 require_torchaudio ,
5251 require_torchcodec ,
5352 slow ,
@@ -1911,8 +1910,7 @@ def test_format_from_source(self):
19111910
19121911 # ---- source forms: local path, URL, base64, data: URI -------------------------------------
19131912
1914- @require_soundfile
1915- @require_soxr
1913+ @require_audio
19161914 def test_load_audio_from_every_source_form (self ):
19171915 # a single sync gives us the file as a local path, a public URL, raw base64 and a data: URI
19181916 with patch ("transformers.audio_utils.is_torchcodec_usable" , return_value = False ):
@@ -1921,8 +1919,7 @@ def test_load_audio_from_every_source_form(self):
19211919 self .assertIsInstance (audio , np .ndarray , form )
19221920 self .assertGreater (audio .size , 0 , form )
19231921
1924- @require_soundfile
1925- @require_soxr
1922+ @require_audio
19261923 def test_invalid_base64_raises_value_error (self ):
19271924 # a non-URL, non-path string is treated as base64 and must fail cleanly
19281925 with patch ("transformers.audio_utils.is_torchcodec_usable" , return_value = False ):
@@ -1932,8 +1929,7 @@ def test_invalid_base64_raises_value_error(self):
19321929
19331930 # ---- soundfile fallback (torchcodec unavailable) ------------------------------------------
19341931
1935- @require_soundfile
1936- @require_soxr
1932+ @require_audio
19371933 def test_soundfile_decodes_soundfile_formats (self ):
19381934 with patch ("transformers.audio_utils.is_torchcodec_usable" , return_value = False ):
19391935 for name , filetype in self ._BUCKET_FILETYPES .items ():
@@ -1944,8 +1940,7 @@ def test_soundfile_decodes_soundfile_formats(self):
19441940 self .assertGreater (audio .size , 0 , name )
19451941
19461942 @require_librosa
1947- @require_soundfile
1948- @require_soxr
1943+ @require_audio
19491944 def test_soundfile_matches_librosa_on_soundfile_formats (self ):
19501945 # the soundfile backend replaces `librosa.load`, so it must return exactly the same samples
19511946 for name , filetype in self ._BUCKET_FILETYPES .items ():
@@ -1955,8 +1950,7 @@ def test_soundfile_matches_librosa_on_soundfile_formats(self):
19551950 expected = librosa .load (self ._path (name ), sr = 16000 )[0 ]
19561951 np .testing .assert_array_equal (audio , expected , err_msg = name )
19571952
1958- @require_soundfile
1959- @require_soxr
1953+ @require_audio
19601954 def test_soundfile_rejects_torchcodec_only_formats_with_helpful_error (self ):
19611955 with patch ("transformers.audio_utils.is_torchcodec_usable" , return_value = False ):
19621956 for name , filetype in self ._BUCKET_FILETYPES .items ():
@@ -1980,8 +1974,7 @@ def test_video_url_rejected_up_front_without_download(self):
19801974 self .assertIn ("torchcodec" , message )
19811975 fetch .assert_not_called ()
19821976
1983- @require_soundfile
1984- @require_soxr
1977+ @require_audio
19851978 def test_deprecated_load_audio_librosa_warns_and_pins_soundfile (self ):
19861979 # BC: even with torchcodec available, the alias must still decode with soundfile (what librosa used)
19871980 with patch ("transformers.audio_utils.is_torchcodec_usable" , return_value = True ):
@@ -2026,8 +2019,7 @@ def test_unknown_backend_raises(self):
20262019 load_audio (self ._path ("audio.wav" ), sampling_rate = 16000 , backend = "not_a_backend" )
20272020
20282021
2029- @require_soundfile
2030- @require_soxr
2022+ @require_audio
20312023class LoadAudioSoundfileTester (unittest .TestCase ):
20322024 """The `"soundfile"` backend replaces `librosa.load`: same samples, without librosa."""
20332025
0 commit comments