TTS icon indicating copy to clipboard operation
TTS copied to clipboard

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

Open Yaodada12 opened this issue 1 year ago • 4 comments

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

Yaodada12 avatar Dec 12 '23 03:12 Yaodada12

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

peteh avatar Dec 12 '23 21:12 peteh

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

Yaodada12 avatar Dec 13 '23 03:12 Yaodada12

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

T0L0ve avatar Dec 14 '23 08:12 T0L0ve

sometimes it didn't download all th

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

Yaodada12 avatar Jan 10 '24 09:01 Yaodada12

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'”

Yaodada12 avatar Jan 10 '24 10:01 Yaodada12

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.

stale[bot] avatar Feb 10 '24 18:02 stale[bot]