Skip to content

Commit

Permalink
Merge pull request #264 from idiap/fix-fairseq
Browse files Browse the repository at this point in the history
fix(fairseq): handle change of model file name
  • Loading branch information
eginhard authored Jan 16, 2025
2 parents 205eed3 + 8224adf commit 44c3491
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
20 changes: 12 additions & 8 deletions TTS/tts/models/vits.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import os
from dataclasses import dataclass, field, replace
from itertools import chain
from typing import Dict, List, Tuple, Union
from pathlib import Path
from typing import Any, Dict, List, Tuple, Union

import numpy as np
import torch
Expand Down Expand Up @@ -1581,13 +1582,16 @@ def load_fairseq_checkpoint(

self.disc = None
# set paths
config_file = os.path.join(checkpoint_dir, "config.json")
checkpoint_file = os.path.join(checkpoint_dir, "G_100000.pth")
vocab_file = os.path.join(checkpoint_dir, "vocab.txt")
checkpoint_dir = Path(checkpoint_dir)
config_file = checkpoint_dir / "config.json"
checkpoint_file = checkpoint_dir / "model.pth"
if not checkpoint_file.is_file():
checkpoint_file = checkpoint_dir / "G_100000.pth"
vocab_file = checkpoint_dir / "vocab.txt"
# set config params
with open(config_file, "r", encoding="utf-8") as file:
with open(config_file, "r", encoding="utf-8") as f:
# Load the JSON data as a dictionary
config_org = json.load(file)
config_org = json.load(f)
self.config.audio.sample_rate = config_org["data"]["sampling_rate"]
# self.config.add_blank = config['add_blank']
# set tokenizer
Expand Down Expand Up @@ -1821,7 +1825,7 @@ def to_config(self) -> "CharactersConfig":


class FairseqVocab(BaseVocabulary):
def __init__(self, vocab: str):
def __init__(self, vocab: Union[str, os.PathLike[Any]]):
super(FairseqVocab).__init__()
self.vocab = vocab

Expand All @@ -1831,7 +1835,7 @@ def vocab(self):
return self._vocab

@vocab.setter
def vocab(self, vocab_file):
def vocab(self, vocab_file: Union[str, os.PathLike[Any]]):
with open(vocab_file, encoding="utf-8") as f:
self._vocab = [x.replace("\n", "") for x in f.readlines()]
self.blank = self._vocab[0]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ build-backend = "hatchling.build"

[project]
name = "coqui-tts"
version = "0.25.2"
version = "0.25.3"
description = "Deep learning for Text to Speech."
readme = "README.md"
requires-python = ">=3.9, <3.13"
Expand Down
1 change: 1 addition & 0 deletions tests/zoo_tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def manager(tmp_path):
num_partitions = int(os.getenv("NUM_PARTITIONS", "1"))
partition = int(os.getenv("TEST_PARTITION", "0"))
model_names = [name for name in TTS.list_models() if name not in MODELS_WITH_SEP_TESTS]
model_names.extend(["tts_models/deu/fairseq/vits", "tts_models/sqi/fairseq/vits"])
model_names = [name for i, name in enumerate(model_names) if i % num_partitions == partition]


Expand Down

0 comments on commit 44c3491

Please sign in to comment.