o
    
jq?                     @   sZ   d dl Z d dlZd dlZd dl mZ d dlmZ dZdd Zdd Ze	d	kr+e  dS dS )
    N)RawTextHelpFormatter)Patha  
Synthesize speech on command line.

You can either use your trained model or choose a model from the provided list.

If you don't specify any models, then it uses LJSpeech based English model.

#### Single Speaker Models

- List provided models:

  ```
  $ tts --list_models
  ```

- Get model info (for both tts_models and vocoder_models):

  - Query by type/name:
    The model_info_by_name uses the name as it from the --list_models.
    ```
    $ tts --model_info_by_name "<model_type>/<language>/<dataset>/<model_name>"
    ```
    For example:
    ```
    $ tts --model_info_by_name tts_models/tr/common-voice/glow-tts
    $ tts --model_info_by_name vocoder_models/en/ljspeech/hifigan_v2
    ```
  - Query by type/idx:
    The model_query_idx uses the corresponding idx from --list_models.

    ```
    $ tts --model_info_by_idx "<model_type>/<model_query_idx>"
    ```

    For example:

    ```
    $ tts --model_info_by_idx tts_models/3
    ```

  - Query info for model info by full name:
    ```
    $ tts --model_info_by_name "<model_type>/<language>/<dataset>/<model_name>"
    ```

- Run TTS with default models:

  ```
  $ tts --text "Text for TTS" --out_path output/path/speech.wav
  ```

- Run TTS and pipe out the generated TTS wav file data:

  ```
  $ tts --text "Text for TTS" --pipe_out --out_path output/path/speech.wav | aplay
  ```

- Run a TTS model with its default vocoder model:

  ```
  $ tts --text "Text for TTS" --model_name "<model_type>/<language>/<dataset>/<model_name>" --out_path output/path/speech.wav
  ```

  For example:

  ```
  $ tts --text "Text for TTS" --model_name "tts_models/en/ljspeech/glow-tts" --out_path output/path/speech.wav
  ```

- Run with specific TTS and vocoder models from the list:

  ```
  $ tts --text "Text for TTS" --model_name "<model_type>/<language>/<dataset>/<model_name>" --vocoder_name "<model_type>/<language>/<dataset>/<model_name>" --out_path output/path/speech.wav
  ```

  For example:

  ```
  $ tts --text "Text for TTS" --model_name "tts_models/en/ljspeech/glow-tts" --vocoder_name "vocoder_models/en/ljspeech/univnet" --out_path output/path/speech.wav
  ```

- Run your own TTS model (Using Griffin-Lim Vocoder):

  ```
  $ tts --text "Text for TTS" --model_path path/to/model.pth --config_path path/to/config.json --out_path output/path/speech.wav
  ```

- Run your own TTS and Vocoder models:

  ```
  $ tts --text "Text for TTS" --model_path path/to/model.pth --config_path path/to/config.json --out_path output/path/speech.wav
      --vocoder_path path/to/vocoder.pth --vocoder_config_path path/to/vocoder_config.json
  ```

#### Multi-speaker Models

- List the available speakers and choose a <speaker_id> among them:

  ```
  $ tts --model_name "<language>/<dataset>/<model_name>"  --list_speaker_idxs
  ```

- Run the multi-speaker TTS model with the target speaker ID:

  ```
  $ tts --text "Text for TTS." --out_path output/path/speech.wav --model_name "<language>/<dataset>/<model_name>"  --speaker_idx <speaker_id>
  ```

- Run your own multi-speaker TTS model:

  ```
  $ tts --text "Text for TTS" --out_path output/path/speech.wav --model_path path/to/model.pth --config_path path/to/config.json --speakers_file_path path/to/speaker.json --speaker_idx <speaker_id>
  ```

### Voice Conversion Models

```
$ tts --out_path output/path/speech.wav --model_name "<language>/<dataset>/<model_name>" --source_wav <path/to/speaker/wav> --target_wav <path/to/reference/wav>
```
c                 C   s8   t | tr| S |  dv rdS |  dv rdS td)N)yestruety1T)nofalsefn0FzBoolean value expected.)
isinstanceboollowerargparseArgumentTypeError)v r   E/home/kuhnn/.local/lib/python3.10/site-packages/TTS/bin/synthesize.pystr2bool   s   

r   c                  C   s|  t jtddtd} | jdtddddd	 | jd
td dd | jdtd dd | jdtd dd | jdtddd | jdtd dd | jdd tdd | jdtd dd | jdtddd | jdtddd  | jd!td"d#d  | jd$td%d d  | jd&td'd d  | jd(td)d d  | jd*td+d d  | jd,d-tdddd. | jd/td0d d  | jd1td2d d  | jd3td4d d  | jd5td6d d  | jd7d8d9d d: | jd;d<d d= | jd>td?d d  | jd@tdAd d  | jdBdCtdddd. | jdDdEtdddd. | jdFtdGdd  | jdHtdId d  | jdJtdKd d  | jdLtdMdd  | jdNtd dOd | jdPtd dQd | jdRtd dSd | 	 }|j
|j|j|j|j|j|j|j|jg	}t|s^| 	dTg |jretjnd }t|jrod ntj dUdVlm} dUdWlm} dUdXlm} tt j!dY }|||j"dZ}| }	d }
d }d }d }d }d }d }d }d }d }d }|jr|  t#  |jr|j}|| t#  |jr|j}|$| t#  |j%d ur0|j&s0|'|j%\}}}|d[ d\kr|}
|}d]|v r|j(d u r|d] n|j(|_(|d[ d^kr|}|}|)d_d d`ks't*|da t+r0|}d }
d }d |_(|j(d urC|j,sC|'|j(\}}}|j&d urU|j&}
|j-}|j.}|j/}|j,d ura|j,}|j0}|j1d urm|j1}|j2}|j3}|j4rvdb}||
|||||||||||j56|}|jrt7dc t7|j8j9j: 	 W d    d S |jrt7dd t7|j8j;j: 	 W d    d S |j<r|j=s|j>st7de 	 W d    d S |j
rt7df?|j
 |
d ur|j@|j
|j=|jA|j>|j|jB|jC|jDdg}n!|d ur|jE|j|jdh}n|d ur|j@|j
|j=|jA|j>di}t7dj?|jF |jG||jF|dk W d    d S 1 s7w   Y  d S )lNz    ```
 )descriptionformatter_classz--list_models?TFz2list available pre-trained TTS and vocoder models.)typenargsconstdefaulthelpz--model_info_by_idxz=model info using query format: <model_type>/<model_query_idx>)r   r   r   z--model_info_by_namezMmodel info using query format: <model_type>/<language>/<dataset>/<model_name>z--textzText to generate speech.z--model_namez$tts_models/en/ljspeech/tacotron2-DDCzUName of one of the pre-trained TTS models in format <language>/<dataset>/<model_name>z--vocoder_namezZName of one of the pre-trained  vocoder models in format <language>/<dataset>/<model_name>z--config_pathzPath to model config file.)r   r   r   z--model_pathzPath to model file.z
--out_pathztts_output.wavzOutput wav file path.z
--use_cudazRun model on CUDA.)r   r   r   z--devicezDevice to run model on.cpuz--vocoder_pathzPath to vocoder model file. If it is not defined, model uses GL as vocoder. Please make sure that you installed vocoder library before (WaveRNN).z--vocoder_config_pathz"Path to vocoder model config file.z--encoder_pathz#Path to speaker encoder model file.z--encoder_config_pathz$Path to speaker encoder config file.z
--pipe_outz1stdout the generated TTS wav file for shell pipe.)r   r   r   r   r   z--speakers_file_pathz"JSON file for multi-speaker model.z--language_ids_file_pathz"JSON file for multi-lingual model.z--speaker_idxz0Target speaker ID for a multi-speaker TTS model.z--language_idxz1Target language ID for a multi-lingual TTS model.z--speaker_wav+zwav file(s) to condition a multi-speaker TTS model with a Speaker Encoder. You can give multiple file paths. The d_vectors is computed as their average.)r   r   r   z--gst_stylez&Wav path file for GST style reference.)r   r   z--capacitron_style_wavz/Wav path file for Capacitron prosody reference.z--capacitron_style_textzTranscription of the reference.z--list_speaker_idxsz?List available speaker ids for the defined multi-speaker model.z--list_language_idxsz@List available language ids for the defined multi-lingual model.z--save_spectogramzIIf true save raw spectogram for further (vocoder) processing in out_path.z--reference_wavzLReference wav file to convert in the voice of the speaker_idx or speaker_wavz--reference_speaker_idxzsspeaker ID of the reference_wav speaker (If not provided the embedding will be computed using the Speaker Encoder).z--progress_barzEIf true shows a progress bar for the model download. Defaults to Truez--source_wavz=Original audio file to convert in the voice of the target_wavz--target_wavz;Target audio file to convert in the voice of the source_wavz--voice_dirzVoice dir for tortoise modelz-hr   )TTS)ModelManager)Synthesizerz../.models.json)progress_bar
model_type
tts_modelsdefault_vocodervoice_conversion_modelsauthorfairseq	model_urlcudazh > Available speaker ids: (Set --speaker_idx flag to one of these values to use the multi-speaker model.zj > Available language ids: (Set --language_idx flag to one of these values to use the multi-lingual model.z [!] Looks like you use a multi-speaker model. Define `--speaker_idx` to select the target speaker. You can list the available speakers for this model by `--list_speaker_idxs`.z > Text: {})speaker_namelanguage_namespeaker_wavreference_wav	style_wav
style_textreference_speaker_name)
source_wav
target_wav)r.   r/   r0   z > Saving output to {})pipe_out)Hr   ArgumentParserr   replacer   add_argumentr   strr   
parse_argstextlist_modelslist_speaker_idxslist_language_idxsr1   model_info_by_idxmodel_info_by_namer5   r6   anyr7   sysstdout
contextlibredirect_stdoutTTS.apir"   TTS.utils.manager#   TTS.utils.synthesizerr$   r   __file__parentr%   exitmodel_info_by_full_name
model_name
model_pathdownload_modelvocoder_namegetr   listvocoder_pathconfig_pathspeakers_file_pathlanguage_ids_file_pathvocoder_config_pathencoder_pathencoder_config_pathdeviceuse_cuda	voice_dirtoprint	tts_modelspeaker_manager
name_to_idlanguage_managertts_speakers_filespeaker_idxr0   formatttslanguage_idxcapacitron_style_wavcapacitron_style_textreference_speaker_idxvoice_conversionout_pathsave_wav)parserargs
check_argsr7   r"   r#   r$   pathmanagerapitts_pathtts_config_pathrW   rX   rU   rY   rZ   r[   vc_pathvc_config_path	model_dirmodel_querymodel_query_full_namerP   rV   
model_item_r\   synthesizerwavr   r   r   main   sL  
	
	



"ow



 $r   __main__)
r   rF   rD   r   pathlibr   r   r   r   __name__r   r   r   r   <module>   s   z
  _
