'''simple docstring'''


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


snake_case__	:     Union[str, Any]      =    get_tests_dir('''fixtures/test_sentencepiece_bpe_char.model''')






@require_torch
class 	__SCREAMING_SNAKE_CASE		(			unittest.TestCase			):







  '''simple docstring'''






  def _UpperCamelCase	(					self		):




       '''simple docstring'''

       UpperCAmelCase_				:  List[Any]  = tempfile.mkdtemp()

       UpperCAmelCase_				:  Any  = SpeechTaTokenizer(snake_case_		)
       tokenizer.save_pretrained(self.tmpdirname		)

       UpperCAmelCase_				:  Optional[Any]  = {
           'feature_size': 1,
           'padding_value': 0.0,
           'sampling_rate': 1_6_0_0_0,
           'do_normalize': False,
           'num_mel_bins': 8_0,
           'hop_length': 1_6,
           'win_length': 6_4,
           'win_function': 'hann_window',
           'fmin': 8_0,
           'fmax': 7_6_0_0,
           'mel_floor': 1E-10,
           'reduction_factor': 2,
           'return_attention_mask': True,
       }

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


  def _UpperCamelCase	(					self ,						**snake_case_		):




       '''simple docstring'''

       return SpeechTaTokenizer.from_pretrained(self.tmpdirname ,						**snake_case_		)


  def _UpperCamelCase	(					self ,						**snake_case_		):




       '''simple docstring'''

       return SpeechTaFeatureExtractor.from_pretrained(self.tmpdirname ,						**snake_case_		)


  def _UpperCamelCase	(					self		):




       '''simple docstring'''

       shutil.rmtree(self.tmpdirname		)


  def _UpperCamelCase	(					self		):




       '''simple docstring'''

       UpperCAmelCase_				:  Dict  = self.get_tokenizer()
       UpperCAmelCase_				:  str  = self.get_feature_extractor()

       UpperCAmelCase_				:  Optional[Any]  = SpeechTaProcessor(tokenizer=snake_case_ ,						feature_extractor=snake_case_		)

       processor.save_pretrained(self.tmpdirname		)
       UpperCAmelCase_				:  Union[str, Any]  = SpeechTaProcessor.from_pretrained(self.tmpdirname		)

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

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


  def _UpperCamelCase	(					self		):




       '''simple docstring'''

       UpperCAmelCase_				:  Dict  = SpeechTaProcessor(tokenizer=self.get_tokenizer() ,						feature_extractor=self.get_feature_extractor()		)
       processor.save_pretrained(self.tmpdirname		)

       UpperCAmelCase_				:  List[Any]  = self.get_tokenizer(bos_token='(BOS)' ,						eos_token='(EOS)'		)
       UpperCAmelCase_				:  Any  = self.get_feature_extractor(do_normalize=snake_case_ ,						padding_value=1.0		)

       UpperCAmelCase_				:  int  = SpeechTaProcessor.from_pretrained(
           self.tmpdirname ,						bos_token='(BOS)' ,						eos_token='(EOS)' ,						do_normalize=snake_case_ ,						padding_value=1.0		)

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

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


  def _UpperCamelCase	(					self		):




       '''simple docstring'''

       UpperCAmelCase_				:  Optional[int]  = self.get_feature_extractor()
       UpperCAmelCase_				:  str  = self.get_tokenizer()

       UpperCAmelCase_				:  List[str]  = SpeechTaProcessor(tokenizer=snake_case_ ,						feature_extractor=snake_case_		)

       UpperCAmelCase_				:  Dict  = floats_list((3, 1_0_0_0)		)

       UpperCAmelCase_				:  Tuple  = feature_extractor(audio=snake_case_ ,						return_tensors='np'		)
       UpperCAmelCase_				:  Dict  = processor(audio=snake_case_ ,						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 _UpperCamelCase	(					self		):




       '''simple docstring'''

       UpperCAmelCase_				:  List[str]  = self.get_feature_extractor()
       UpperCAmelCase_				:  str  = self.get_tokenizer()

       UpperCAmelCase_				:  List[str]  = SpeechTaProcessor(tokenizer=snake_case_ ,						feature_extractor=snake_case_		)

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

       UpperCAmelCase_				:  List[Any]  = feature_extractor(audio_target=snake_case_ ,						return_tensors='np'		)
       UpperCAmelCase_				:  Optional[int]  = processor(audio_target=snake_case_ ,						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 _UpperCamelCase	(					self		):




       '''simple docstring'''

       UpperCAmelCase_				:  List[Any]  = self.get_feature_extractor()
       UpperCAmelCase_				:  Optional[int]  = self.get_tokenizer()

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

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

       UpperCAmelCase_				:  Dict  = processor(text=snake_case_		)
       UpperCAmelCase_				:  Union[str, Any]  = tokenizer(snake_case_		)

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


  def _UpperCamelCase	(					self		):




       '''simple docstring'''

       UpperCAmelCase_				:  Optional[Any]  = self.get_feature_extractor()
       UpperCAmelCase_				:  Dict  = self.get_tokenizer()

       UpperCAmelCase_				:  Tuple  = SpeechTaProcessor(tokenizer=snake_case_ ,						feature_extractor=snake_case_		)

       UpperCAmelCase_				:  Optional[int]  = 'This is a test string'

       UpperCAmelCase_				:  int  = processor(text_target=snake_case_		)
       UpperCAmelCase_				:  Optional[int]  = tokenizer(snake_case_		)

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


  def _UpperCamelCase	(					self		):




       '''simple docstring'''

       UpperCAmelCase_				:  int  = self.get_feature_extractor()
       UpperCAmelCase_				:  Tuple  = self.get_tokenizer()

       UpperCAmelCase_				:  List[str]  = SpeechTaProcessor(tokenizer=snake_case_ ,						feature_extractor=snake_case_		)

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

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

       self.assertListEqual(snake_case_ ,						snake_case_		)






  def _UpperCamelCase	(					self		):




       '''simple docstring'''

       UpperCAmelCase_				:  List[Any]  = self.get_feature_extractor()
       UpperCAmelCase_				:  Dict  = self.get_tokenizer()

       UpperCAmelCase_				:  Optional[Any]  = SpeechTaProcessor(tokenizer=snake_case_ ,						feature_extractor=snake_case_		)

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











"""simple docstring"""






def 	snake_case__  (						__lowerCamelCase							:       str				,						__lowerCamelCase							:       int = 13      ):
			"""simple docstring"""
			lowerCamelCase__						:						List[str]						      =''''''
			for c in s:
						if "A" <= c <= "Z":
									out += chr(ord('''A'''      ) + (ord(__lowerCamelCase      ) - ord('''A'''      ) + n) % 26      )
						elif "a" <= c <= "z":
									out += chr(ord('''a'''      ) + (ord(__lowerCamelCase      ) - ord('''a'''      ) + n) % 26      )
						else:
									out += c
			return out






def 	snake_case__  (						):
			"""simple docstring"""
			lowerCamelCase__						:						List[str]						      =input('''Enter message: '''      )

			lowerCamelCase__						:						str						      =dencrypt(__lowerCamelCase				,						13      )
			print('''Encryption:'''				,						__lowerCamelCase      )

			lowerCamelCase__						:						Any						      =dencrypt(__lowerCamelCase				,						13      )
			print('''Decryption: '''				,						__lowerCamelCase      )


if __name__ == "__main__":
		import doctest

		doctest.testmod()
		main()




