





import itertools
import random
import unittest

import numpy as np

from transformers import BatchFeature, SpeechTaFeatureExtractor
from transformers.testing_utils import require_torch
from transformers.utils.import_utils import is_torch_available

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


if is_torch_available():
     import torch


__A     =    random.Random()





def 					lowerCAmelCase_			(	__a     ,   __a=1.0     ,   __a=None     ,   __a=None		)					->		Tuple:







  """simple docstring"""





  if rng is None:
    lowerCamelCase__:				Dict        =global_rng

  lowerCamelCase__:				Optional[Any]        =[]
  for batch_idx in range(shape[0]		):
    values.append([]		)
    for _ in range(shape[1]		):
      values[-1].append(rng.random() * scale		)

  return values



@require_torch
class        _SCREAMING_SNAKE_CASE						(     unittest.TestCase   ):







 '''simple docstring'''

 def __init__(self    :       int	,			UpperCAmelCase_    :       Dict	,			UpperCAmelCase_    :       str=7	,			UpperCAmelCase_    :       Union[str, Any]=400	,			UpperCAmelCase_    :       List[Any]=2_000	,			UpperCAmelCase_    :       Optional[int]=1	,			UpperCAmelCase_    :       int=0.0	,			UpperCAmelCase_    :       List[str]=16_000	,			UpperCAmelCase_    :       Optional[int]=True	,			UpperCAmelCase_    :       str=80	,			UpperCAmelCase_    :       Union[str, Any]=16	,			UpperCAmelCase_    :       Tuple=64	,			UpperCAmelCase_    :       Tuple="hann_window"	,			UpperCAmelCase_    :       int=80	,			UpperCAmelCase_    :       List[Any]=7_600	,			UpperCAmelCase_    :       List[Any]=1E-1_0	,			UpperCAmelCase_    :       List[str]=True	,			)	->Dict:



   '''simple docstring'''



   lowerCamelCase__:				List[str]        =parent
   lowerCamelCase__:				List[str]        =batch_size
   lowerCamelCase__:				Optional[Any]        =min_seq_length
   lowerCamelCase__:				Tuple        =max_seq_length
   lowerCamelCase__:				List[str]        =(self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
   lowerCamelCase__:				Optional[int]        =feature_size
   lowerCamelCase__:				Optional[int]        =padding_value
   lowerCamelCase__:				Tuple        =sampling_rate
   lowerCamelCase__:				Dict        =do_normalize
   lowerCamelCase__:				str        =num_mel_bins
   lowerCamelCase__:				str        =hop_length
   lowerCamelCase__:				Union[str, Any]        =win_length
   lowerCamelCase__:				int        =win_function
   lowerCamelCase__:				Dict        =fmin
   lowerCamelCase__:				str        =fmax
   lowerCamelCase__:				Dict        =mel_floor
   lowerCamelCase__:				List[str]        =return_attention_mask

 def 							SCREAMING_SNAKE_CASE_ (self    :       Any)	->Any:



   '''simple docstring'''



   return {
       "feature_size": self.feature_size,
       "padding_value": self.padding_value,
       "sampling_rate": self.sampling_rate,
       "do_normalize": self.do_normalize,
       "num_mel_bins": self.num_mel_bins,
       "hop_length": self.hop_length,
       "win_length": self.win_length,
       "win_function": self.win_function,
       "fmin": self.fmin,
       "fmax": self.fmax,
       "mel_floor": self.mel_floor,
       "return_attention_mask": self.return_attention_mask,
   }

 def 							SCREAMING_SNAKE_CASE_ (self    :       Tuple	,			UpperCAmelCase_    :       Dict=False	,			UpperCAmelCase_    :       List[str]=False)	->Tuple:



   '''simple docstring'''



   def _flatten(UpperCAmelCase_    :       Any):
     return list(itertools.chain(*UpperCAmelCase_))

   if equal_length:
     lowerCamelCase__:				Tuple        =floats_list((self.batch_size, self.max_seq_length))
   else:
     # make sure that inputs increase in size
     lowerCamelCase__:				Tuple        =[
         _flatten(floats_list((x, self.feature_size)))
         for x in range(self.min_seq_length	,			self.max_seq_length	,			self.seq_length_diff)
     ]

   if numpify:
     lowerCamelCase__:				List[Any]        =[np.asarray(UpperCAmelCase_) for x in speech_inputs]

   return speech_inputs







 def 							SCREAMING_SNAKE_CASE_ (self    :       Union[str, Any]	,			UpperCAmelCase_    :       Dict=False	,			UpperCAmelCase_    :       int=False)	->int:



   '''simple docstring'''



   if equal_length:
     lowerCamelCase__:				int        =[floats_list((self.max_seq_length, self.num_mel_bins)) for _ in range(self.batch_size)]
   else:
     # make sure that inputs increase in size
     lowerCamelCase__:				Union[str, Any]        =[
         floats_list((x, self.num_mel_bins))
         for x in range(self.min_seq_length	,			self.max_seq_length	,			self.seq_length_diff)
     ]

   if numpify:
     lowerCamelCase__:				Optional[Any]        =[np.asarray(UpperCAmelCase_) for x in speech_inputs]

   return speech_inputs



@require_torch
class        _SCREAMING_SNAKE_CASE						(     __SCREAMING_SNAKE_CASE   ,							unittest.TestCase   ):







 '''simple docstring'''
 lowercase_		=      SpeechTaFeatureExtractor

 def 							SCREAMING_SNAKE_CASE_ (self    :       Union[str, Any])	->Dict:



   '''simple docstring'''



   lowerCamelCase__:				Union[str, Any]        =SpeechTaFeatureExtractionTester(self)

 def 							SCREAMING_SNAKE_CASE_ (self    :       Optional[Any]	,			UpperCAmelCase_    :       Tuple)	->Dict:



   '''simple docstring'''



   self.assertTrue(np.all(np.mean(UpperCAmelCase_	,			axis=0) < 1E-3))
   self.assertTrue(np.all(np.abs(np.var(UpperCAmelCase_	,			axis=0) - 1) < 1E-3))

 def 							SCREAMING_SNAKE_CASE_ (self    :       Dict)	->Union[str, Any]:



   '''simple docstring'''



   lowerCamelCase__:				List[Any]        =self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
   # create three inputs of length 800, 1000, and 1200
   lowerCamelCase__:				Tuple        =[floats_list((1, x))[0] for x in range(800	,			1_400	,			200)]
   lowerCamelCase__:				List[str]        =[np.asarray(UpperCAmelCase_) for speech_input in speech_inputs]

   # Test not batched input
   lowerCamelCase__:				Union[str, Any]        =feat_extract(speech_inputs[0]	,			return_tensors="np").input_values
   lowerCamelCase__:				List[str]        =feat_extract(np_speech_inputs[0]	,			return_tensors="np").input_values
   self.assertTrue(np.allclose(UpperCAmelCase_	,			UpperCAmelCase_	,			atol=1E-3))

   # Test batched
   lowerCamelCase__:				Dict        =feat_extract(UpperCAmelCase_	,			return_tensors="np").input_values
   lowerCamelCase__:				Any        =feat_extract(UpperCAmelCase_	,			return_tensors="np").input_values
   for enc_seq_a, enc_seq_a in zip(UpperCAmelCase_	,			UpperCAmelCase_):
     self.assertTrue(np.allclose(UpperCAmelCase_	,			UpperCAmelCase_	,			atol=1E-3))

 def 							SCREAMING_SNAKE_CASE_ (self    :       Dict)	->List[Any]:



   '''simple docstring'''



   lowerCamelCase__:				Dict        =self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
   lowerCamelCase__:				Dict        =[floats_list((1, x))[0] for x in range(800	,			1_400	,			200)]

   lowerCamelCase__:				Optional[int]        =["longest", "max_length", "do_not_pad"]
   lowerCamelCase__:				Union[str, Any]        =[None, 1_600, None]
   for max_length, padding in zip(UpperCAmelCase_	,			UpperCAmelCase_):
     lowerCamelCase__:				List[Any]        =feat_extract(UpperCAmelCase_	,			padding=UpperCAmelCase_	,			max_length=UpperCAmelCase_	,			return_tensors="np")
     lowerCamelCase__:				List[Any]        =processed.input_values

     self._check_zero_mean_unit_variance(input_values[0][:800])
     self.assertTrue(input_values[0][800:].sum() < 1E-6)
     self._check_zero_mean_unit_variance(input_values[1][:1_000])
     self.assertTrue(input_values[0][1_000:].sum() < 1E-6)
     self._check_zero_mean_unit_variance(input_values[2][:1_200])

 def 							SCREAMING_SNAKE_CASE_ (self    :       Tuple)	->Dict:



   '''simple docstring'''



   lowerCamelCase__:				int        =self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
   lowerCamelCase__:				Union[str, Any]        =range(800	,			1_400	,			200)
   lowerCamelCase__:				List[str]        =[floats_list((1, x))[0] for x in lengths]

   lowerCamelCase__:				Dict        =["longest", "max_length", "do_not_pad"]
   lowerCamelCase__:				List[str]        =[None, 1_600, None]

   for max_length, padding in zip(UpperCAmelCase_	,			UpperCAmelCase_):
     lowerCamelCase__:				List[Any]        =feat_extract(UpperCAmelCase_	,			max_length=UpperCAmelCase_	,			padding=UpperCAmelCase_)
     lowerCamelCase__:				Union[str, Any]        =processed.input_values

     self._check_zero_mean_unit_variance(input_values[0][:800])
     self._check_zero_mean_unit_variance(input_values[1][:1_000])
     self._check_zero_mean_unit_variance(input_values[2][:1_200])

 def 							SCREAMING_SNAKE_CASE_ (self    :       Union[str, Any])	->Optional[int]:



   '''simple docstring'''



   lowerCamelCase__:				Union[str, Any]        =self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
   lowerCamelCase__:				Optional[int]        =[floats_list((1, x))[0] for x in range(800	,			1_400	,			200)]
   lowerCamelCase__:				Union[str, Any]        =feat_extract(
       UpperCAmelCase_	,			truncation=UpperCAmelCase_	,			max_length=1_000	,			padding="max_length"	,			return_tensors="np")
   lowerCamelCase__:				Union[str, Any]        =processed.input_values

   self._check_zero_mean_unit_variance(input_values[0, :800])
   self._check_zero_mean_unit_variance(input_values[1])
   self._check_zero_mean_unit_variance(input_values[2])

 def 							SCREAMING_SNAKE_CASE_ (self    :       Tuple)	->Optional[Any]:



   '''simple docstring'''



   lowerCamelCase__:				str        =self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
   lowerCamelCase__:				Any        =[floats_list((1, x))[0] for x in range(800	,			1_400	,			200)]
   lowerCamelCase__:				str        =feat_extract(
       UpperCAmelCase_	,			truncation=UpperCAmelCase_	,			max_length=1_000	,			padding="longest"	,			return_tensors="np")
   lowerCamelCase__:				int        =processed.input_values

   self._check_zero_mean_unit_variance(input_values[0, :800])
   self._check_zero_mean_unit_variance(input_values[1, :1_000])
   self._check_zero_mean_unit_variance(input_values[2])

   # make sure that if max_length < longest -> then pad to max_length
   self.assertTrue(input_values.shape == (3, 1_000))

   lowerCamelCase__:				Tuple        =[floats_list((1, x))[0] for x in range(800	,			1_400	,			200)]
   lowerCamelCase__:				Any        =feat_extract(
       UpperCAmelCase_	,			truncation=UpperCAmelCase_	,			max_length=2_000	,			padding="longest"	,			return_tensors="np")
   lowerCamelCase__:				Optional[int]        =processed.input_values

   self._check_zero_mean_unit_variance(input_values[0, :800])
   self._check_zero_mean_unit_variance(input_values[1, :1_000])
   self._check_zero_mean_unit_variance(input_values[2])

   # make sure that if max_length > longest -> then pad to longest
   self.assertTrue(input_values.shape == (3, 1_200))

 def 							SCREAMING_SNAKE_CASE_ (self    :       Dict)	->int:



   '''simple docstring'''



   lowerCamelCase__:				int        =self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
   lowerCamelCase__:				Optional[int]        =np.random.rand(100).astype(np.floataa)
   lowerCamelCase__:				Optional[int]        =np_speech_inputs.tolist()

   for inputs in [py_speech_inputs, np_speech_inputs]:
     lowerCamelCase__:				Optional[Any]        =feature_extractor.pad([{"input_values": inputs}]	,			return_tensors="np")
     self.assertTrue(np_processed.input_values.dtype == np.floataa)
     lowerCamelCase__:				Dict        =feature_extractor.pad([{"input_values": inputs}]	,			return_tensors="pt")
     self.assertTrue(pt_processed.input_values.dtype == torch.floataa)

 def 							SCREAMING_SNAKE_CASE_ (self    :       Tuple)	->Any:



   '''simple docstring'''



   lowerCamelCase__:				Any        =self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict())
   # create three inputs of length 800, 1000, and 1200
   lowerCamelCase__:				Union[str, Any]        =[floats_list((1, x))[0] for x in range(800	,			1_400	,			200)]
   lowerCamelCase__:				Tuple        =[np.asarray(UpperCAmelCase_) for speech_input in speech_inputs]

   # Test feature size
   lowerCamelCase__:				Optional[Any]        =feature_extractor(audio_target=UpperCAmelCase_	,			padding=UpperCAmelCase_	,			return_tensors="np").input_values
   self.assertTrue(input_values.ndim == 3)
   self.assertTrue(input_values.shape[-1] == feature_extractor.num_mel_bins)

   # Test not batched input
   lowerCamelCase__:				Dict        =feature_extractor(speech_inputs[0]	,			return_tensors="np").input_values
   lowerCamelCase__:				Dict        =feature_extractor(np_speech_inputs[0]	,			return_tensors="np").input_values
   self.assertTrue(np.allclose(UpperCAmelCase_	,			UpperCAmelCase_	,			atol=1E-3))

   # Test batched
   lowerCamelCase__:				str        =feature_extractor(UpperCAmelCase_	,			return_tensors="np").input_values
   lowerCamelCase__:				List[Any]        =feature_extractor(UpperCAmelCase_	,			return_tensors="np").input_values
   for enc_seq_a, enc_seq_a in zip(UpperCAmelCase_	,			UpperCAmelCase_):
     self.assertTrue(np.allclose(UpperCAmelCase_	,			UpperCAmelCase_	,			atol=1E-3))

   # Test 2-D numpy arrays are batched.
   lowerCamelCase__:				str        =[floats_list((1, x))[0] for x in (800, 800, 800)]
   lowerCamelCase__:				Optional[int]        =np.asarray(UpperCAmelCase_)
   lowerCamelCase__:				Any        =feature_extractor(UpperCAmelCase_	,			return_tensors="np").input_values
   lowerCamelCase__:				Optional[int]        =feature_extractor(UpperCAmelCase_	,			return_tensors="np").input_values
   for enc_seq_a, enc_seq_a in zip(UpperCAmelCase_	,			UpperCAmelCase_):
     self.assertTrue(np.allclose(UpperCAmelCase_	,			UpperCAmelCase_	,			atol=1E-3))

 def 							SCREAMING_SNAKE_CASE_ (self    :       Dict)	->Optional[int]:



   '''simple docstring'''



   lowerCamelCase__:				Tuple        =self.feat_extract_tester.prepare_inputs_for_target()
   lowerCamelCase__:				int        =self.feature_extraction_class(**self.feat_extract_dict)
   lowerCamelCase__:				Optional[int]        =feat_extract.model_input_names[0]

   lowerCamelCase__:				Dict        =BatchFeature({input_name: speech_inputs})

   self.assertTrue(all(len(UpperCAmelCase_) == len(UpperCAmelCase_) for x, y in zip(UpperCAmelCase_	,			processed_features[input_name])))

   lowerCamelCase__:				Optional[int]        =self.feat_extract_tester.prepare_inputs_for_target(equal_length=UpperCAmelCase_)
   lowerCamelCase__:				Dict        =BatchFeature({input_name: speech_inputs}	,			tensor_type="np")

   lowerCamelCase__:				Tuple        =processed_features[input_name]

   if len(batch_features_input.shape) < 3:
     lowerCamelCase__:				Tuple        =batch_features_input[:, :, None]

   self.assertTrue(
       batch_features_input.shape
       == (self.feat_extract_tester.batch_size, len(speech_inputs[0]), self.feat_extract_tester.num_mel_bins))

 @require_torch
 def 							SCREAMING_SNAKE_CASE_ (self    :       Tuple)	->Tuple:



   '''simple docstring'''



   lowerCamelCase__:				str        =self.feat_extract_tester.prepare_inputs_for_target(equal_length=UpperCAmelCase_)
   lowerCamelCase__:				str        =self.feature_extraction_class(**self.feat_extract_dict)
   lowerCamelCase__:				Union[str, Any]        =feat_extract.model_input_names[0]

   lowerCamelCase__:				int        =BatchFeature({input_name: speech_inputs}	,			tensor_type="pt")

   lowerCamelCase__:				str        =processed_features[input_name]

   if len(batch_features_input.shape) < 3:
     lowerCamelCase__:				List[str]        =batch_features_input[:, :, None]

   self.assertTrue(
       batch_features_input.shape
       == (self.feat_extract_tester.batch_size, len(speech_inputs[0]), self.feat_extract_tester.num_mel_bins))

 @require_torch
 def 							SCREAMING_SNAKE_CASE_ (self    :       Optional[int])	->str:



   '''simple docstring'''



   lowerCamelCase__:				int        =self.feature_extraction_class(**self.feat_extract_dict)
   lowerCamelCase__:				Optional[Any]        =self.feat_extract_tester.prepare_inputs_for_target()
   lowerCamelCase__:				List[str]        =feat_extract.model_input_names[0]

   lowerCamelCase__:				int        =BatchFeature({input_name: speech_inputs})

   lowerCamelCase__:				Optional[Any]        =feat_extract.num_mel_bins  # hack!

   lowerCamelCase__:				int        =feat_extract.pad(UpperCAmelCase_	,			padding="longest"	,			return_tensors="np")[input_name]
   lowerCamelCase__:				Tuple        =feat_extract.pad(UpperCAmelCase_	,			padding="longest"	,			return_tensors="pt")[input_name]

   self.assertTrue(abs(input_np.astype(np.floataa).sum() - input_pt.numpy().astype(np.floataa).sum()) < 1E-2)

 def 							SCREAMING_SNAKE_CASE_ (self    :       Dict)	->Optional[Any]:



   '''simple docstring'''



   lowerCamelCase__:				List[Any]        =self.feat_extract_dict
   lowerCamelCase__:				Optional[Any]        =True
   lowerCamelCase__:				Optional[int]        =self.feature_extraction_class(**UpperCAmelCase_)
   lowerCamelCase__:				Optional[int]        =self.feat_extract_tester.prepare_inputs_for_target()
   lowerCamelCase__:				Union[str, Any]        =[len(UpperCAmelCase_) for x in speech_inputs]
   lowerCamelCase__:				Optional[Any]        =feat_extract.model_input_names[0]

   lowerCamelCase__:				Any        =BatchFeature({input_name: speech_inputs})

   lowerCamelCase__:				List[str]        =feat_extract.num_mel_bins  # hack!

   lowerCamelCase__:				Optional[Any]        =feat_extract.pad(UpperCAmelCase_	,			padding="longest"	,			return_tensors="np")
   self.assertIn("attention_mask"	,			UpperCAmelCase_)
   self.assertListEqual(list(processed.attention_mask.shape)	,			list(processed[input_name].shape[:2]))
   self.assertListEqual(processed.attention_mask.sum(-1).tolist()	,			UpperCAmelCase_)

 def 							SCREAMING_SNAKE_CASE_ (self    :       Tuple)	->Union[str, Any]:



   '''simple docstring'''



   lowerCamelCase__:				List[Any]        =self.feat_extract_dict
   lowerCamelCase__:				Optional[Any]        =True
   lowerCamelCase__:				List[str]        =self.feature_extraction_class(**UpperCAmelCase_)
   lowerCamelCase__:				Tuple        =self.feat_extract_tester.prepare_inputs_for_target()
   lowerCamelCase__:				Tuple        =[len(UpperCAmelCase_) for x in speech_inputs]
   lowerCamelCase__:				Union[str, Any]        =feat_extract.model_input_names[0]

   lowerCamelCase__:				List[Any]        =BatchFeature({input_name: speech_inputs})
   lowerCamelCase__:				int        =min(UpperCAmelCase_)

   lowerCamelCase__:				Tuple        =feat_extract.num_mel_bins  # hack!

   lowerCamelCase__:				Dict        =feat_extract.pad(
       UpperCAmelCase_	,			padding="max_length"	,			max_length=UpperCAmelCase_	,			truncation=UpperCAmelCase_	,			return_tensors="np")
   self.assertIn("attention_mask"	,			UpperCAmelCase_)
   self.assertListEqual(
       list(processed_pad.attention_mask.shape)	,			[processed_pad[input_name].shape[0], max_length])
   self.assertListEqual(
       processed_pad.attention_mask[:, :max_length].sum(-1).tolist()	,			[max_length for x in speech_inputs])

 def 							SCREAMING_SNAKE_CASE_ (self    :       int	,			UpperCAmelCase_    :       Tuple)	->Tuple:



   '''simple docstring'''



   from datasets import load_dataset

   lowerCamelCase__:				Tuple        =load_dataset("hf-internal-testing/librispeech_asr_dummy"	,			"clean"	,			split="validation")
   # automatic decoding with librispeech
   lowerCamelCase__:				Dict        =ds.sort("id").select(range(UpperCAmelCase_))[:num_samples]["audio"]

   return [x["array"] for x in speech_samples]

 def 							SCREAMING_SNAKE_CASE_ (self    :       Dict)	->str:



   '''simple docstring'''



   lowerCamelCase__:				Any        =torch.tensor(
       [2.3_8_0_4E-0_3, 2.0_7_5_2E-0_3, 1.9_8_3_6E-0_3, 2.1_0_5_7E-0_3, 1.6_1_7_4E-0_3,
        3.0_5_1_8E-0_4, 9.1_5_5_3E-0_5, 3.3_5_6_9E-0_4, 9.7_6_5_6E-0_4, 1.8_3_1_1E-0_3,
        2.0_1_4_2E-0_3, 2.1_0_5_7E-0_3, 1.7_3_9_5E-0_3, 4.5_7_7_6E-0_4, -3.9_6_7_3E-0_4,
        4.5_7_7_6E-0_4, 1.0_0_7_1E-0_3, 9.1_5_5_3E-0_5, 4.8_8_2_8E-0_4, 1.1_5_9_7E-0_3,
        7.3_2_4_2E-0_4, 9.4_6_0_4E-0_4, 1.8_0_0_5E-0_3, 1.8_3_1_1E-0_3, 8.8_5_0_1E-0_4,
        4.2_7_2_5E-0_4, 4.8_8_2_8E-0_4, 7.3_2_4_2E-0_4, 1.0_9_8_6E-0_3, 2.1_0_5_7E-0_3])
   # fmt: on

   lowerCamelCase__:				str        =self._load_datasamples(1)
   lowerCamelCase__:				Tuple        =SpeechTaFeatureExtractor()
   lowerCamelCase__:				List[Any]        =feature_extractor(UpperCAmelCase_	,			return_tensors="pt").input_values
   self.assertEquals(input_values.shape	,			(1, 93_680))
   self.assertTrue(torch.allclose(input_values[0, :30]	,			UpperCAmelCase_	,			atol=1E-6))







 def 							SCREAMING_SNAKE_CASE_ (self    :       Any)	->Optional[int]:



   '''simple docstring'''



   lowerCamelCase__:				Any        =torch.tensor(
       [-2.6870, -3.0104, -3.1356, -3.5352, -3.0044, -3.0353, -3.4719, -3.6777,
        -3.1520, -2.9435, -2.6553, -2.8795, -2.9944, -2.5921, -3.0279, -3.0386,
        -3.0864, -3.1291, -3.2353, -2.7444, -2.6831, -2.7287, -3.1761, -3.1571,
        -3.2726, -3.0582, -3.1007, -3.4533, -3.4695, -3.0998])
   # fmt: on

   lowerCamelCase__:				Tuple        =self._load_datasamples(1)
   lowerCamelCase__:				List[str]        =SpeechTaFeatureExtractor()
   lowerCamelCase__:				Union[str, Any]        =feature_extractor(audio_target=UpperCAmelCase_	,			return_tensors="pt").input_values
   self.assertEquals(input_values.shape	,			(1, 366, 80))
   self.assertTrue(torch.allclose(input_values[0, 0, :30]	,			UpperCAmelCase_	,			atol=1E-4))








from math import pow





def 					lowerCAmelCase_			(	__a     ,   __a     ,   __a     ,   __a     ,   __a     ,   )					->		tuple[int, int]:







  """simple docstring"""





  if current_sum == needed_sum:
    # If the sum of the powers is equal to needed_sum, then we have a solution.
    solutions_count += 1
    return current_sum, solutions_count

  lowerCamelCase__:				Optional[Any]        =int(pow(__a     ,   __a		)		)
  if current_sum + i_to_n <= needed_sum:
    # If the sum of the powers is less than needed_sum, then continue adding powers.
    current_sum += i_to_n
    lowerCamelCase__  , lowerCamelCase__:				int        =backtrack(
        __a     ,   __a     ,   current_number + 1     ,   __a     ,   __a		)
    current_sum -= i_to_n
  if i_to_n < needed_sum:
    # If the power of i is less than needed_sum, then try with the next power.
    lowerCamelCase__  , lowerCamelCase__:				Dict        =backtrack(
        __a     ,   __a     ,   current_number + 1     ,   __a     ,   __a		)
  return current_sum, solutions_count





def 					lowerCAmelCase_			(	__a     ,   __a		)					->		int:







  """simple docstring"""





  if not (1 <= needed_sum <= 1000 and 2 <= power <= 10):
    raise ValueError(
        "Invalid input\n"
        "needed_sum must be between 1 and 1000, power between 2 and 10."		)

  return backtrack(__a     ,   __a     ,   1     ,   0     ,   0		)[1]  # Return the solutions_count


if __name__ == "__main__":
     import doctest

     doctest.testmod()

