





'''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 					__a      (lowerCamelCase     ):
							__a					:   Dict									=       "microsoft/speecht5_tts"
							__a					:   List[str]									=       (
							    "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					:   int									=       SpeechTaProcessor
							__a					:   List[str]									=       SpeechTaForTextToSpeech
							__a					:   str									=       SpeechTaHifiGan

							__a					:   int									=       ["text"]
							__a					:   int									=       ["audio"]

							def     UpperCAmelCase__	(							self							:     Any   )					->       Any:







													"""simple docstring"""
													if self.post_processor is None:
																			UpperCAmelCase_			:      List[Any]     						=  '''microsoft/speecht5_hifigan'''
													super().setup()

							def     UpperCAmelCase__	(							self							:     List[Any]       ,     __magic_name__							:     Tuple       ,     __magic_name__							:     str=None   )					->       List[str]:







													"""simple docstring"""
													UpperCAmelCase_			:      str     						=  self.pre_processor(text=__magic_name__       ,     return_tensors='''pt'''       ,     truncation=__magic_name__   )

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

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

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

							def     UpperCAmelCase__	(							self							:     Dict       ,     __magic_name__							:     Optional[int]   )					->       int:







													"""simple docstring"""
													with torch.no_grad():
																			return self.model.generate_speech(**__magic_name__   )



							def     UpperCAmelCase__	(							self							:     int       ,     __magic_name__							:     Tuple   )					->       int:







													"""simple docstring"""
													with torch.no_grad():
																			return self.post_processor(__magic_name__   ).cpu().detach()












'''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.
from ..models.whisper import WhisperForConditionalGeneration, WhisperProcessor
from .base import PipelineTool


class 					__a      (lowerCamelCase     ):
							__a					:   List[Any]									=       "openai/whisper-base"
							__a					:   Optional[Any]									=       (
							    "This is a tool that transcribes an audio into text. It takes an input named `audio` and returns the "
							    "transcribed text."
							)
							__a					:   Any									=       "transcriber"
							__a					:   str									=       WhisperProcessor
							__a					:   List[Any]									=       WhisperForConditionalGeneration

							__a					:   int									=       ["audio"]
							__a					:   Optional[Any]									=       ["text"]

							def     UpperCAmelCase__	(							self							:     Dict       ,     __magic_name__							:     List[str]   )					->       Optional[int]:







													"""simple docstring"""
													return self.pre_processor(__magic_name__       ,     return_tensors='''pt'''   ).input_features

							def     UpperCAmelCase__	(							self							:     Dict       ,     __magic_name__							:     Dict   )					->       Tuple:







													"""simple docstring"""
													return self.model.generate(inputs=__magic_name__   )



							def     UpperCAmelCase__	(							self							:     List[str]       ,     __magic_name__							:     Dict   )					->       str:







													"""simple docstring"""
													return self.pre_processor.batch_decode(__magic_name__       ,     skip_special_tokens=__magic_name__   )[0]





