



# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import torch

from ..models.speechta import SpeechTaForTextToSpeech, SpeechTaHifiGan, SpeechTaProcessor
from ..utils import is_datasets_available
from .base import PipelineTool


if is_datasets_available():
      from datasets import load_dataset



class       UpperCAmelCase__(							lowerCamelCase	):

   '''simple docstring'''




   A    :  Tuple       				=    "microsoft/speecht5_tts"
   A    :  Dict       				=    (
       "This is a tool that reads an English text out loud. It takes an input named `text` which should contain the "
       "text to read (in English) and returns a waveform object containing the sound."
   )
   A    :  str       				=    "text_reader"
   A    :  Dict       				=    SpeechTaProcessor
   A    :  Dict       				=    SpeechTaForTextToSpeech
   A    :  Union[str, Any]       				=    SpeechTaHifiGan

   A    :  Dict       				=    ["text"]
   A    :  int       				=    ["audio"]


   def 			UpperCAmelCase		(						self  :			str)	->				Tuple:




         """simple docstring"""

         if self.post_processor is None:
               lowercase__     =  'microsoft/speecht5_hifigan'
         super().setup()


   def 			UpperCAmelCase		(						self  :			Any			,				lowerCAmelCase  :			Dict			,				lowerCAmelCase  :			Optional[int]=None)	->				int:




         """simple docstring"""

         lowercase__     =  self.pre_processor(text=lowerCAmelCase			,				return_tensors='pt'			,				truncation=lowerCAmelCase)

         if speaker_embeddings is None:
               if not is_datasets_available():
                     raise ImportError('Datasets needs to be installed if not passing speaker embeddings.')

               lowercase__     =  load_dataset('Matthijs/cmu-arctic-xvectors'			,				split='validation')
               lowercase__     =  torch.tensor(embeddings_dataset[73_05]['xvector']).unsqueeze(0)

         return {"input_ids": inputs["input_ids"], "speaker_embeddings": speaker_embeddings}


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




         """simple docstring"""

         with torch.no_grad():
               return self.model.generate_speech(**lowerCAmelCase)



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




         """simple docstring"""

         with torch.no_grad():
               return self.post_processor(lowerCAmelCase).cpu().detach()





def   _lowerCAmelCase   (						A__						,  A__						,  A__	):
      if principal <= 0:
            raise Exception('Principal borrowed must be > 0'	)
      if rate_per_annum < 0:
            raise Exception('Rate of interest must be >= 0'	)
      if years_to_repay <= 0 or not isinstance(A__						,  A__	):
            raise Exception('Years to repay must be an integer > 0'	)

      # Yearly rate is divided by 12 to get monthly rate
      lowercase__     =  rate_per_annum / 12

      # Years to repay is multiplied by 12 to get number of payments as payment is monthly
      lowercase__     =  years_to_repay * 12

      return (
          principal
          * rate_per_month
          * (1 + rate_per_month) ** number_of_payments
          / ((1 + rate_per_month) ** number_of_payments - 1)
      )


if __name__ == "__main__":
       import doctest

       doctest.testmod()
