解决使用Coqui/TTS遇到的ValueError: [!] Model file not found in the output path问题

问题描述

windows + conda 环境下:
使用TTS文本转语音生成命令时,经常会遇到ValueError: [!] Model file not found in the output path的问题:
运行命令:

TTS --text "hello world" --model_name "tts_models/en/ljspeech/glow-tts" --out_path output.wav

报错内容:

(tts) D:\aitools\TTS>TTS --text "hello world" --model_name "tts_models/en/ljspeech/glow-tts" --out_path output.wav
 > tts_models/en/ljspeech/glow-tts is already downloaded.
Traceback (most recent call last):
  File "C:\Users\Carino\AppData\Local\Programs\Python\Python310\Scripts\tts-script.py", line 33, in 
    sys.exit(load_entry_point('TTS==0.11.1', 'console_scripts', 'tts')())
  File "C:\Users\Carino\AppData\Local\Programs\Python\Python310\lib\site-packages\tts-0.11.1-py3.10-win-amd64.egg\TTS\bin\synthesize.py", line 294, in main
    model_path, config_path, model_item = manager.download_model(args.model_name)
  File "C:\Users\Carino\AppData\Local\Programs\Python\Python310\lib\site-packages\tts-0.11.1-py3.10-win-amd64.egg\TTS\utils\manage.py", line 248, in download_model
    output_model_path, output_config_path = self._find_files(output_path)
  File "C:\Users\Carino\AppData\Local\Programs\Python\Python310\lib\site-packages\tts-0.11.1-py3.10-win-amd64.egg\TTS\utils\manage.py", line 271, in _find_files
    raise ValueError(" [!] Model file not found in the output path")
ValueError:  [!] Model file not found in the output path

原因分析:

是因为在运行生成语言的文件时,程序会去下载对应的模型文件,但因为网络原因,导致文件下载不成功,但是在系统路径C:\Users\<你的电脑用户名>\AppData\Local\tts\里却已经创建了对应模型的路径,而实际的模型文件要么根本就没下载下来,要么就是下载了一半的BadZIpFile,因此报错。

解决办法:

C:\Users\<你的电脑用户名>\AppData\Local\tts\下,将模型文件同名文件夹删除,重新运行生成语音命令,在程序报错时,观察报错信息里出现的网址https://coqui.gateway.scarf.sh/v0.6.1_models/tts_models--en--ljspeech--glow-tts.zip,复制网址从浏览器下载模型文件。如下:

解决使用Coqui/TTS遇到的ValueError: [!] Model file not found in the output path问题_第1张图片

然后将模型文件解压缩,并放在上述路径下。注意,模型文件通常包含config.json,model_file.pth,例如:

在这里插入图片描述

解决 ModuleNotFoundError: No module named ‘torch._C‘问题

再次运行过程中,大概率会出现 ModuleNotFoundError: No module named ‘torch._C‘问题,是因为torch版本问题导致,解决办法:

我的操作顺序是(以下操作均在虚拟环境下):
1. conda install pytorch
2. pip uninstall torch
3. conda uninstall pytorch
4. pip install TTS --upgrade

正常的操作方式,应该只需要首先卸载虚拟环境里安装好的torch, 然后通过更新TTS的方式将torch补齐安装:

pip install TTS --upgrade

接下来就可以成功运行啦!

(tts_2) C:\Windows\system32>TTS --text "hello world" --model_name "tts_models/en/ljspeech/glow-tts" --out_path output.wav
 > tts_models/en/ljspeech/glow-tts is already downloaded.
 > vocoder_models/en/ljspeech/multiband-melgan is already downloaded.
 > Using model: glow_tts
 > Setting up Audio Processor...
 | > sample_rate:22050
 | > resample:False
 | > num_mels:80
 | > log_func:np.log10
 | > min_level_db:-100
 | > frame_shift_ms:None
 | > frame_length_ms:None
 | > ref_level_db:0
 | > fft_size:1024
 | > power:1.1
 | > preemphasis:0.0
 | > griffin_lim_iters:60
 | > signal_norm:False
 | > symmetric_norm:True
 | > mel_fmin:50.0
 | > mel_fmax:7600.0
 | > pitch_fmin:1.0
 | > pitch_fmax:640.0
 | > spec_gain:1.0
 | > stft_pad_mode:reflect
 | > max_norm:1.0
 | > clip_norm:True
 | > do_trim_silence:True
 | > trim_db:60
 | > do_sound_norm:False
 | > do_amp_to_db_linear:True
 | > do_amp_to_db_mel:True
 | > do_rms_norm:False
 | > db_level:None
 | > stats_path:None
 | > base:10
 | > hop_length:256
 | > win_length:1024
 > Vocoder Model: multiband_melgan
 > Setting up Audio Processor...
 | > sample_rate:22050
 | > resample:False
 | > num_mels:80
 | > log_func:np.log10
 | > min_level_db:-100
 | > frame_shift_ms:None
 | > frame_length_ms:None
 | > ref_level_db:0
 | > fft_size:1024
 | > power:1.5
 | > preemphasis:0.0
 | > griffin_lim_iters:60
 | > signal_norm:True
 | > symmetric_norm:True
 | > mel_fmin:50.0
 | > mel_fmax:7600.0
 | > pitch_fmin:0.0
 | > pitch_fmax:640.0
 | > spec_gain:1.0
 | > stft_pad_mode:reflect
 | > max_norm:4.0
 | > clip_norm:True
 | > do_trim_silence:True
 | > trim_db:60
 | > do_sound_norm:False
 | > do_amp_to_db_linear:True
 | > do_amp_to_db_mel:True
 | > do_rms_norm:False
 | > db_level:None
 | > stats_path:C:\Users\Carino\AppData\Local\tts\vocoder_models--en--ljspeech--multiband-melgan\scale_stats.npy
 | > base:10
 | > hop_length:256
 | > win_length:1024
 > Generator Model: multiband_melgan_generator
 > Discriminator Model: melgan_multiscale_discriminator
 > Text: hello world
 > Text splitted to sentences.
['hello world']
 > Processing time: 0.3919985294342041
 > Real-time factor: 0.28358161332100396
 > Saving output to output.wav

其他问题

ts_models--multilingual--multi-dataset--your_tts.zip模型下载

当想尝试用自己的声音训练模型时,需要用到模型tts_models--multilingual--multi-dataset--your_tts.zip, 通过 命令下载模型由于网络原因经常会失败,与上面同样的方式,需要通过浏览器下载后将文件解压缩放在C:\Users\<你的电脑用户名>\AppData\Local\tts\路径下使用
它的下载地址是https://github.com/coqui-ai/TTS/releases/download/v0.10.1_models/tts_models--multilingual--multi-dataset--your_tts.zip

你可能感兴趣的:(python,windows,ubuntu,TTS)