
'''simple docstring'''

# 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    lowerCAmelCase       (     UpperCamelCase_  ):
 A_				:				str	=			"""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_				:				Any	=			"""text_reader"""
 A_				:				Dict	=			SpeechTaProcessor
 A_				:				str	=			SpeechTaForTextToSpeech
 A_				:				Optional[Any]	=			SpeechTaHifiGan

 A_				:				Union[str, Any]	=			["""text"""]
 A_				:				Tuple	=			["""audio"""]


 def    _A	(    self  : int    ):
  '''simple docstring'''

  if self.post_processor is None:
   lowerCAmelCase__     :   str     		=	"microsoft/speecht5_hifigan"
  super().setup()


 def    _A	(    self  : int			,							a__  : Any			,							a__  : Dict=None    ):
  '''simple docstring'''

  lowerCAmelCase__     :   List[str]     		=	self.pre_processor(text=a__			,							return_tensors="pt"			,							truncation=a__    )

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

   lowerCAmelCase__     :   int     		=	load_dataset("Matthijs/cmu-arctic-xvectors"			,							split="validation"    )
   lowerCAmelCase__     :   Dict     		=	torch.tensor(embeddings_dataset[7305]["xvector"]    ).unsqueeze(0    )

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


 def    _A	(    self  : Tuple			,							a__  : int    ):
  '''simple docstring'''

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


 def    _A	(    self  : Optional[int]			,							a__  : List[Any]    ):
  '''simple docstring'''

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







'''simple docstring'''

from ....configuration_utils import PretrainedConfig
from ....utils import logging


snake_case									=    logging.get_logger(__name__)

snake_case									=    {
    """Visual-Attention-Network/van-base""": (
        """https://huggingface.co/Visual-Attention-Network/van-base/blob/main/config.json"""
    ),
}




class    lowerCAmelCase       (     UpperCamelCase_  ):
 A_				:				Tuple	=			"""van"""


 def __init__(    self  : List[Any]			,							a__  : Dict=224			,							a__  : Dict=3			,							a__  : Union[str, Any]=[7, 3, 3, 3]			,							a__  : Optional[Any]=[4, 2, 2, 2]			,							a__  : Optional[Any]=[64, 128, 320, 512]			,							a__  : List[str]=[3, 3, 12, 3]			,							a__  : Any=[8, 8, 4, 4]			,							a__  : Optional[int]="gelu"			,							a__  : List[Any]=0.02			,							a__  : Tuple=1e-6			,							a__  : List[str]=1e-2			,							a__  : List[str]=0.0			,							a__  : List[Any]=0.0			,							**a__  : Tuple			,							):
  '''simple docstring'''

  super().__init__(**a__    )
  lowerCAmelCase__     :   Any     		=	image_size
  lowerCAmelCase__     :   Tuple     		=	num_channels
  lowerCAmelCase__     :   List[Any]     		=	patch_sizes
  lowerCAmelCase__     :   Dict     		=	strides
  lowerCAmelCase__     :   List[str]     		=	hidden_sizes
  lowerCAmelCase__     :   Union[str, Any]     		=	depths
  lowerCAmelCase__     :   Tuple     		=	mlp_ratios
  lowerCAmelCase__     :   Optional[Any]     		=	hidden_act
  lowerCAmelCase__     :   Dict     		=	initializer_range
  lowerCAmelCase__     :   int     		=	layer_norm_eps
  lowerCAmelCase__     :   Optional[Any]     		=	layer_scale_init_value
  lowerCAmelCase__     :   List[str]     		=	drop_path_rate
  lowerCAmelCase__     :   Any     		=	dropout_rate





