Skip to content

Commit

Permalink
Add basic speaker manager
Browse files Browse the repository at this point in the history
  • Loading branch information
WeberJulian committed Dec 11, 2023
1 parent 0a136a8 commit 36143fe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion TTS/.models.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"multilingual": {
"multi-dataset": {
"xtts_v2": {
"description": "XTTS-v2.0.2 by Coqui with 16 languages.",
"description": "XTTS-v2.0.3 by Coqui with 17 languages.",
"hf_url": [
"https://coqui.gateway.scarf.sh/hf-coqui/XTTS-v2/main/model.pth",
"https://coqui.gateway.scarf.sh/hf-coqui/XTTS-v2/main/config.json",
Expand Down
9 changes: 9 additions & 0 deletions TTS/tts/layers/xtts/speaker_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import torch

class SpeakerManager():
def __init__(self, speaker_file_path=None):
self.speakers = torch.load(speaker_file_path)

@property
def name_to_id(self):
return self.speakers.keys()
7 changes: 7 additions & 0 deletions TTS/tts/models/xtts.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from TTS.tts.layers.xtts.hifigan_decoder import HifiDecoder
from TTS.tts.layers.xtts.stream_generator import init_stream_support
from TTS.tts.layers.xtts.tokenizer import VoiceBpeTokenizer, split_sentence
from TTS.tts.layers.xtts.speaker_manager import SpeakerManager
from TTS.tts.models.base_tts import BaseTTS
from TTS.utils.io import load_fsspec

Expand Down Expand Up @@ -733,6 +734,7 @@ def load_checkpoint(
eval=True,
strict=True,
use_deepspeed=False,
speaker_file_path=None,
):
"""
Loads a checkpoint from disk and initializes the model's state and tokenizer.
Expand All @@ -751,6 +753,11 @@ def load_checkpoint(

model_path = checkpoint_path or os.path.join(checkpoint_dir, "model.pth")
vocab_path = vocab_path or os.path.join(checkpoint_dir, "vocab.json")
speaker_file_path = speaker_file_path or os.path.join(checkpoint_dir, "speakers.json")

self.speaker_manager = None
if os.path.exists(speaker_file_path):
self.speaker_manager = SpeakerManager(speaker_file_path)

if os.path.exists(vocab_path):
self.tokenizer = VoiceBpeTokenizer(vocab_file=vocab_path)
Expand Down

0 comments on commit 36143fe

Please sign in to comment.