
"""simple docstring"""






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


UpperCAmelCase        =				random.Random()




def __magic_name__	(				_lowerCamelCase:		Union[str, Any],					_lowerCamelCase:		int=1.0,					_lowerCamelCase:		Optional[Any]=None,					_lowerCamelCase:		Union[str, Any]=None			)					->						Union[str, Any]:

	'''simple docstring'''




	if rng is None:
		lowerCAmelCase												=  global_rng

	lowerCAmelCase												=  []
	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 			lowercase					( unittest.TestCase		):






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





				"""simple docstring"""


				lowerCAmelCase												=  parent
				lowerCAmelCase												=  batch_size
				lowerCAmelCase												=  min_seq_length
				lowerCAmelCase												=  max_seq_length
				lowerCAmelCase												=  (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
				lowerCAmelCase												=  feature_size
				lowerCAmelCase												=  padding_value
				lowerCAmelCase												=  sampling_rate
				lowerCAmelCase												=  do_normalize
				lowerCAmelCase												=  num_mel_bins
				lowerCAmelCase												=  hop_length
				lowerCAmelCase												=  win_length
				lowerCAmelCase												=  win_function
				lowerCAmelCase												=  fmin
				lowerCAmelCase												=  fmax
				lowerCAmelCase												=  mel_floor
				lowerCAmelCase												=  return_attention_mask






			def 					UpperCAmelCase							(self  :	Optional[int]			)       ->	int:





				"""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 					UpperCAmelCase							(self  :	str      ,SCREAMING_SNAKE_CASE_  :	Optional[int]=False      ,SCREAMING_SNAKE_CASE_  :	Union[str, Any]=False			)       ->	Union[str, Any]:





				"""simple docstring"""


				def _flatten(SCREAMING_SNAKE_CASE_  :	Tuple			):
					return list(itertools.chain(*SCREAMING_SNAKE_CASE_			)			)

				if equal_length:
					lowerCAmelCase												=  floats_list((self.batch_size, self.max_seq_length)			)
				else:
					# make sure that inputs increase in size
					lowerCAmelCase												=  [
					    _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												=  [np.asarray(SCREAMING_SNAKE_CASE_			) for x in speech_inputs]

				return speech_inputs






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





				"""simple docstring"""


				if equal_length:
					lowerCAmelCase												=  [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												=  [
					    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												=  [np.asarray(SCREAMING_SNAKE_CASE_			) for x in speech_inputs]

				return speech_inputs





@require_torch
class 			lowercase					( lowercase__   ,unittest.TestCase		):
			lowercase        =     SpeechTaFeatureExtractor






			def 					UpperCAmelCase							(self  :	Optional[int]			)       ->	str:





				"""simple docstring"""


				lowerCAmelCase												=  SpeechTaFeatureExtractionTester(self			)






			def 					UpperCAmelCase							(self  :	Any      ,SCREAMING_SNAKE_CASE_  :	int			)       ->	Tuple:





				"""simple docstring"""


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






			def 					UpperCAmelCase							(self  :	int			)       ->	int:





				"""simple docstring"""


				lowerCAmelCase												=  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()			)
				# create three inputs of length 800, 1000, and 1200
				lowerCAmelCase												=  [floats_list((1, x)			)[0] for x in range(800      ,1_400      ,200			)]
				lowerCAmelCase												=  [np.asarray(SCREAMING_SNAKE_CASE_			) for speech_input in speech_inputs]

				# Test not batched input
				lowerCAmelCase												=  feat_extract(speech_inputs[0]      ,return_tensors='''np'''			).input_values
				lowerCAmelCase												=  feat_extract(np_speech_inputs[0]      ,return_tensors='''np'''			).input_values
				self.assertTrue(np.allclose(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_      ,atol=1e-3			)			)

				# Test batched
				lowerCAmelCase												=  feat_extract(SCREAMING_SNAKE_CASE_      ,return_tensors='''np'''			).input_values
				lowerCAmelCase												=  feat_extract(SCREAMING_SNAKE_CASE_      ,return_tensors='''np'''			).input_values
				for enc_seq_a, enc_seq_a in zip(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			):
					self.assertTrue(np.allclose(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_      ,atol=1e-3			)			)






			def 					UpperCAmelCase							(self  :	List[str]			)       ->	Optional[int]:





				"""simple docstring"""


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

				lowerCAmelCase												=  ['''longest''', '''max_length''', '''do_not_pad''']
				lowerCAmelCase												=  [None, 1_600, None]
				for max_length, padding in zip(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			):
					lowerCAmelCase												=  feat_extract(SCREAMING_SNAKE_CASE_      ,padding=SCREAMING_SNAKE_CASE_      ,max_length=SCREAMING_SNAKE_CASE_      ,return_tensors='''np'''			)
					lowerCAmelCase												=  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 					UpperCAmelCase							(self  :	Optional[int]			)       ->	List[Any]:





				"""simple docstring"""


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

				lowerCAmelCase												=  ['''longest''', '''max_length''', '''do_not_pad''']
				lowerCAmelCase												=  [None, 1_600, None]

				for max_length, padding in zip(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			):
					lowerCAmelCase												=  feat_extract(SCREAMING_SNAKE_CASE_      ,max_length=SCREAMING_SNAKE_CASE_      ,padding=SCREAMING_SNAKE_CASE_			)
					lowerCAmelCase												=  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 					UpperCAmelCase							(self  :	str			)       ->	Dict:





				"""simple docstring"""


				lowerCAmelCase												=  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()			)
				lowerCAmelCase												=  [floats_list((1, x)			)[0] for x in range(800      ,1_400      ,200			)]
				lowerCAmelCase												=  feat_extract(
				    SCREAMING_SNAKE_CASE_      ,truncation=SCREAMING_SNAKE_CASE_      ,max_length=1_000      ,padding='''max_length'''      ,return_tensors='''np'''			)
				lowerCAmelCase												=  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 					UpperCAmelCase							(self  :	Union[str, Any]			)       ->	Optional[int]:





				"""simple docstring"""


				lowerCAmelCase												=  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()			)
				lowerCAmelCase												=  [floats_list((1, x)			)[0] for x in range(800      ,1_400      ,200			)]
				lowerCAmelCase												=  feat_extract(
				    SCREAMING_SNAKE_CASE_      ,truncation=SCREAMING_SNAKE_CASE_      ,max_length=1_000      ,padding='''longest'''      ,return_tensors='''np'''			)
				lowerCAmelCase												=  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												=  [floats_list((1, x)			)[0] for x in range(800      ,1_400      ,200			)]
				lowerCAmelCase												=  feat_extract(
				    SCREAMING_SNAKE_CASE_      ,truncation=SCREAMING_SNAKE_CASE_      ,max_length=2_000      ,padding='''longest'''      ,return_tensors='''np'''			)
				lowerCAmelCase												=  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 					UpperCAmelCase							(self  :	int			)       ->	Dict:





				"""simple docstring"""


				lowerCAmelCase												=  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()			)
				lowerCAmelCase												=  np.random.rand(100			).astype(np.floataa			)
				lowerCAmelCase												=  np_speech_inputs.tolist()

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






			def 					UpperCAmelCase							(self  :	List[str]			)       ->	Union[str, Any]:





				"""simple docstring"""


				lowerCAmelCase												=  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()			)
				# create three inputs of length 800, 1000, and 1200
				lowerCAmelCase												=  [floats_list((1, x)			)[0] for x in range(800      ,1_400      ,200			)]
				lowerCAmelCase												=  [np.asarray(SCREAMING_SNAKE_CASE_			) for speech_input in speech_inputs]

				# Test feature size
				lowerCAmelCase												=  feature_extractor(audio_target=SCREAMING_SNAKE_CASE_      ,padding=SCREAMING_SNAKE_CASE_      ,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												=  feature_extractor(speech_inputs[0]      ,return_tensors='''np'''			).input_values
				lowerCAmelCase												=  feature_extractor(np_speech_inputs[0]      ,return_tensors='''np'''			).input_values
				self.assertTrue(np.allclose(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_      ,atol=1e-3			)			)

				# Test batched
				lowerCAmelCase												=  feature_extractor(SCREAMING_SNAKE_CASE_      ,return_tensors='''np'''			).input_values
				lowerCAmelCase												=  feature_extractor(SCREAMING_SNAKE_CASE_      ,return_tensors='''np'''			).input_values
				for enc_seq_a, enc_seq_a in zip(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			):
					self.assertTrue(np.allclose(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_      ,atol=1e-3			)			)

				# Test 2-D numpy arrays are batched.
				lowerCAmelCase												=  [floats_list((1, x)			)[0] for x in (800, 800, 800)]
				lowerCAmelCase												=  np.asarray(SCREAMING_SNAKE_CASE_			)
				lowerCAmelCase												=  feature_extractor(SCREAMING_SNAKE_CASE_      ,return_tensors='''np'''			).input_values
				lowerCAmelCase												=  feature_extractor(SCREAMING_SNAKE_CASE_      ,return_tensors='''np'''			).input_values
				for enc_seq_a, enc_seq_a in zip(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			):
					self.assertTrue(np.allclose(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_      ,atol=1e-3			)			)






			def 					UpperCAmelCase							(self  :	str			)       ->	Tuple:





				"""simple docstring"""


				lowerCAmelCase												=  self.feat_extract_tester.prepare_inputs_for_target()
				lowerCAmelCase												=  self.feature_extraction_class(**self.feat_extract_dict			)
				lowerCAmelCase												=  feat_extract.model_input_names[0]

				lowerCAmelCase												=  BatchFeature({input_name: speech_inputs}			)

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

				lowerCAmelCase												=  self.feat_extract_tester.prepare_inputs_for_target(equal_length=SCREAMING_SNAKE_CASE_			)
				lowerCAmelCase												=  BatchFeature({input_name: speech_inputs}      ,tensor_type='''np'''			)

				lowerCAmelCase												=  processed_features[input_name]

				if len(batch_features_input.shape			) < 3:
					lowerCAmelCase												=  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 					UpperCAmelCase							(self  :	List[str]			)       ->	Union[str, Any]:





				"""simple docstring"""


				lowerCAmelCase												=  self.feat_extract_tester.prepare_inputs_for_target(equal_length=SCREAMING_SNAKE_CASE_			)
				lowerCAmelCase												=  self.feature_extraction_class(**self.feat_extract_dict			)
				lowerCAmelCase												=  feat_extract.model_input_names[0]

				lowerCAmelCase												=  BatchFeature({input_name: speech_inputs}      ,tensor_type='''pt'''			)

				lowerCAmelCase												=  processed_features[input_name]

				if len(batch_features_input.shape			) < 3:
					lowerCAmelCase												=  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 					UpperCAmelCase							(self  :	int			)       ->	Any:





				"""simple docstring"""


				lowerCAmelCase												=  self.feature_extraction_class(**self.feat_extract_dict			)
				lowerCAmelCase												=  self.feat_extract_tester.prepare_inputs_for_target()
				lowerCAmelCase												=  feat_extract.model_input_names[0]

				lowerCAmelCase												=  BatchFeature({input_name: speech_inputs}			)

				lowerCAmelCase												=  feat_extract.num_mel_bins  # hack!

				lowerCAmelCase												=  feat_extract.pad(SCREAMING_SNAKE_CASE_      ,padding='''longest'''      ,return_tensors='''np'''			)[input_name]
				lowerCAmelCase												=  feat_extract.pad(SCREAMING_SNAKE_CASE_      ,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 					UpperCAmelCase							(self  :	Optional[int]			)       ->	int:





				"""simple docstring"""


				lowerCAmelCase												=  self.feat_extract_dict
				lowerCAmelCase												=  True
				lowerCAmelCase												=  self.feature_extraction_class(**SCREAMING_SNAKE_CASE_			)
				lowerCAmelCase												=  self.feat_extract_tester.prepare_inputs_for_target()
				lowerCAmelCase												=  [len(SCREAMING_SNAKE_CASE_			) for x in speech_inputs]
				lowerCAmelCase												=  feat_extract.model_input_names[0]

				lowerCAmelCase												=  BatchFeature({input_name: speech_inputs}			)

				lowerCAmelCase												=  feat_extract.num_mel_bins  # hack!

				lowerCAmelCase												=  feat_extract.pad(SCREAMING_SNAKE_CASE_      ,padding='''longest'''      ,return_tensors='''np'''			)
				self.assertIn('''attention_mask'''      ,SCREAMING_SNAKE_CASE_			)
				self.assertListEqual(list(processed.attention_mask.shape			)      ,list(processed[input_name].shape[:2]			)			)
				self.assertListEqual(processed.attention_mask.sum(-1			).tolist()      ,SCREAMING_SNAKE_CASE_			)






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





				"""simple docstring"""


				lowerCAmelCase												=  self.feat_extract_dict
				lowerCAmelCase												=  True
				lowerCAmelCase												=  self.feature_extraction_class(**SCREAMING_SNAKE_CASE_			)
				lowerCAmelCase												=  self.feat_extract_tester.prepare_inputs_for_target()
				lowerCAmelCase												=  [len(SCREAMING_SNAKE_CASE_			) for x in speech_inputs]
				lowerCAmelCase												=  feat_extract.model_input_names[0]

				lowerCAmelCase												=  BatchFeature({input_name: speech_inputs}			)
				lowerCAmelCase												=  min(SCREAMING_SNAKE_CASE_			)

				lowerCAmelCase												=  feat_extract.num_mel_bins  # hack!

				lowerCAmelCase												=  feat_extract.pad(
				    SCREAMING_SNAKE_CASE_      ,padding='''max_length'''      ,max_length=SCREAMING_SNAKE_CASE_      ,truncation=SCREAMING_SNAKE_CASE_      ,return_tensors='''np'''			)
				self.assertIn('''attention_mask'''      ,SCREAMING_SNAKE_CASE_			)
				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 					UpperCAmelCase							(self  :	str      ,SCREAMING_SNAKE_CASE_  :	List[str]			)       ->	List[str]:





				"""simple docstring"""


				from datasets import load_dataset

				lowerCAmelCase												=  load_dataset('''hf-internal-testing/librispeech_asr_dummy'''      ,'''clean'''      ,split='''validation'''			)
				# automatic decoding with librispeech
				lowerCAmelCase												=  ds.sort('''id'''			).select(range(SCREAMING_SNAKE_CASE_			)			)[:num_samples]['''audio''']

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






			def 					UpperCAmelCase							(self  :	int			)       ->	List[str]:





				"""simple docstring"""


				lowerCAmelCase												=  torch.tensor(
				    [2.3_804e-03, 2.0_752e-03, 1.9_836e-03, 2.1_057e-03, 1.6_174e-03,
				     3.0_518e-04, 9.1_553e-05, 3.3_569e-04, 9.7_656e-04, 1.8_311e-03,
				     2.0_142e-03, 2.1_057e-03, 1.7_395e-03, 4.5_776e-04, -3.9_673e-04,
				     4.5_776e-04, 1.0_071e-03, 9.1_553e-05, 4.8_828e-04, 1.1_597e-03,
				     7.3_242e-04, 9.4_604e-04, 1.8_005e-03, 1.8_311e-03, 8.8_501e-04,
				     4.2_725e-04, 4.8_828e-04, 7.3_242e-04, 1.0_986e-03, 2.1_057e-03]			)
				# fmt: on

				lowerCAmelCase												=  self._load_datasamples(1			)
				lowerCAmelCase												=  SpeechTaFeatureExtractor()
				lowerCAmelCase												=  feature_extractor(SCREAMING_SNAKE_CASE_      ,return_tensors='''pt'''			).input_values
				self.assertEquals(input_values.shape      ,(1, 93_680)			)
				self.assertTrue(torch.allclose(input_values[0, :30]      ,SCREAMING_SNAKE_CASE_      ,atol=1e-6			)			)






			def 					UpperCAmelCase							(self  :	Optional[int]			)       ->	int:





				"""simple docstring"""


				lowerCAmelCase												=  torch.tensor(
				    [-2.68_70, -3.01_04, -3.13_56, -3.53_52, -3.00_44, -3.03_53, -3.47_19, -3.67_77,
				     -3.15_20, -2.94_35, -2.65_53, -2.87_95, -2.99_44, -2.59_21, -3.02_79, -3.03_86,
				     -3.08_64, -3.12_91, -3.23_53, -2.74_44, -2.68_31, -2.72_87, -3.17_61, -3.15_71,
				     -3.27_26, -3.05_82, -3.10_07, -3.45_33, -3.46_95, -3.09_98]			)
				# fmt: on

				lowerCAmelCase												=  self._load_datasamples(1			)
				lowerCAmelCase												=  SpeechTaFeatureExtractor()
				lowerCAmelCase												=  feature_extractor(audio_target=SCREAMING_SNAKE_CASE_      ,return_tensors='''pt'''			).input_values
				self.assertEquals(input_values.shape      ,(1, 366, 80)			)
				self.assertTrue(torch.allclose(input_values[0, 0, :30]      ,SCREAMING_SNAKE_CASE_      ,atol=1e-4			)			)




"""simple docstring"""






from typing import List, Optional, Union

from ...image_utils import ImageInput
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType



class 			lowercase					( lowercase__		):
			lowercase        =     ['''image_processor''', '''tokenizer''']
			lowercase        =     '''BlipImageProcessor'''
			lowercase        =     ('''BertTokenizer''', '''BertTokenizerFast''')






			def __init__(self  :	Any      ,SCREAMING_SNAKE_CASE_  :	List[str]      ,SCREAMING_SNAKE_CASE_  :	Optional[int]			)       ->	Dict:





				"""simple docstring"""


				lowerCAmelCase												=  False
				super().__init__(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			)
				lowerCAmelCase												=  self.image_processor






			def __call__(self  :	int      ,SCREAMING_SNAKE_CASE_  :	ImageInput = None      ,SCREAMING_SNAKE_CASE_  :	Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None      ,SCREAMING_SNAKE_CASE_  :	bool = True      ,SCREAMING_SNAKE_CASE_  :	Union[bool, str, PaddingStrategy] = False      ,SCREAMING_SNAKE_CASE_  :	Union[bool, str, TruncationStrategy] = None      ,SCREAMING_SNAKE_CASE_  :	Optional[int] = None      ,SCREAMING_SNAKE_CASE_  :	int = 0      ,SCREAMING_SNAKE_CASE_  :	Optional[int] = None      ,SCREAMING_SNAKE_CASE_  :	Optional[bool] = None      ,SCREAMING_SNAKE_CASE_  :	bool = False      ,SCREAMING_SNAKE_CASE_  :	bool = False      ,SCREAMING_SNAKE_CASE_  :	bool = False      ,SCREAMING_SNAKE_CASE_  :	bool = False      ,SCREAMING_SNAKE_CASE_  :	bool = False      ,SCREAMING_SNAKE_CASE_  :	bool = True      ,SCREAMING_SNAKE_CASE_  :	Optional[Union[str, TensorType]] = None      ,**SCREAMING_SNAKE_CASE_  :	str      ,)       ->	BatchEncoding:





				"""simple docstring"""


				if images is None and text is None:
					raise ValueError('''You have to specify either images or text.'''			)

				# Get only text
				if images is None:
					lowerCAmelCase												=  self.tokenizer
					lowerCAmelCase												=  self.tokenizer(
					    text=SCREAMING_SNAKE_CASE_      ,add_special_tokens=SCREAMING_SNAKE_CASE_      ,padding=SCREAMING_SNAKE_CASE_      ,truncation=SCREAMING_SNAKE_CASE_      ,max_length=SCREAMING_SNAKE_CASE_      ,stride=SCREAMING_SNAKE_CASE_      ,pad_to_multiple_of=SCREAMING_SNAKE_CASE_      ,return_attention_mask=SCREAMING_SNAKE_CASE_      ,return_overflowing_tokens=SCREAMING_SNAKE_CASE_      ,return_special_tokens_mask=SCREAMING_SNAKE_CASE_      ,return_offsets_mapping=SCREAMING_SNAKE_CASE_      ,return_token_type_ids=SCREAMING_SNAKE_CASE_      ,return_length=SCREAMING_SNAKE_CASE_      ,verbose=SCREAMING_SNAKE_CASE_      ,return_tensors=SCREAMING_SNAKE_CASE_      ,**SCREAMING_SNAKE_CASE_      ,)
					return text_encoding

				# add pixel_values
				lowerCAmelCase												=  self.image_processor(SCREAMING_SNAKE_CASE_      ,return_tensors=SCREAMING_SNAKE_CASE_			)

				if text is not None:
					lowerCAmelCase												=  self.tokenizer(
					    text=SCREAMING_SNAKE_CASE_      ,add_special_tokens=SCREAMING_SNAKE_CASE_      ,padding=SCREAMING_SNAKE_CASE_      ,truncation=SCREAMING_SNAKE_CASE_      ,max_length=SCREAMING_SNAKE_CASE_      ,stride=SCREAMING_SNAKE_CASE_      ,pad_to_multiple_of=SCREAMING_SNAKE_CASE_      ,return_attention_mask=SCREAMING_SNAKE_CASE_      ,return_overflowing_tokens=SCREAMING_SNAKE_CASE_      ,return_special_tokens_mask=SCREAMING_SNAKE_CASE_      ,return_offsets_mapping=SCREAMING_SNAKE_CASE_      ,return_token_type_ids=SCREAMING_SNAKE_CASE_      ,return_length=SCREAMING_SNAKE_CASE_      ,verbose=SCREAMING_SNAKE_CASE_      ,return_tensors=SCREAMING_SNAKE_CASE_      ,**SCREAMING_SNAKE_CASE_      ,)
				else:
					lowerCAmelCase												=  None

				if text_encoding is not None:
					encoding_image_processor.update(SCREAMING_SNAKE_CASE_			)

				return encoding_image_processor






			def 					UpperCAmelCase							(self  :	List[str]      ,*SCREAMING_SNAKE_CASE_  :	str      ,**SCREAMING_SNAKE_CASE_  :	str			)       ->	Union[str, Any]:





				"""simple docstring"""


				return self.tokenizer.batch_decode(*SCREAMING_SNAKE_CASE_      ,**SCREAMING_SNAKE_CASE_			)






			def 					UpperCAmelCase							(self  :	List[Any]      ,*SCREAMING_SNAKE_CASE_  :	str      ,**SCREAMING_SNAKE_CASE_  :	Optional[int]			)       ->	Any:





				"""simple docstring"""


				return self.tokenizer.decode(*SCREAMING_SNAKE_CASE_      ,**SCREAMING_SNAKE_CASE_			)






			@property
			def 					UpperCAmelCase							(self  :	Dict			)       ->	Tuple:





				"""simple docstring"""


				lowerCAmelCase												=  self.tokenizer.model_input_names
				lowerCAmelCase												=  self.image_processor.model_input_names
				return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names			)			)


