
    h'                         S SK JrJr  S SKJrJrJrJr  S SKJ	r	  S SK
Jr   " S S\5      r " S S\5      r " S	 S
\5      rg)    )ABCabstractmethod)ListOptionalTupleUnion)Tensor)	Tacotron2c                   d    \ rS rSr\\S 5       5       r\S\\\	\   4   S\
\\4   4S j5       rSrg)_TextProcessor   c                     g)zTThe tokens that the each value in the processed tensor represent.

:type: List[str]
N selfs    [/var/www/auris/envauris/lib/python3.13/site-packages/torchaudio/pipelines/_tts/interface.pytokens_TextProcessor.tokens	           textsreturnc                     g)a*  Encode the given (batch of) texts into numerical tensors

Args:
    text (str or list of str): The input texts.

Returns:
    (Tensor, Tensor):
    Tensor:
        The encoded texts. Shape: `(batch, max length)`
    Tensor:
        The valid length of each sample in the batch. Shape: `(batch, )`.
Nr   )r   r   s     r   __call___TextProcessor.__call__   r   r   r   N)__name__
__module____qualname____firstlineno__propertyr   r   r   strr   r   r	   r   __static_attributes__r   r   r   r   r      sT       eCcN3 ffn8M  r   r   c                   h    \ rS rSr\\S 5       5       r\S	S\S\\   S\	\\\   4   4S jj5       r
Srg)
_Vocoder!   c                     g)z8The sample rate of the resulting waveform

:type: float
Nr   r   s    r   sample_rate_Vocoder.sample_rate"   r   r   N	specgramslengthsr   c                     g)a:  Generate waveform from the given input, such as spectrogram

Args:
    specgrams (Tensor):
        The input spectrogram. Shape: `(batch, frequency bins, time)`.
        The expected shape depends on the implementation.
    lengths (Tensor, or None, optional):
        The valid length of each sample in the batch. Shape: `(batch, )`.
        (Default: `None`)

Returns:
    (Tensor, Optional[Tensor]):
    Tensor:
        The generated waveform. Shape: `(batch, max length)`
    Tensor or None:
        The valid length of each sample in the batch. Shape: `(batch, )`.
Nr   )r   r)   r*   s      r   r   _Vocoder.__call__*   r   r   r   )N)r   r   r   r   r    r   r'   r	   r   r   r   r"   r   r   r   r$   r$   !   s\       & 8F3C uU[]efl]mUmOn  r   r$   c                       \ rS rSrSr " S S\5      r " S S\5      r\	SS.S	\4S
 jj5       r
\	SS.S	\4S jj5       r\	SS.S	\4S jj5       rSrg)Tacotron2TTSBundle?   u4  Data class that bundles associated information to use pretrained Tacotron2 and vocoder.

This class provides interfaces for instantiating the pretrained model along with
the information necessary to retrieve pretrained weights and additional data
to be used with the model.

Torchaudio library instantiates objects of this class, each of which represents
a different pretrained model. Client code should access pretrained models via these
instances.

Please see below for the usage and the available values.

Example - Character-based TTS pipeline with Tacotron2 and WaveRNN
    >>> import torchaudio
    >>>
    >>> text = "Hello, T T S !"
    >>> bundle = torchaudio.pipelines.TACOTRON2_WAVERNN_CHAR_LJSPEECH
    >>>
    >>> # Build processor, Tacotron2 and WaveRNN model
    >>> processor = bundle.get_text_processor()
    >>> tacotron2 = bundle.get_tacotron2()
    Downloading:
    100%|███████████████████████████████| 107M/107M [00:01<00:00, 87.9MB/s]
    >>> vocoder = bundle.get_vocoder()
    Downloading:
    100%|███████████████████████████████| 16.7M/16.7M [00:00<00:00, 78.1MB/s]
    >>>
    >>> # Encode text
    >>> input, lengths = processor(text)
    >>>
    >>> # Generate (mel-scale) spectrogram
    >>> specgram, lengths, _ = tacotron2.infer(input, lengths)
    >>>
    >>> # Convert spectrogram to waveform
    >>> waveforms, lengths = vocoder(specgram, lengths)
    >>>
    >>> torchaudio.save('hello-tts.wav', waveforms, vocoder.sample_rate)

Example - Phoneme-based TTS pipeline with Tacotron2 and WaveRNN
    >>>
    >>> # Note:
    >>> #     This bundle uses pre-trained DeepPhonemizer as
    >>> #     the text pre-processor.
    >>> #     Please install deep-phonemizer.
    >>> #     See https://github.com/as-ideas/DeepPhonemizer
    >>> #     The pretrained weight is automatically downloaded.
    >>>
    >>> import torchaudio
    >>>
    >>> text = "Hello, TTS!"
    >>> bundle = torchaudio.pipelines.TACOTRON2_WAVERNN_PHONE_LJSPEECH
    >>>
    >>> # Build processor, Tacotron2 and WaveRNN model
    >>> processor = bundle.get_text_processor()
    Downloading:
    100%|███████████████████████████████| 63.6M/63.6M [00:04<00:00, 15.3MB/s]
    >>> tacotron2 = bundle.get_tacotron2()
    Downloading:
    100%|███████████████████████████████| 107M/107M [00:01<00:00, 87.9MB/s]
    >>> vocoder = bundle.get_vocoder()
    Downloading:
    100%|███████████████████████████████| 16.7M/16.7M [00:00<00:00, 78.1MB/s]
    >>>
    >>> # Encode text
    >>> input, lengths = processor(text)
    >>>
    >>> # Generate (mel-scale) spectrogram
    >>> specgram, lengths, _ = tacotron2.infer(input, lengths)
    >>>
    >>> # Convert spectrogram to waveform
    >>> waveforms, lengths = vocoder(specgram, lengths)
    >>>
    >>> torchaudio.save('hello-tts.wav', waveforms, vocoder.sample_rate)
c                       \ rS rSrSrSrg) Tacotron2TTSBundle.TextProcessor   zInterface of the text processing part of Tacotron2TTS pipeline

See :func:`torchaudio.pipelines.Tacotron2TTSBundle.get_text_processor` for the usage.
r   Nr   r   r   r   __doc__r"   r   r   r   TextProcessorr1          	r   r5   c                       \ rS rSrSrSrg)Tacotron2TTSBundle.Vocoder   zInterface of the vocoder part of Tacotron2TTS pipeline

See :func:`torchaudio.pipelines.Tacotron2TTSBundle.get_vocoder` for the usage.
r   Nr3   r   r   r   Vocoderr8      r6   r   r:   N)	dl_kwargsr   c                    g)u	  Create a text processor

For character-based pipeline, this processor splits the input text by character.
For phoneme-based pipeline, this processor converts the input text (grapheme) to
phonemes.

If a pre-trained weight file is necessary,
:func:`torch.hub.download_url_to_file` is used to downloaded it.

Args:
    dl_kwargs (dictionary of keyword arguments,):
        Passed to :func:`torch.hub.download_url_to_file`.

Returns:
    TextProcessor:
        A callable which takes a string or a list of strings as input and
        returns Tensor of encoded texts and Tensor of valid lengths.
        The object also has ``tokens`` property, which allows to recover the
        tokenized form.

Example - Character-based
    >>> text = [
    >>>     "Hello World!",
    >>>     "Text-to-speech!",
    >>> ]
    >>> bundle = torchaudio.pipelines.TACOTRON2_WAVERNN_CHAR_LJSPEECH
    >>> processor = bundle.get_text_processor()
    >>> input, lengths = processor(text)
    >>>
    >>> print(input)
    tensor([[19, 16, 23, 23, 26, 11, 34, 26, 29, 23, 15,  2,  0,  0,  0],
            [31, 16, 35, 31,  1, 31, 26,  1, 30, 27, 16, 16, 14, 19,  2]],
           dtype=torch.int32)
    >>>
    >>> print(lengths)
    tensor([12, 15], dtype=torch.int32)
    >>>
    >>> print([processor.tokens[i] for i in input[0, :lengths[0]]])
    ['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!']
    >>> print([processor.tokens[i] for i in input[1, :lengths[1]]])
    ['t', 'e', 'x', 't', '-', 't', 'o', '-', 's', 'p', 'e', 'e', 'c', 'h', '!']

Example - Phoneme-based
    >>> text = [
    >>>     "Hello, T T S !",
    >>>     "Text-to-speech!",
    >>> ]
    >>> bundle = torchaudio.pipelines.TACOTRON2_WAVERNN_PHONE_LJSPEECH
    >>> processor = bundle.get_text_processor()
    Downloading:
    100%|███████████████████████████████| 63.6M/63.6M [00:04<00:00, 15.3MB/s]
    >>> input, lengths = processor(text)
    >>>
    >>> print(input)
    tensor([[54, 20, 65, 69, 11, 92, 44, 65, 38,  2,  0,  0,  0,  0],
            [81, 40, 64, 79, 81,  1, 81, 20,  1, 79, 77, 59, 37,  2]],
           dtype=torch.int32)
    >>>
    >>> print(lengths)
    tensor([10, 14], dtype=torch.int32)
    >>>
    >>> print([processor.tokens[i] for i in input[0]])
    ['HH', 'AH', 'L', 'OW', ' ', 'W', 'ER', 'L', 'D', '!', '_', '_', '_', '_']
    >>> print([processor.tokens[i] for i in input[1]])
    ['T', 'EH', 'K', 'S', 'T', '-', 'T', 'AH', '-', 'S', 'P', 'IY', 'CH', '!']
Nr   r   r;   s     r   get_text_processor%Tacotron2TTSBundle.get_text_processor   r   r   c                    g)a  Create a vocoder module, based off of either WaveRNN or GriffinLim.

If a pre-trained weight file is necessary,
:func:`torch.hub.load_state_dict_from_url` is used to downloaded it.

Args:
    dl_kwargs (dictionary of keyword arguments):
        Passed to :func:`torch.hub.load_state_dict_from_url`.

Returns:
    Vocoder:
        A vocoder module, which takes spectrogram Tensor and an optional
        length Tensor, then returns resulting waveform Tensor and an optional
        length Tensor.
Nr   r=   s     r   get_vocoderTacotron2TTSBundle.get_vocoder   r   r   c                    g)zCreate a Tacotron2 model with pre-trained weight.

Args:
    dl_kwargs (dictionary of keyword arguments):
        Passed to :func:`torch.hub.load_state_dict_from_url`.

Returns:
    Tacotron2:
        The resulting model.
Nr   r=   s     r   get_tacotron2 Tacotron2TTSBundle.get_tacotron2   r   r   r   )r   r   r   r   r4   r   r5   r$   r:   r   r>   rA   r
   rD   r"   r   r   r   r.   r.   ?   s    Ib (  .2 B} B BH '+   " )- 
) 
 
r   r.   N)abcr   r   typingr   r   r   r   torchr	   torchaudio.modelsr
   r   r$   r.   r   r   r   <module>rJ      s:    # / /  'S 2s <@ @r   