Repository: coqui-ai/TTS

Issue:
[Bug] Cant run any of the xtts models using the TTS Command Line Interface (CLI) 
### Describe the bug

Hello I just started playing with the TTS library and I am running tests using the TTS Command Line Interface (CLI). 
I was able to try capacitron, vits (english and portuguese) and tacotron2 successfully. But when I tried any of the xtts models, I get the same error that suggests I have yet to set a language option. 




### To Reproduce

I tried running the following and it issues the error 

`tts --text "Welcome. This is a TTS test."  --model_name "tts_models/multilingual/multi-dataset/xtts_v2" --language en --out_path TTS_english_test_xtts_output2.wav`

`tts --text "Welcome. This is a TTS test."  --model_name "tts_models/multilingual/multi-dataset/xtts_v1.1" --language en --out_path TTS_english_test_xtts_output2.wav`

I tried these commands on multiple systems yet I get the same error 
AssertionError:  ❗  Language None is not supported. Supported languages are ['en', 'es', 'fr', 'de', 'it', 'pt', 'pl', 'tr', 'ru', 'nl', 'cs', 'ar', 'zh-cn', 'hu', 'ko', 'ja']



### Expected behavior

_No response_

### Logs

_No response_

### Environment

```shell
- TTS installed from pip install TTS
- Linux OS
```


### Additional context


My guess is that --language en is ignored and perhaps the xtts_v2 and xtts_v1.1 models are required to run in Python? I wanted to try a multilingual model through the command line interface (CLI) are there any missing steps I am missing here?

I was able to run bark using 

`tts --text "Welcome. This is a TTS test."  --model_name "tts_models/multilingual/multi-dataset/bark" --language en --out_path TTS_english_test_bark_output2.wav`
[Bug] Custom model inference error [Unresolved]
### Describe the bug

Inferencing custom model fails to work for various reasons (Language, unable to synthesize audio, unexpected pathing, json errors)

### To Reproduce

1.) Finetune model/Train model on Ljspeech dataset
2.) Run "tts --text "Text for TTS" --model_path path/to/model --config_path path/to/config.json --out_path speech.wav --language en"
3.) Errors [Language None is not supported. | raise TypeError("Invalid file: {0!r}".format(self.name))]

### Expected behavior

Produces a voice fil with which to evaluate the model

### Logs

```shell
(coqui) alpha78@----------:/mnt/q/Utilities/CUDA/TTS/TTS/server$ tts --text "Text for TTS" --model_path ./tts_models/en/ljspeech/ --config_path ./tts_models/en/ljspeech/config.json --out_path speech.wav --language en
 > Using model: xtts
 > Text: Text for TTS
 > Text splitted to sentences.
['Text for TTS']
Traceback (most recent call last):
  File "/home/alpha78/anaconda3/envs/coqui/bin/tts", line 8, in <module>
    sys.exit(main())
  File "/mnt/q/Utilities/CUDA/TTS/TTS/bin/synthesize.py", line 515, in main
    wav = synthesizer.tts(
  File "/mnt/q/Utilities/CUDA/TTS/TTS/utils/synthesizer.py", line 374, in tts
    outputs = self.tts_model.synthesize(
  File "/mnt/q/Utilities/CUDA/TTS/TTS/tts/models/xtts.py", line 392, in synthesize
    return self.inference_with_config(text, config, ref_audio_path=speaker_wav, language=language, **kwargs)
  File "/mnt/q/Utilities/CUDA/TTS/TTS/tts/models/xtts.py", line 400, in inference_with_config
    "zh-cn" if language == "zh" else language in self.config.languages
AssertionError:  ❗ Language None is not supported. Supported languages are ['en', 'es', 'fr', 'de', 'it', 'pt', 'pl', 'tr', 'ru', 'nl', 'cs', 'ar', 'zh-cn', 'hu', 'ko', 'ja']


(coqui) alpha78@----------:/mnt/q/Utilities/CUDA/TTS/TTS/server$ tts --text "Text for TTS" --model_path ./tts_models/en/ljspeech/ --config_path ./tts_models/en/ljspeech/config.json --out_path speech.wav --language en
 > Using model: xtts
 > Text: Text for TTS
 > Text splitted to sentences.
['Text for TTS']
Traceback (most recent call last):
  File "/home/alpha78/anaconda3/envs/coqui/bin/tts", line 8, in <module>
    sys.exit(main())
  File "/mnt/q/Utilities/CUDA/TTS/TTS/bin/synthesize.py", line 515, in main
    wav = synthesizer.tts(
  File "/mnt/q/Utilities/CUDA/TTS/TTS/utils/synthesizer.py", line 374, in tts
    outputs = self.tts_model.synthesize(
  File "/mnt/q/Utilities/CUDA/TTS/TTS/tts/models/xtts.py", line 392, in synthesize
    return self.inference_with_config(text, config, ref_audio_path=speaker_wav, language=language, **kwargs)
  File "/mnt/q/Utilities/CUDA/TTS/TTS/tts/models/xtts.py", line 415, in inference_with_config
    return self.full_inference(text, ref_audio_path, language, **settings)
  File "/home/alpha78/anaconda3/envs/coqui/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/mnt/q/Utilities/CUDA/TTS/TTS/tts/models/xtts.py", line 476, in full_inference
    (gpt_cond_latent, speaker_embedding) = self.get_conditioning_latents(
  File "/home/alpha78/anaconda3/envs/coqui/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/mnt/q/Utilities/CUDA/TTS/TTS/tts/models/xtts.py", line 351, in get_conditioning_latents
    audio = load_audio(file_path, load_sr)
  File "/mnt/q/Utilities/CUDA/TTS/TTS/tts/models/xtts.py", line 72, in load_audio
    audio, lsr = torchaudio.load(audiopath)
  File "/home/alpha78/anaconda3/envs/coqui/lib/python3.10/site-packages/torchaudio/_backend/utils.py", line 204, in load
    return backend.load(uri, frame_offset, num_frames, normalize, channels_first, format, buffer_size)
  File "/home/alpha78/anaconda3/envs/coqui/lib/python3.10/site-packages/torchaudio/_backend/soundfile.py", line 27, in load
    return soundfile_backend.load(uri, frame_offset, num_frames, normalize, channels_first, format)
  File "/home/alpha78/anaconda3/envs/coqui/lib/python3.10/site-packages/torchaudio/_backend/soundfile_backend.py", line 221, in load
    with soundfile.SoundFile(filepath, "r") as file_:
  File "/home/alpha78/anaconda3/envs/coqui/lib/python3.10/site-packages/soundfile.py", line 658, in __init__
    self._file = self._open(file, mode_int, closefd)
  File "/home/alpha78/anaconda3/envs/coqui/lib/python3.10/site-packages/soundfile.py", line 1212, in _open
    raise TypeError("Invalid file: {0!r}".format(self.name))
TypeError: Invalid file: None
```


### Environment

```shell
{
    "CUDA": {
        "GPU": [
            "NVIDIA GeForce RTX 3090"
        ],
        "available": true,
        "version": "12.1"
    },
    "Packages": {
        "PyTorch_debug": false,
        "PyTorch_version": "2.1.1+cu121",
        "TTS": "0.20.6",
        "numpy": "1.22.0"
    },
    "System": {
        "OS": "Linux",
        "architecture": [
            "64bit",
            "ELF"
        ],
        "processor": "x86_64",
        "python": "3.10.13",
        "version": "#1 SMP Thu Oct 5 21:02:42 UTC 2023"
    }
}
```


### Additional context

Documentation pages had two different ways to infer the model, neither worked.


Discussion:
```
~$ tts --help
usage: tts [-h] [--list_models [LIST_MODELS]]
           [--model_info_by_idx MODEL_INFO_BY_IDX]
           [--model_info_by_name MODEL_INFO_BY_NAME] [--text TEXT]
           [--model_name MODEL_NAME] [--vocoder_name VOCODER_NAME]
           [--config_path CONFIG_PATH] [--model_path MODEL_PATH]
           [--out_path OUT_PATH] [--use_cuda USE_CUDA] [--device DEVICE]
           [--vocoder_path VOCODER_PATH]
           [--vocoder_config_path VOCODER_CONFIG_PATH]
           [--encoder_path ENCODER_PATH]
           [--encoder_config_path ENCODER_CONFIG_PATH] [--cs_model CS_MODEL]
           [--emotion EMOTION] [--language LANGUAGE] [--pipe_out [PIPE_OUT]]
           [--speed SPEED] [--speakers_file_path SPEAKERS_FILE_PATH]
           [--language_ids_file_path LANGUAGE_IDS_FILE_PATH]
           [--speaker_idx SPEAKER_IDX] [--language_idx LANGUAGE_IDX]
           [--speaker_wav SPEAKER_WAV [SPEAKER_WAV ...]]
           [--gst_style GST_STYLE]
           [--capacitron_style_wav CAPACITRON_STYLE_WAV]
           [--capacitron_style_text CAPACITRON_STYLE_TEXT]
           [--list_speaker_idxs [LIST_SPEAKER_IDXS]]
           [--list_language_idxs [LIST_LANGUAGE_IDXS]]
           [--save_spectogram SAVE_SPECTOGRAM] [--reference_wav REFERENCE_WAV]
           [--reference_speaker_idx REFERENCE_SPEAKER_IDX]
           [--progress_bar PROGRESS_BAR] [--source_wav SOURCE_WAV]
           [--target_wav TARGET_WAV] [--voice_dir VOICE_DIR]
```

As you can see in the help, or in  the documentation, the proper argument name for specifying the language is `--language_idx`


Resolving patch:
diff --git a/TTS/bin/synthesize.py b/TTS/bin/synthesize.py
--- a/TTS/bin/synthesize.py
+++ b/TTS/bin/synthesize.py
@@ -419,6 +419,13 @@ def main():
             print(" > Saving output to ", args.out_path)
             return
 
+        if args.language_idx is None and args.language is not None:
+            msg = (
+                "--language is only supported for Coqui Studio models. "
+                "Use --language_idx to specify the target language for multilingual models."
+            )
+            raise ValueError(msg)
+
         # CASE4: load pre-trained model paths
         if args.model_name is not None and not args.model_path:
             model_path, config_path, model_item = manager.download_model(args.model_name)


Test patch: