coqui-ai / TTS

🐸💬 - a deep learning toolkit for Text-to-Speech, battle-tested in research and production
http://coqui.ai
Mozilla Public License 2.0
35.86k stars 4.39k forks source link

[Bug] `list_speaker_idx` and throws error (CLI, v0.22.0) #3434

Closed JRMeyer closed 9 months ago

JRMeyer commented 11 months ago

Describe the bug

trying to list studio speakers from the CLI, and getting errors (macOS, CPU)

To Reproduce

  1. pip install -U TTS
  2. tts --model_name tts_models/multilingual/multi-dataset/xtts_v2 --list_speaker_idx

Expected behavior

tts --model_name tts_models/multilingual/multi-dataset/xtts_v2 --list_speaker_idx
 > tts_models/multilingual/multi-dataset/xtts_v2 is already downloaded.
 > Using model: xtts
 > Available speaker ids: (Set --speaker_idx flag to one of these values to use the multi-speaker model.
dict_keys(['Claribel Dervla', 'Daisy Studious', 'Gracie Wise', 'Tammie Ema', 'Alison Dietlinde', 'Ana Florence', 'Annmarie Nele', 'Asya Anara', 'Brenda Stern', 'Gitta Nikolina', 'Henriette Usha', 'Sofia Hellen', 'Tammy Grit', 'Tanja Adelina', 'Vjollca Johnnie', 'Andrew Chipper', 'Badr Odhiambo', 'Dionisio Schuyler', 'Royston Min', 'Viktor Eka', 'Abrahan Mack', 'Adde Michal', 'Baldur Sanjin', 'Craig Gutsy', 'Damien Black', 'Gilberto Mathias', 'Ilkin Urbano', 'Kazuhiko Atallah', 'Ludvig Milivoj', 'Suad Qasim', 'Torcull Diarmuid', 'Viktor Menelaos', 'Zacharie Aimilios', 'Nova Hogarth', 'Maja Ruoho', 'Uta Obando', 'Lidiya Szekeres', 'Chandra MacFarland', 'Szofi Granger', 'Camilla Holmström', 'Lilya Stainthorpe', 'Zofija Kendrick', 'Narelle Moon', 'Barbora MacLean', 'Alexandra Hisakawa', 'Alma María', 'Rosemary Okafor', 'Ige Behringer', 'Filip Traverse', 'Damjan Chapman', 'Wulf Carlevaro', 'Aaron Dreschner', 'Kumar Dahl', 'Eugenio Mataracı', 'Ferran Simen', 'Xavier Hayasaka', 'Luis Moray', 'Marcos Rudaski'])

Logs

josh@joshuas-macbook-pro cv % tts --model_name tts_models/multilingual/multi-dataset/xtts_v2 --list_speaker_idx

 > tts_models/multilingual/multi-dataset/xtts_v2 is already downloaded.
 > Using model: xtts
 > Available speaker ids: (Set --speaker_idx flag to one of these values to use the multi-speaker model.
Traceback (most recent call last):
  File "/opt/homebrew/bin/tts", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/TTS/bin/synthesize.py", line 443, in main
    print(synthesizer.tts_model.speaker_manager.name_to_id)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'name_to_id'

### Environment

```shell
{
    "CUDA": {
        "GPU": [],
        "available": false,
        "version": null
    },
    "Packages": {
        "PyTorch_debug": false,
        "PyTorch_version": "2.1.0",
        "TTS": "0.22.0",
        "numpy": "1.24.3"
    },
    "System": {
        "OS": "Darwin",
        "architecture": [
            "64bit",
            ""
        ],
        "processor": "arm",
        "python": "3.11.6",
        "version": "Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:18 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6000"
    }
}

Additional context

No response

kovrom commented 11 months ago

Do you have speakers_xtts.pth file? I would check that first.

davidcheal commented 11 months ago

Seeing similar/same issue using Docker container on Ubuntu

`tts --list_speaker_idxs

results in:

Traceback (most recent call last):
  File "/usr/local/bin/tts", line 8, in <module>
    sys.exit(main())
  File "/root/TTS/bin/synthesize.py", line 443, in main
    print(synthesizer.tts_model.speaker_manager.name_to_id)
AttributeError: 'NoneType' object has no attribute 'name_to_id'
{
    "CUDA": {
        "GPU": [],
        "available": false,
        "version": "11.8"
    },
    "Packages": {
        "PyTorch_debug": false,
        "PyTorch_version": "2.1.1+cu118",
        "TTS": "0.22.0",
        "numpy": "1.22.0"
    },
    "System": {
        "OS": "Linux",
        "architecture": [
            "64bit",
            ""
        ],
        "processor": "",
        "python": "3.10.8",
        "version": "#38~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Nov  2 18:01:13 UTC 2"
    }
}
imkasen commented 11 months ago

I have a similar problem. My code is as follows:

import torch
from TTS.api import TTS

# Get device
DEVICE: str = "cuda" if torch.cuda.is_available() else "cpu"

# Init TTS
tts: TTS = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2").to(DEVICE)

if tts.is_multi_speaker:
   print(tts.speakers)

Then, I got the error: AttributeError: 'TTS' object has no attribute 'speakers'.

So I checked the source code of speakers() method of the class TTS in TTS/api.py:

@property
def speakers(self):
    if not self.is_multi_speaker:
        return None
    return self.synthesizer.tts_model.speaker_manager.speaker_names

I ran it again using the implementation in the source code:

print(tts.synthesizer.tts_model.speaker_manager.speaker_names)

And a new error was:

AttributeError: 'dict_keys' object has no attribute 'keys'

Then again I checked the source code of speaker_names() method of the class SpeakerManager in TTS/tts/utils/speakers.py:

@property
def speaker_names(self):
    return list(self.name_to_id.keys())

And I tried to know what name_to_id is:

print(tts.synthesizer.tts_model.speaker_manager.name_to_id)
>>> dict_keys(['Claribel Dervla', 'Daisy Studious', ... , 'Marcos Rudaski'])

So, if I use print(list(tts.synthesizer.tts_model.speaker_manager.name_to_id)) instead of print(tts.speakers), I can get the expected answer:

print(list(tts.synthesizer.tts_model.speaker_manager.name_to_id))
>>> ['Claribel Dervla', 'Daisy Studious', ...'Marcos Rudaski']

It's certain that there's a problem in the code, but I'm not sure where it's caused by. Obviously, name_to_id is supposed to be a type like dict[str, int], but that's clearly not what's happening now. :joy:

djmaze commented 10 months ago

Had the same problem. You probably have an outdated version of the model checkpoint. The speaker data has been updated only 1 month ago.

Quick solution: rm ~/.local/share/tts/tts_models--multilingual--multi-dataset--xtts_v2 -fR

The new model will automatically be downloaded the next time you try to use it.

stale[bot] commented 9 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You might also look our discussion channels.