






'''simple docstring'''




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       __lowercase					(__lowerCamelCase    ):
 _lowerCamelCase              =  '''microsoft/speecht5_tts'''
 _lowerCamelCase              =  (
     '''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.'''
 )
 _lowerCamelCase              =  '''text_reader'''
 _lowerCamelCase              =  SpeechTaProcessor
 _lowerCamelCase              =  SpeechTaForTextToSpeech
 _lowerCamelCase              =  SpeechTaHifiGan

 _lowerCamelCase              =  ['''text''']
 _lowerCamelCase              =  ['''audio''']

 def      __UpperCamelCase							(      self   :						Union[str, Any]):
   if self.post_processor is None:
     UpperCamelCase__				:					Optional[int]					=					'microsoft/speecht5_hifigan'
   super().setup()

 def      __UpperCamelCase							(      self   :						int  ,					UpperCAmelCase_   :						List[str]  ,					UpperCAmelCase_   :						int=None):
   UpperCamelCase__				:					List[Any]					=					self.pre_processor(text=UpperCAmelCase_  ,					return_tensors='pt'  ,					truncation=UpperCAmelCase_)

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

     UpperCamelCase__				:					int					=					load_dataset('Matthijs/cmu-arctic-xvectors'  ,					split='validation')
     UpperCamelCase__				:					Optional[int]					=					torch.tensor(embeddings_dataset[7_305]['xvector']).unsqueeze(0)

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

 def      __UpperCamelCase							(      self   :						Optional[Any]  ,					UpperCAmelCase_   :						Optional[Any]):
   with torch.no_grad():
     return self.model.generate_speech(**UpperCAmelCase_)





 def      __UpperCamelCase							(      self   :						Optional[int]  ,					UpperCAmelCase_   :						List[Any]):
   with torch.no_grad():
     return self.post_processor(UpperCAmelCase_).cpu().detach()












'''simple docstring'''




from ..utils import DummyObject, requires_backends







class       __lowercase					(metaclass=__lowerCamelCase    ):
	_lowerCamelCase              =  ['''torch''', '''scipy''']

	def __init__(      self   :						List[Any]  ,					*UpperCAmelCase_   :						Any  ,					**UpperCAmelCase_   :						int):
			requires_backends(self  ,					['torch', 'scipy'])

	@classmethod
	def      __UpperCamelCase							(      cls   :						Union[str, Any]  ,					*UpperCAmelCase_   :						Any  ,					**UpperCAmelCase_   :						List[Any]):
			requires_backends(cls  ,					['torch', 'scipy'])





	@classmethod
	def      __UpperCamelCase							(      cls   :						Union[str, Any]  ,					*UpperCAmelCase_   :						Optional[Any]  ,					**UpperCAmelCase_   :						Any):
			requires_backends(cls  ,					['torch', 'scipy'])




