



import json
import os
import shutil
import tempfile
import unittest

from transformers import is_speech_available, is_torch_available
from transformers.models.speechta import SpeechTaTokenizer
from transformers.testing_utils import get_tests_dir, require_torch
from transformers.utils import FEATURE_EXTRACTOR_NAME


if is_speech_available() and is_torch_available():
      from transformers import SpeechTaFeatureExtractor, SpeechTaProcessor

      from .test_feature_extraction_speechta import floats_list


UpperCamelCase_									=   get_tests_dir('''fixtures/test_sentencepiece_bpe_char.model''')







@require_torch
class       _snake_case				(     unittest.TestCase ):






   '''simple docstring'''






   def       A__    (    self:     List[str]							)	->      Dict:
       UpperCAmelCase_     :       str  		=					tempfile.mkdtemp()

       UpperCAmelCase_     :       Dict  		=					SpeechTaTokenizer(lowerCAmelCase_							)
       tokenizer.save_pretrained(self.tmpdirname							)

       UpperCAmelCase_     :       Optional[int]  		=					{
           """feature_size""": 1,
           """padding_value""": 0.0,
           """sampling_rate""": 16000,
           """do_normalize""": False,
           """num_mel_bins""": 80,
           """hop_length""": 16,
           """win_length""": 64,
           """win_function""": """hann_window""",
           """fmin""": 80,
           """fmax""": 7600,
           """mel_floor""": 1e-10,
           """reduction_factor""": 2,
           """return_attention_mask""": True,
       }

       UpperCAmelCase_     :       Optional[Any]  		=					os.path.join(self.tmpdirname  ,lowerCAmelCase_							)
       with open(self.feature_extraction_file  ,"""w"""  ,encoding="""utf-8"""							) as fp:
           fp.write(json.dumps(lowerCAmelCase_							) + """\n"""							)


   def       A__    (    self:     str  ,**lowerCamelCase_:     Optional[int]							)	->      str:
       return SpeechTaTokenizer.from_pretrained(self.tmpdirname  ,**lowerCAmelCase_							)


   def       A__    (    self:     Optional[Any]  ,**lowerCamelCase_:     str							)	->      Optional[int]:
       return SpeechTaFeatureExtractor.from_pretrained(self.tmpdirname  ,**lowerCAmelCase_							)


   def       A__    (    self:     List[Any]							)	->      Optional[int]:
       shutil.rmtree(self.tmpdirname							)


   def       A__    (    self:     str							)	->      Tuple:
       UpperCAmelCase_     :       List[str]  		=					self.get_tokenizer()
       UpperCAmelCase_     :       Tuple  		=					self.get_feature_extractor()

       UpperCAmelCase_     :       Any  		=					SpeechTaProcessor(tokenizer=lowerCAmelCase_  ,feature_extractor=lowerCAmelCase_							)

       processor.save_pretrained(self.tmpdirname							)
       UpperCAmelCase_     :       Dict  		=					SpeechTaProcessor.from_pretrained(self.tmpdirname							)

       self.assertEqual(processor.tokenizer.get_vocab()  ,tokenizer.get_vocab()							)
       self.assertIsInstance(processor.tokenizer  ,lowerCAmelCase_							)

       self.assertEqual(processor.feature_extractor.to_json_string()  ,feature_extractor.to_json_string()							)
       self.assertIsInstance(processor.feature_extractor  ,lowerCAmelCase_							)


   def       A__    (    self:     List[Any]							)	->      List[Any]:
       UpperCAmelCase_     :       str  		=					SpeechTaProcessor(tokenizer=self.get_tokenizer()  ,feature_extractor=self.get_feature_extractor()							)
       processor.save_pretrained(self.tmpdirname							)

       UpperCAmelCase_     :       List[str]  		=					self.get_tokenizer(bos_token="""(BOS)"""  ,eos_token="""(EOS)"""							)
       UpperCAmelCase_     :       Dict  		=					self.get_feature_extractor(do_normalize=lowerCAmelCase_  ,padding_value=1.0							)

       UpperCAmelCase_     :       Any  		=					SpeechTaProcessor.from_pretrained(
           self.tmpdirname  ,bos_token="""(BOS)"""  ,eos_token="""(EOS)"""  ,do_normalize=lowerCAmelCase_  ,padding_value=1.0							)

       self.assertEqual(processor.tokenizer.get_vocab()  ,tokenizer_add_kwargs.get_vocab()							)
       self.assertIsInstance(processor.tokenizer  ,lowerCAmelCase_							)

       self.assertEqual(processor.feature_extractor.to_json_string()  ,feature_extractor_add_kwargs.to_json_string()							)
       self.assertIsInstance(processor.feature_extractor  ,lowerCAmelCase_							)


   def       A__    (    self:     List[Any]							)	->      Dict:
       UpperCAmelCase_     :       int  		=					self.get_feature_extractor()
       UpperCAmelCase_     :       str  		=					self.get_tokenizer()

       UpperCAmelCase_     :       int  		=					SpeechTaProcessor(tokenizer=lowerCAmelCase_  ,feature_extractor=lowerCAmelCase_							)

       UpperCAmelCase_     :       Optional[Any]  		=					floats_list((3, 1000)							)

       UpperCAmelCase_     :       Dict  		=					feature_extractor(audio=lowerCAmelCase_  ,return_tensors="""np"""							)
       UpperCAmelCase_     :       Optional[int]  		=					processor(audio=lowerCAmelCase_  ,return_tensors="""np"""							)

       for key in input_feat_extract.keys():
           self.assertAlmostEqual(input_feat_extract[key].sum()  ,input_processor[key].sum()  ,delta=1e-2							)


   def       A__    (    self:     Union[str, Any]							)	->      List[str]:
       UpperCAmelCase_     :       int  		=					self.get_feature_extractor()
       UpperCAmelCase_     :       Optional[Any]  		=					self.get_tokenizer()

       UpperCAmelCase_     :       Any  		=					SpeechTaProcessor(tokenizer=lowerCAmelCase_  ,feature_extractor=lowerCAmelCase_							)

       UpperCAmelCase_     :       Dict  		=					floats_list((3, 1000)							)

       UpperCAmelCase_     :       int  		=					feature_extractor(audio_target=lowerCAmelCase_  ,return_tensors="""np"""							)
       UpperCAmelCase_     :       Any  		=					processor(audio_target=lowerCAmelCase_  ,return_tensors="""np"""							)

       for key in input_feat_extract.keys():
           self.assertAlmostEqual(input_feat_extract[key].sum()  ,input_processor[key].sum()  ,delta=1e-2							)


   def       A__    (    self:     List[Any]							)	->      List[Any]:
       UpperCAmelCase_     :       List[Any]  		=					self.get_feature_extractor()
       UpperCAmelCase_     :       Union[str, Any]  		=					self.get_tokenizer()

       UpperCAmelCase_     :       Union[str, Any]  		=					SpeechTaProcessor(tokenizer=lowerCAmelCase_  ,feature_extractor=lowerCAmelCase_							)

       UpperCAmelCase_     :       Union[str, Any]  		=					"""This is a test string"""

       UpperCAmelCase_     :       List[str]  		=					processor(text=lowerCAmelCase_							)
       UpperCAmelCase_     :       List[str]  		=					tokenizer(lowerCAmelCase_							)

       for key in encoded_tok.keys():
           self.assertListEqual(encoded_tok[key]  ,encoded_processor[key]							)


   def       A__    (    self:     int							)	->      Tuple:
       UpperCAmelCase_     :       List[str]  		=					self.get_feature_extractor()
       UpperCAmelCase_     :       List[str]  		=					self.get_tokenizer()

       UpperCAmelCase_     :       List[Any]  		=					SpeechTaProcessor(tokenizer=lowerCAmelCase_  ,feature_extractor=lowerCAmelCase_							)

       UpperCAmelCase_     :       Tuple  		=					"""This is a test string"""

       UpperCAmelCase_     :       Dict  		=					processor(text_target=lowerCAmelCase_							)
       UpperCAmelCase_     :       List[Any]  		=					tokenizer(lowerCAmelCase_							)

       for key in encoded_tok.keys():
           self.assertListEqual(encoded_tok[key]  ,encoded_processor[key]							)


   def       A__    (    self:     Optional[Any]							)	->      Tuple:
       UpperCAmelCase_     :       List[Any]  		=					self.get_feature_extractor()
       UpperCAmelCase_     :       List[str]  		=					self.get_tokenizer()

       UpperCAmelCase_     :       Optional[int]  		=					SpeechTaProcessor(tokenizer=lowerCAmelCase_  ,feature_extractor=lowerCAmelCase_							)

       UpperCAmelCase_     :       List[str]  		=					[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

       UpperCAmelCase_     :       Any  		=					processor.batch_decode(lowerCAmelCase_							)
       UpperCAmelCase_     :       List[Any]  		=					tokenizer.batch_decode(lowerCAmelCase_							)

       self.assertListEqual(lowerCAmelCase_  ,lowerCAmelCase_							)






   def       A__    (    self:     Tuple							)	->      Any:
       UpperCAmelCase_     :       Union[str, Any]  		=					self.get_feature_extractor()
       UpperCAmelCase_     :       Any  		=					self.get_tokenizer()

       UpperCAmelCase_     :       List[Any]  		=					SpeechTaProcessor(tokenizer=lowerCAmelCase_  ,feature_extractor=lowerCAmelCase_							)

       self.assertListEqual(
           processor.model_input_names  ,feature_extractor.model_input_names  ,msg="""`processor` and `feature_extractor` model input names do not match"""  ,)

def 	__lowerCamelCase							(				)      ->       Dict:
	_lowercase   =1

	while True:
		if (
		    sorted(str(__a		)		)
		    == sorted(str(2 * i		)		)
		    == sorted(str(3 * i		)		)
		    == sorted(str(4 * i		)		)
		    == sorted(str(5 * i		)		)
		    == sorted(str(6 * i		)		)
		):
			return i

		i += 1


if __name__ == "__main__":
						print(solution())




