o
    
j-                     @   sH   d dl mZmZ d dlmZ d dlmZmZmZ eG dd deZ	dS )    )	dataclassfield)List)BaseTTSConfigCapacitronVAEConfig	GSTConfigc                   @   s  e Zd ZU dZdZeed< dZeed< dZ	e
ed< dZeed< dZeed	< dZeed
< dZeed< dZeed< dZeed< dZeee  ed< dZeed< dZeed< dZeed< dZeed< dZeed< dZeed< dZeed< dZeed< dZeed < dZeed!< d"Z eed#< d$Z!eed%< dZ"eed&< dZ#eed'< d(Z$eed)< dZ%eed*< dZ&eed+< dZ'eed,< dZ(eed-< dZ)eed.< dZ*eed/< dZ+eed0< dZ,eed1< d2Z-eed3< dZ.eed4< dZ/eed5< d6Z0eed7< dZ1eed8< dZ2eed9< dZ3eed:< d;Z4eed<< e5d=d> d?Z6e7ed@< dAZ8eedB< e5dCd> d?Z9e7edD< dEZ:eedF< dGZ;eedH< dZ<eedI< dZ=eedJ< dKZ>eedL< dKZ?eedM< dKZ@eedN< dKZAeedO< dKZBeedP< dKZCeedQ< dGZDeedR< e5dSd> d?ZEee edT< dUdV ZFdS )WTacotronConfiga  Defines parameters for Tacotron based models.

    Example:

        >>> from TTS.tts.configs.tacotron_config import TacotronConfig
        >>> config = TacotronConfig()

    Args:
        model (str):
            Model name used to select the right model class to initilize. Defaults to `Tacotron`.
        use_gst (bool):
            enable / disable the use of Global Style Token modules. Defaults to False.
        gst (GSTConfig):
            Instance of `GSTConfig` class.
        gst_style_input (str):
            Path to the wav file used at inference to set the speech style through GST. If `GST` is enabled and
            this is not defined, the model uses a zero vector as an input. Defaults to None.
        use_capacitron_vae (bool):
            enable / disable the use of Capacitron modules. Defaults to False.
        capacitron_vae (CapacitronConfig):
            Instance of `CapacitronConfig` class.
        num_chars (int):
            Number of characters used by the model. It must be defined before initializing the model. Defaults to None.
        num_speakers (int):
            Number of speakers for multi-speaker models. Defaults to 1.
        r (int):
            Initial number of output frames that the decoder computed per iteration. Larger values makes training and inference
            faster but reduces the quality of the output frames. This must be equal to the largest `r` value used in
            `gradual_training` schedule. Defaults to 1.
        gradual_training (List[List]):
            Parameters for the gradual training schedule. It is in the form `[[a, b, c], [d ,e ,f] ..]` where `a` is
            the step number to start using the rest of the values, `b` is the `r` value and `c` is the batch size.
            If sets None, no gradual training is used. Defaults to None.
        memory_size (int):
            Defines the number of previous frames used by the Prenet. If set to < 0, then it uses only the last frame.
            Defaults to -1.
        prenet_type (str):
            `original` or `bn`. `original` sets the default Prenet and `bn` uses Batch Normalization version of the
            Prenet. Defaults to `original`.
        prenet_dropout (bool):
            enables / disables the use of dropout in the Prenet. Defaults to True.
        prenet_dropout_at_inference (bool):
            enable / disable the use of dropout in the Prenet at the inference time. Defaults to False.
        stopnet (bool):
            enable /disable the Stopnet that predicts the end of the decoder sequence. Defaults to True.
        stopnet_pos_weight (float):
            Weight that is applied to over-weight positive instances in the Stopnet loss. Use larger values with
            datasets with longer sentences. Defaults to 0.2.
        max_decoder_steps (int):
            Max number of steps allowed for the decoder. Defaults to 50.
        encoder_in_features (int):
            Channels of encoder input and character embedding tensors. Defaults to 256.
        decoder_in_features (int):
            Channels of decoder input and encoder output tensors. Defaults to 256.
        out_channels (int):
            Channels of the final model output. It must match the spectragram size. Defaults to 80.
        separate_stopnet (bool):
            Use a distinct Stopnet which is trained separately from the rest of the model. Defaults to True.
        attention_type (str):
            attention type. Check ```TTS.tts.layers.attentions.init_attn```. Defaults to 'original'.
        attention_heads (int):
            Number of attention heads for GMM attention. Defaults to 5.
        windowing (bool):
            It especially useful at inference to keep attention alignment diagonal. Defaults to False.
        use_forward_attn (bool):
            It is only valid if ```attn_type``` is ```original```.  Defaults to False.
        forward_attn_mask (bool):
            enable/disable extra masking over forward attention. It is useful at inference to prevent
            possible attention failures. Defaults to False.
        transition_agent (bool):
            enable/disable transition agent in forward attention. Defaults to False.
        location_attn (bool):
            enable/disable location sensitive attention as in the original Tacotron2 paper.
            It is only valid if ```attn_type``` is ```original```. Defaults to True.
        bidirectional_decoder (bool):
            enable/disable bidirectional decoding. Defaults to False.
        double_decoder_consistency (bool):
            enable/disable double decoder consistency. Defaults to False.
        ddc_r (int):
            reduction rate used by the coarse decoder when `double_decoder_consistency` is in use. Set this
            as a multiple of the `r` value. Defaults to 6.
        speakers_file (str):
            Path to the speaker mapping file for the Speaker Manager. Defaults to None.
        use_speaker_embedding (bool):
            enable / disable using speaker embeddings for multi-speaker models. If set True, the model is
            in the multi-speaker mode. Defaults to False.
        use_d_vector_file (bool):
            enable /disable using external speaker embeddings in place of the learned embeddings. Defaults to False.
        d_vector_file (str):
            Path to the file including pre-computed speaker embeddings. Defaults to None.
        optimizer (str):
            Optimizer used for the training. Set one from `torch.optim.Optimizer` or `TTS.utils.training`.
            Defaults to `RAdam`.
        optimizer_params (dict):
            Optimizer kwargs. Defaults to `{"betas": [0.8, 0.99], "weight_decay": 0.0}`
        lr_scheduler (str):
            Learning rate scheduler for the training. Use one from `torch.optim.Scheduler` schedulers or
            `TTS.utils.training`. Defaults to `NoamLR`.
        lr_scheduler_params (dict):
            Parameters for the generator learning rate scheduler. Defaults to `{"warmup": 4000}`.
        lr (float):
            Initial learning rate. Defaults to `1e-4`.
        wd (float):
            Weight decay coefficient. Defaults to `1e-6`.
        grad_clip (float):
            Gradient clipping threshold. Defaults to `5`.
        seq_len_norm (bool):
            enable / disable the sequnce length normalization in the loss functions. If set True, loss of a sample
            is divided by the sequence length. Defaults to False.
        loss_masking (bool):
            enable / disable masking the paddings of the samples in loss computation. Defaults to True.
        decoder_loss_alpha (float):
            Weight for the decoder loss of the Tacotron model. If set less than or equal to zero, it disables the
            corresponding loss function. Defaults to 0.25
        postnet_loss_alpha (float):
            Weight for the postnet loss of the Tacotron model. If set less than or equal to zero, it disables the
            corresponding loss function. Defaults to 0.25
        postnet_diff_spec_alpha (float):
            Weight for the postnet differential loss of the Tacotron model. If set less than or equal to zero, it disables the
            corresponding loss function. Defaults to 0.25
        decoder_diff_spec_alpha (float):

            Weight for the decoder differential loss of the Tacotron model. If set less than or equal to zero, it disables the
            corresponding loss function. Defaults to 0.25
        decoder_ssim_alpha (float):
            Weight for the decoder SSIM loss of the Tacotron model. If set less than or equal to zero, it disables the
            corresponding loss function. Defaults to 0.25
        postnet_ssim_alpha (float):
            Weight for the postnet SSIM loss of the Tacotron model. If set less than or equal to zero, it disables the
            corresponding loss function. Defaults to 0.25
        ga_alpha (float):
            Weight for the guided attention loss. If set less than or equal to zero, it disables the corresponding loss
            function. Defaults to 5.
    tacotronmodelFuse_gstNgstgst_style_inputuse_capacitron_vaecapacitron_vae   num_speakersr   	num_chars   rgradual_trainingmemory_sizeoriginalprenet_typeTprenet_dropoutprenet_dropout_at_inferencestopnetseparate_stopnetg?stopnet_pos_weighti'  max_decoder_steps   encoder_in_featuresdecoder_in_featuresP   decoder_output_dimi  out_channelsattention_typeattention_headssigmoidattention_normattention_win	windowinguse_forward_attnforward_attn_masktransition_agentlocation_attnbidirectional_decoderdouble_decoder_consistency   ddc_rspeakers_fileuse_speaker_embeddingi   speaker_embedding_dimuse_d_vector_filed_vector_filed_vector_dimRAdam	optimizerc                   C   s   ddgddS )Ng?gV-?gư>)betasweight_decay r>   r>   r>   R/home/kuhnn/.local/lib/python3.10/site-packages/TTS/tts/configs/tacotron_config.py<lambda>   s    zTacotronConfig.<lambda>)default_factoryoptimizer_paramsNoamLRlr_schedulerc                   C   s   ddiS )Nwarmup_stepsi  r>   r>   r>   r>   r?   r@          lr_scheduler_paramsg-C6?lrg      @	grad_clipseq_len_normloss_maskingg      ?decoder_loss_alphapostnet_loss_alphapostnet_diff_spec_alphadecoder_diff_spec_alphadecoder_ssim_alphapostnet_ssim_alphaga_alphac                   C   s   g dS )N)zcIt took me quite a long time to develop a voice, and now that I have it I'm not going to be silent.zBe a voice, not an echo.z+I'm sorry Dave. I'm afraid I can't do that.z0This cake is great. It's so delicious and moist.zPrior to November 22, 1963.r>   r>   r>   r>   r?   r@      rF   test_sentencesc                 C   s   | j r| j d d | jksJ d| j d d  d| j | jdkrB| jd urB| j| jjd d ksBJ | j d| jjd d  | jdkrU| jd urW| j| jjksYJ d S d S d S )Nr   r   zU[!] the first scheduled gradual training `r` must be equal to the model's `r` value. z vs r	   r   	tacotron2)r   r   r
   audior%   fft_sizenum_mels)selfr>   r>   r?   check_values   s   zTacotronConfig.check_values)G__name__
__module____qualname____doc__r
   str__annotations__r   boolr   r   r   r   r   r   r   intr   r   r   r   r   r   r   r   r   r   r   floatr   r!   r"   r$   r%   r&   r'   r)   r*   r+   r,   r-   r.   r/   r0   r1   r3   r4   r5   r6   r7   r8   r9   r;   r   rB   dictrD   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rY   r>   r>   r>   r?   r      s|   
  
r   N)
dataclassesr   r   typingr   TTS.tts.configs.shared_configsr   r   r   r   r>   r>   r>   r?   <module>   s
    