






'''simple docstring'''



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


__UpperCamelCase      :       Union[str, Any]      			=      logging.get_logger(__name__)

__UpperCamelCase      :       Tuple      			=      {
    """tanreinama/GPTSAN-2.8B-spout_is_uniform""": (
        """https://huggingface.co/tanreinama/GPTSAN-2.8B-spout_is_uniform/resolve/main/config.json"""
    ),
}
class 							__SCREAMING_SNAKE_CASE       (							_lowercase     ):
      __a  					='''gptsan-japanese'''
      __a  					=[
          '''past_key_values''',
      ]
      __a  					={
          '''hidden_size''': '''d_model''',
          '''num_attention_heads''': '''num_heads''',
          '''num_hidden_layers''': '''num_layers''',
      }




      def __init__(  self ,   lowerCamelCase=3_6000 ,   lowerCamelCase=1280 ,   lowerCamelCase=1024 ,   lowerCamelCase=8192 ,   lowerCamelCase=4096 ,   lowerCamelCase=128 ,   lowerCamelCase=10 ,   lowerCamelCase=0 ,   lowerCamelCase=16 ,   lowerCamelCase=16 ,   lowerCamelCase=128 ,   lowerCamelCase=0.0 ,   lowerCamelCase=1e-5 ,   lowerCamelCase=False ,   lowerCamelCase=0.0 ,   lowerCamelCase="float32" ,   lowerCamelCase=False ,   lowerCamelCase=False ,   lowerCamelCase=False ,   lowerCamelCase=0.002 ,   lowerCamelCase=False ,   lowerCamelCase=True ,   lowerCamelCase=3_5998 ,   lowerCamelCase=3_5995 ,   lowerCamelCase=3_5999 ,   **lowerCamelCase ,   )							->Optional[int]:



         '''simple docstring'''
         __a				     =    vocab_size
         __a				     =    max_position_embeddings
         __a				     =    d_model
         __a				     =    d_ff
         __a				     =    d_ext
         __a				     =    d_spout
         __a				     =    num_switch_layers
         __a				     =    num_ext_layers
         __a				     =    num_switch_layers + num_ext_layers
         __a				     =    num_heads
         __a				     =    num_experts
         __a				     =    expert_capacity
         __a				     =    dropout_rate
         __a				     =    layer_norm_epsilon
         __a				     =    router_bias
         __a				     =    router_jitter_noise
         __a				     =    router_dtype
         __a				     =    router_ignore_padding_tokens
         __a				     =    output_hidden_states
         __a				     =    output_attentions
         __a				     =    initializer_factor
         __a				     =    output_router_logits
         __a				     =    use_cache

         super().__init__(
             separator_token_id=A_ ,   pad_token_id=A_ ,   eos_token_id=A_ ,   **A_ ,   )







'''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 							__SCREAMING_SNAKE_CASE       (							_lowerCAmelCase     ):
      __a  					="microsoft/speecht5_tts"
      __a  					=(
          "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  					="text_reader"
      __a  					=SpeechTaProcessor
      __a  					=SpeechTaForTextToSpeech
      __a  					=SpeechTaHifiGan

      __a  					=["text"]
      __a  					=["audio"]




      def  __UpperCamelCase							(  self      )							->str:



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




      def  __UpperCamelCase							(  self ,   lowerCamelCase ,   lowerCamelCase=None      )							->str:



         '''simple docstring'''
         __a				     =    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.'      )

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

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




      def  __UpperCamelCase							(  self ,   lowerCamelCase      )							->List[str]:



         '''simple docstring'''
         with torch.no_grad():
            return self.model.generate_speech(**lowerCamelCase      )






      def  __UpperCamelCase							(  self ,   lowerCamelCase      )							->List[str]:



         '''simple docstring'''
         with torch.no_grad():
            return self.post_processor(lowerCamelCase      ).cpu().detach()