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.61k stars 4.36k forks source link

[Bug] TypeError: 'NoneType' object is not subscriptable #3406

Closed Yaodada12 closed 9 months ago

Yaodada12 commented 11 months ago

Describe the bug

when I use tts_models/multilingual/multi-dataset/xtts_v2, speaker cannot be specified.

To Reproduce

from TTS.api import TTS
# List available 🐸TTS models
print(TTS().list_models())

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

# Run TTS
# ❗ Since this model is multi-lingual voice cloning model, we must set the target speaker_wav and language
# Text to speech to a file
tts.tts_to_file(text="Hello world!", speaker=tts.speakers[0], language=tts.languages[0], file_path="data/outputs/test/1.wav")

Expected behavior

no error

Logs

> tts_models/multilingual/multi-dataset/xtts_v2 is already downloaded.
 > Using model: xtts
Traceback (most recent call last):
File "/home/user/Desktop/TTS/demo.py", line 16, in <module>
    test_xttsv2()
File "/home/user/Desktop/TTS/demo.py", line 12, in test_xttsv2
    tts.tts_to_file(text="Hello world!", speaker=tts.speakers[0], language=tts.languages[0], file_path="data/outputs/test/1.wav")
TypeError: 'NoneType' object is not subscriptable

### Environment

```shell
TTS Version:v0.21.3;
Pytorch Version:2.1.0;
Python Version:3.8;
OS:Linux;

Additional context

No response

peteh commented 11 months ago

It might be related to this one: https://github.com/coqui-ai/TTS/commit/36143fee2625aac6c6b3f7c7d0e0b7d75800167a

If the speaker_file_path is None, it will try to load os.path.join(checkpoint_dir, "speakers_xtts.pth") If checkoint_dir is also None, because it's an optional parameter it will throw an exception because checkpoint_dir is not a path but None.

Then will fail in if os.path.exists(speaker_file_path): because the

Yaodada12 commented 11 months ago

It might be related to this one: 36143fe

If the speaker_file_path is None, it will try to load os.path.join(checkpoint_dir, "speakers_xtts.pth") If checkoint_dir is also None, because it's an optional parameter it will throw an exception because checkpoint_dir is not a path but None.

Then will fail in if os.path.exists(speaker_file_path): because the

you are right, I can't find the speaker_file_path in model dir,this model is not officially open sourced by coqui-ai

T0L0ve commented 11 months ago

I solved the problem by delete the "tts_models/multilingual/multi-dataset/xtts_v2" model path and install tts0.22.0 ,it will redownload the model.Then you can get the speakers_xtts.pth I don't know why sometimes it didn't download all the files.

image

from TTS.api import TTS
print(TTS().list_models())
model_name = TTS().list_models().list_models()[0]
print(model_name)
tts = TTS(model_name).to('cuda')
tts.tts_to_file("你好,这是一个测试。这也是一个测试。",speaker=tts.speakers[0], language='zh-cn',file_path="output.wav")

image

Yaodada12 commented 10 months ago

sometimes it didn't download all th

大佬666,你有尝试过用这套代码训练单个人的语音吗?

Yaodada12 commented 10 months ago

I solved the problem by delete the "tts_models/multilingual/multi-dataset/xtts_v2" model path and install tts0.22.0 ,it will redownload the model.Then you can get the speakers_xtts.pth I don't know why sometimes it didn't download all the files.

image

from TTS.api import TTS
print(TTS().list_models())
model_name = TTS().list_models().list_models()[0]
print(model_name)
tts = TTS(model_name).to('cuda')
tts.tts_to_file("你好,这是一个测试。这也是一个测试。",speaker=tts.speakers[0], language='zh-cn',file_path="output.wav")

image

根据你说的重新下载模型,speakers_xtts.pth确实下载了,但是又报错“ 'TTS' object has no attribute 'speakers'”

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.