
"""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  ( lowerCAmelCase			):
				a__:      Tuple          =    'microsoft/speecht5_tts'
				a__:      Optional[Any]          =    (
				    '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__:      Dict          =    'text_reader'
				a__:      Tuple          =    SpeechTaProcessor
				a__:      int          =    SpeechTaForTextToSpeech
				a__:      str          =    SpeechTaHifiGan

				a__:      Any          =    ['text']
				a__:      Union[str, Any]          =    ['audio']




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




				def        UpperCAmelCase__						(				self							,						UpperCAmelCase							,						UpperCAmelCase=None   ):
							lowerCamelCase_					=  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.'''   )

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

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




				def        UpperCAmelCase__						(				self							,						UpperCAmelCase   ):
							with torch.no_grad():
										return self.model.generate_speech(**UpperCAmelCase   )





				def        UpperCAmelCase__						(				self							,						UpperCAmelCase   ):
							with torch.no_grad():
										return self.post_processor(UpperCAmelCase   ).cpu().detach()





"""simple docstring"""


from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


A_    							=					{
    """configuration_nllb_moe""": [
        """NLLB_MOE_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """NllbMoeConfig""",
    ]
}

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						A_    							=					[
						    """NLLB_MOE_PRETRAINED_MODEL_ARCHIVE_LIST""",
						    """NllbMoeForConditionalGeneration""",
						    """NllbMoeModel""",
						    """NllbMoePreTrainedModel""",
						    """NllbMoeTop2Router""",
						    """NllbMoeSparseMLP""",
						]


if TYPE_CHECKING:
						from .configuration_nllb_moe import (
						    NLLB_MOE_PRETRAINED_CONFIG_ARCHIVE_MAP,
						    NllbMoeConfig,
						)

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_nllb_moe import (
												    NLLB_MOE_PRETRAINED_MODEL_ARCHIVE_LIST,
												    NllbMoeForConditionalGeneration,
												    NllbMoeModel,
												    NllbMoePreTrainedModel,
												    NllbMoeSparseMLP,
												    NllbMoeTopaRouter,
												)


else:
						import sys

						A_    							=					_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



