code: 
  
  import shutil
  import tempfile
  import unittest
  
  import pytest
  
  from transformers import WhisperTokenizer, is_speech_available
  from transformers.testing_utils import require_sentencepiece, require_torch, require_torchaudio
  
  from .test_feature_extraction_whisper import floats_list
  
  
  if is_speech_available():
  		from transformers import WhisperFeatureExtractor, WhisperProcessor
  
  
  lowerCamelCase__           =				5_03_58
  lowerCamelCase__           =				5_03_62
  
  
  
  
  @require_torch
  @require_torchaudio
  @require_sentencepiece
  class 					UpperCamelCase	(     unittest.TestCase      ):
  
  
  
  
  					def 							UpperCamelCase_						( self :					Tuple						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     "openai/whisper-small.en"
  							__snake_case		       =     tempfile.mkdtemp()
  
  
  
  
  					def 							UpperCamelCase_						( self :					Dict      ,**_lowerCAmelCase :					str						):
  
  
  							"""simple docstring"""
  
  
  
  
  							return WhisperTokenizer.from_pretrained(self.checkpoint      ,**_lowerCAmelCase						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					Any      ,**_lowerCAmelCase :					Any						):
  
  
  							"""simple docstring"""
  
  
  
  
  							return WhisperFeatureExtractor.from_pretrained(self.checkpoint      ,**_lowerCAmelCase						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					int						):
  
  
  							"""simple docstring"""
  
  
  
  
  							shutil.rmtree(self.tmpdirname						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					Optional[int]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     self.get_tokenizer()
  							__snake_case		       =     self.get_feature_extractor()
  
  							__snake_case		       =     WhisperProcessor(tokenizer=_lowerCAmelCase      ,feature_extractor=_lowerCAmelCase						)
  
  							processor.save_pretrained(self.tmpdirname						)
  							__snake_case		       =     WhisperProcessor.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 							UpperCamelCase_						( self :					List[Any]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     WhisperProcessor(tokenizer=self.get_tokenizer()      ,feature_extractor=self.get_feature_extractor()						)
  							processor.save_pretrained(self.tmpdirname						)
  
  							__snake_case		       =     self.get_tokenizer(bos_token="(BOS)"      ,eos_token="(EOS)"						)
  							__snake_case		       =     self.get_feature_extractor(do_normalize=_lowerCAmelCase      ,padding_value=1.0						)
  
  							__snake_case		       =     WhisperProcessor.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 							UpperCamelCase_						( self :					List[Any]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     self.get_feature_extractor()
  							__snake_case		       =     self.get_tokenizer()
  
  							__snake_case		       =     WhisperProcessor(tokenizer=_lowerCAmelCase      ,feature_extractor=_lowerCAmelCase						)
  
  							__snake_case		       =     floats_list((3, 1_000)						)
  
  							__snake_case		       =     feature_extractor(_lowerCAmelCase      ,return_tensors="np"						)
  							__snake_case		       =     processor(_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 							UpperCamelCase_						( self :					int						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     self.get_feature_extractor()
  							__snake_case		       =     self.get_tokenizer()
  
  							__snake_case		       =     WhisperProcessor(tokenizer=_lowerCAmelCase      ,feature_extractor=_lowerCAmelCase						)
  
  							__snake_case		       =     "This is a test string"
  
  							__snake_case		       =     processor(text=_lowerCAmelCase						)
  
  							__snake_case		       =     tokenizer(_lowerCAmelCase						)
  
  							for key in encoded_tok.keys():
  									self.assertListEqual(encoded_tok[key]      ,encoded_processor[key]						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					List[str]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     self.get_feature_extractor()
  							__snake_case		       =     self.get_tokenizer()
  
  							__snake_case		       =     WhisperProcessor(tokenizer=_lowerCAmelCase      ,feature_extractor=_lowerCAmelCase						)
  
  							__snake_case		       =     [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]
  
  							__snake_case		       =     processor.batch_decode(_lowerCAmelCase						)
  							__snake_case		       =     tokenizer.batch_decode(_lowerCAmelCase						)
  
  							self.assertListEqual(_lowerCAmelCase      ,_lowerCAmelCase						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					Optional[Any]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     self.get_feature_extractor()
  							__snake_case		       =     self.get_tokenizer()
  
  							__snake_case		       =     WhisperProcessor(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 							UpperCamelCase_						( self :					List[Any]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     self.get_feature_extractor()
  							__snake_case		       =     self.get_tokenizer()
  
  							__snake_case		       =     WhisperProcessor(tokenizer=_lowerCAmelCase      ,feature_extractor=_lowerCAmelCase						)
  							__snake_case		       =     processor.get_decoder_prompt_ids(task="transcribe"      ,no_timestamps=_lowerCAmelCase						)
  
  							self.assertIsInstance(_lowerCAmelCase      ,_lowerCAmelCase						)
  							for ids in forced_decoder_ids:
  									self.assertIsInstance(_lowerCAmelCase      ,(list, tuple)						)
  
  							__snake_case		       =     [TRANSCRIBE, NOTIMESTAMPS]
  							self.assertListEqual([ids[-1] for ids in forced_decoder_ids]      ,_lowerCAmelCase						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					str						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     WhisperProcessor(tokenizer=self.get_tokenizer()      ,feature_extractor=self.get_feature_extractor()						)
  							__snake_case		       =     processor.get_prompt_ids("Mr. Quilter"						)
  							__snake_case		       =     processor.tokenizer.decode(_lowerCAmelCase						)
  
  							self.assertListEqual(prompt_ids.tolist()      ,[50_360, 1_770, 13, 2_264, 346, 353]						)
  							self.assertEqual(_lowerCAmelCase      ,"<|startofprev|> Mr. Quilter"						)
  
  
  
  
  					def 							UpperCamelCase_						( self :					Optional[int]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     WhisperProcessor(tokenizer=self.get_tokenizer()      ,feature_extractor=self.get_feature_extractor()						)
  							__snake_case		       =     processor.get_prompt_ids(""						)
  							__snake_case		       =     processor.tokenizer.decode(_lowerCAmelCase						)
  
  							self.assertListEqual(prompt_ids.tolist()      ,[50_360, 220]						)
  							self.assertEqual(_lowerCAmelCase      ,"<|startofprev|> "						)
  
  
  
  
  
  
  
  					def 							UpperCamelCase_						( self :					Optional[int]						):
  
  
  							"""simple docstring"""
  
  
  
  
  							__snake_case		       =     WhisperProcessor(tokenizer=self.get_tokenizer()      ,feature_extractor=self.get_feature_extractor()						)
  
  							def _test_prompt_error_raised_helper(_lowerCAmelCase :					Union[str, Any]      ,_lowerCAmelCase :					str						):
  									with pytest.raises(_lowerCAmelCase						) as excinfo:
  											processor.get_prompt_ids(_lowerCAmelCase						)
  									__snake_case		       =     F"""Encountered text in the prompt corresponding to disallowed special token: {special_token}."""
  									self.assertEqual(_lowerCAmelCase      ,str(excinfo.value						)						)
  
  							_test_prompt_error_raised_helper("<|startofprev|> test"      ,"<|startofprev|>"						)
  							_test_prompt_error_raised_helper("test <|notimestamps|>"      ,"<|notimestamps|>"						)
  							_test_prompt_error_raised_helper("test <|zh|> test <|transcribe|>"      ,"<|zh|>"						)
  
  
  
  
  
  
style_context: import os
  from string import ascii_letters
  
  lowerCamelCase__           =				ascii_letters + ' \t\n'
  
  
  
  def 							_lowerCamelCase(				)  ->   dict[str, None]:
  		__snake_case		       =     os.path.split(os.path.realpath(__snake_case	)	)
  		__snake_case		       =     {}
  		with open(path[0] + "/dictionary.txt"	) as dictionary_file:
  				for word in dictionary_file.read().split("\n"	):
  						__snake_case		       =     None
  		return english_words
  
  
  lowerCamelCase__           =				load_dictionary()
  
  
  
  def 							_lowerCamelCase(				__snake_case	)  ->   float:
  		__snake_case		       =     message.upper()
  		__snake_case		       =     remove_non_letters(__snake_case	)
  		__snake_case		       =     message.split()
  		__snake_case		       =     len([word for word in possible_words if word in ENGLISH_WORDS]	)
  		return float(__snake_case	) / len(__snake_case	)
  
  
  
  def 							_lowerCamelCase(				__snake_case	)  ->   str:
  		return "".join(symbol for symbol in message if symbol in LETTERS_AND_SPACE	)
  
  
  
  def 							_lowerCamelCase(				__snake_case						,						__snake_case = 20						,						__snake_case = 85	)  ->   bool:
  		__snake_case		       =     get_english_count(__snake_case	) * 100 >= word_percentage
  		__snake_case		       =     len(remove_non_letters(__snake_case	)	)
  		__snake_case		       =     (float(__snake_case	) / len(__snake_case	)) * 100
  		__snake_case		       =     message_letters_percentage >= letter_percentage
  		return words_match and letters_match
  
  
  if __name__ == "__main__":
  		import doctest
  
  		doctest.testmod()
  
  
  
  
  
  