152334H / tortoise-tts-fast

Fast TorToiSe inference (5x or your money back!)
GNU Affero General Public License v3.0
755 stars 176 forks source link

Assertion Error when importing tortoise.model.vocoder #118

Closed alexlnkp closed 10 months ago

alexlnkp commented 11 months ago

when i run tortoise-tts.py with CLI:

(env) D:\live-translate-master\tortoise-tts-fast>python ./scripts/tortoise_tts.py --preset ultra_fast --voice emma --seed 42 --text "test"

i get this assertion:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ D:\live-translate-master\tortoise-tts-fast\scripts\tortoise_tts.py:15 in <module>                │
│                                                                                                  │
│    12 import torchaudio                                                                          │
│    13 from simple_parsing import ArgumentParser, field                                           │
│    14                                                                                            │
│ ❱  15 from tortoise.api import MODELS_DIR, TextToSpeech                                          │
│    16 from tortoise.utils.audio import load_audio                                                │
│    17 from tortoise.utils.diffusion import SAMPLERS                                              │
│    18 from tortoise.models.vocoder import VocConf                                                │
│                                                                                                  │
│ D:\live-translate-master\env\lib\site-packages\tortoise-2.4.2-py3.10.egg\tortoise\api.py:19 in   │
│ <module>                                                                                         │
│                                                                                                  │
│    16 from tortoise.models.cvvp import CVVP                                                      │
│    17 from tortoise.models.diffusion_decoder import DiffusionTts                                 │
│    18 from tortoise.models.random_latent_generator import RandomLatentConverter                  │
│ ❱  19 from tortoise.models.vocoder import VocConf                                                │
│    20 from tortoise.utils.audio import denormalize_tacotron_mel, wav_to_univnet_mel              │
│    21 from tortoise.utils.diffusion import (                                                     │
│    22 │   SpacedDiffusion,                                                                       │
│                                                                                                  │
│ D:\live-translate-master\env\lib\site-packages\tortoise-2.4.2-py3.10.egg\tortoise\models\vocoder │
│ .py:406 in <module>                                                                              │
│                                                                                                  │
│   403                                                                                            │
│   404 from pathlib import Path                                                                   │
│   405 STATIC_DIR = Path(__file__).parent.parent.parent/'static'                                  │
│ ❱ 406 assert STATIC_DIR.is_dir()                                                                 │
│   407 def BVGWithConf(fname: str):                                                               │
│   408 │   json_config = json.loads(                                                              │
│   409 │   │   (STATIC_DIR/fname).read_text()                                                     │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
AssertionError

i did setup.py install and pip install -r requirements.txt i also use a virtual environment, python ver is 3.10.11

artempavlov commented 11 months ago

TLDR: just use pip install -e . instead of python setup.py install

I was getting the same issue while trying to make it work inside a docker container. After investigating it for a while I realized the issue was due to me using python3 -m pip install instead of python3 -m pip install -e . The problem is that this line: STATIC_DIR = Path(__file__).parent.parent.parent/'static' uses __file__ attribute that stores the "pathname of the file from which the module was loaded". When you run setup.py install all your .py files get copied to D:\live-translate-master\env\lib\site-packages but the static folder that is referenced in vocoder.py does not. In this case you need to run pip install -e . instead of python setup.py install. This way nothing gets copied to your site-packages but a path to your project is added to python's environment variables. It looks kinda dirty but it should just work.

alexlnkp commented 10 months ago

TLDR: just use pip install -e . instead of python setup.py install

I was getting the same issue while trying to make it work inside a docker container. After investigating it for a while I realized the issue was due to me using python3 -m pip install instead of python3 -m pip install -e . The problem is that this line: STATIC_DIR = Path(__file__).parent.parent.parent/'static' uses __file__ attribute that stores the "pathname of the file from which the module was loaded". When you run setup.py install all your .py files get copied to D:\live-translate-master\env\lib\site-packages but the static folder that is referenced in vocoder.py does not. In this case you need to run pip install -e . instead of python setup.py install. This way nothing gets copied to your site-packages but a path to your project is added to python's environment variables. It looks kinda dirty but it should just work.

Ohhh, i see! Thanks a lot dude :)

maepopi commented 9 months ago

Hello! Allow me to reopen this thread, as I am completely over my head right now ^^I am trying to run a fine tuned model, so here is the command I used: python tortoise_tts.py --text="Hey there" --voice="voice2" --preset="fast" --candidates=3 --ar-checkpoint="/home/me/AI_Projects/tortoise-tts-fix/tortoise/custom_models/autoregressive.pth" However when I do that, I have this same error :


from pathlib import Path                                                                   │
│   405 STATIC_DIR = Path(__file__).parent.parent.parent/'static'                                  │
│ ❱ 406 assert STATIC_DIR.is_dir()                                                                 │
│   407 def BVGWithConf(fname: str):                                                               │
│   408 │   json_config = json.loads(                                                              │
│   409 │   │   (STATIC_DIR/fname).read_text()  

I tried to do as you said earlier, that is to say launch pip install -e, but I still have the same error...

I'm very new to machine learning so sorry if I ask obvious questions, I'm kind of struggling a lot lol

artempavlov commented 9 months ago

Did you remove the old package first and did it actually install successfully when you used pip install -e? Make sure to remove the old installation before running the above command:

  1. pip uninstall tortoise
  2. pip install -e

Not sure why it didn't work for you but I think installing everything from scratch should help.

maepopi commented 9 months ago

Hello ! Thank you for your answer ! Yeah I ended up reinstalling everything and it finally worked, thank you 😊😊