mirror of
https://github.com/wassname/TTS.git
synced 2026-09-10 11:50:20 +08:00
rename external speaker embedding arguments as d_vectors
This commit is contained in:
@@ -22,7 +22,7 @@ class TestExtractTTSSpectrograms(unittest.TestCase):
|
||||
c = load_config(config_path)
|
||||
# create model
|
||||
num_chars = len(phonemes if c.use_phonemes else symbols)
|
||||
model = setup_model(num_chars, 1, c, speaker_embedding_dim=None)
|
||||
model = setup_model(num_chars, 1, c, d_vector_dim=None)
|
||||
# save model
|
||||
torch.save({"model": model.state_dict()}, checkpoint_path)
|
||||
# run test
|
||||
@@ -41,7 +41,7 @@ class TestExtractTTSSpectrograms(unittest.TestCase):
|
||||
c = load_config(config_path)
|
||||
# create model
|
||||
num_chars = len(phonemes if c.use_phonemes else symbols)
|
||||
model = setup_model(num_chars, 1, c, speaker_embedding_dim=None)
|
||||
model = setup_model(num_chars, 1, c, d_vector_dim=None)
|
||||
# save model
|
||||
torch.save({"model": model.state_dict()}, checkpoint_path)
|
||||
# run test
|
||||
@@ -60,7 +60,7 @@ class TestExtractTTSSpectrograms(unittest.TestCase):
|
||||
c = load_config(config_path)
|
||||
# create model
|
||||
num_chars = len(phonemes if c.use_phonemes else symbols)
|
||||
model = setup_model(num_chars, 1, c, speaker_embedding_dim=None)
|
||||
model = setup_model(num_chars, 1, c, d_vector_dim=None)
|
||||
# save model
|
||||
torch.save({"model": model.state_dict()}, checkpoint_path)
|
||||
# run test
|
||||
|
||||
@@ -15,11 +15,11 @@ encoder_config_path = os.path.join(get_tests_input_path(), "test_speaker_encoder
|
||||
encoder_model_path = os.path.join(get_tests_input_path(), "checkpoint_0.pth.tar")
|
||||
sample_wav_path = os.path.join(get_tests_input_path(), "../data/ljspeech/wavs/LJ001-0001.wav")
|
||||
sample_wav_path2 = os.path.join(get_tests_input_path(), "../data/ljspeech/wavs/LJ001-0002.wav")
|
||||
x_vectors_file_path = os.path.join(get_tests_input_path(), "../data/dummy_speakers.json")
|
||||
d_vectors_file_path = os.path.join(get_tests_input_path(), "../data/dummy_speakers.json")
|
||||
|
||||
|
||||
class SpeakerManagerTest(unittest.TestCase):
|
||||
"""Test SpeakerManager for loading embedding files and computing x_vectors from waveforms"""
|
||||
"""Test SpeakerManager for loading embedding files and computing d_vectors from waveforms"""
|
||||
|
||||
@staticmethod
|
||||
def test_speaker_embedding():
|
||||
@@ -38,38 +38,38 @@ class SpeakerManagerTest(unittest.TestCase):
|
||||
# load a sample audio and compute embedding
|
||||
waveform = ap.load_wav(sample_wav_path)
|
||||
mel = ap.melspectrogram(waveform)
|
||||
x_vector = manager.compute_x_vector(mel.T)
|
||||
assert x_vector.shape[1] == 256
|
||||
d_vector = manager.compute_d_vector(mel.T)
|
||||
assert d_vector.shape[1] == 256
|
||||
|
||||
# compute x_vector directly from an input file
|
||||
x_vector = manager.compute_x_vector_from_clip(sample_wav_path)
|
||||
x_vector2 = manager.compute_x_vector_from_clip(sample_wav_path)
|
||||
x_vector = torch.FloatTensor(x_vector)
|
||||
x_vector2 = torch.FloatTensor(x_vector2)
|
||||
assert x_vector.shape[0] == 256
|
||||
assert (x_vector - x_vector2).sum() == 0.0
|
||||
# compute d_vector directly from an input file
|
||||
d_vector = manager.compute_d_vector_from_clip(sample_wav_path)
|
||||
d_vector2 = manager.compute_d_vector_from_clip(sample_wav_path)
|
||||
d_vector = torch.FloatTensor(d_vector)
|
||||
d_vector2 = torch.FloatTensor(d_vector2)
|
||||
assert d_vector.shape[0] == 256
|
||||
assert (d_vector - d_vector2).sum() == 0.0
|
||||
|
||||
# compute x_vector from a list of wav files.
|
||||
x_vector3 = manager.compute_x_vector_from_clip([sample_wav_path, sample_wav_path2])
|
||||
x_vector3 = torch.FloatTensor(x_vector3)
|
||||
assert x_vector3.shape[0] == 256
|
||||
assert (x_vector - x_vector3).sum() != 0.0
|
||||
# compute d_vector from a list of wav files.
|
||||
d_vector3 = manager.compute_d_vector_from_clip([sample_wav_path, sample_wav_path2])
|
||||
d_vector3 = torch.FloatTensor(d_vector3)
|
||||
assert d_vector3.shape[0] == 256
|
||||
assert (d_vector - d_vector3).sum() != 0.0
|
||||
|
||||
# remove dummy model
|
||||
os.remove(encoder_model_path)
|
||||
|
||||
@staticmethod
|
||||
def test_speakers_file_processing():
|
||||
manager = SpeakerManager(x_vectors_file_path=x_vectors_file_path)
|
||||
manager = SpeakerManager(d_vectors_file_path=d_vectors_file_path)
|
||||
print(manager.num_speakers)
|
||||
print(manager.x_vector_dim)
|
||||
print(manager.d_vector_dim)
|
||||
print(manager.clip_ids)
|
||||
x_vector = manager.get_x_vector_by_clip(manager.clip_ids[0])
|
||||
assert len(x_vector) == 256
|
||||
x_vectors = manager.get_x_vectors_by_speaker(manager.speaker_ids[0])
|
||||
assert len(x_vectors[0]) == 256
|
||||
x_vector1 = manager.get_mean_x_vector(manager.speaker_ids[0], num_samples=2, randomize=True)
|
||||
assert len(x_vector1) == 256
|
||||
x_vector2 = manager.get_mean_x_vector(manager.speaker_ids[0], num_samples=2, randomize=False)
|
||||
assert len(x_vector2) == 256
|
||||
assert np.sum(np.array(x_vector1) - np.array(x_vector2)) != 0
|
||||
d_vector = manager.get_d_vector_by_clip(manager.clip_ids[0])
|
||||
assert len(d_vector) == 256
|
||||
d_vectors = manager.get_d_vectors_by_speaker(manager.speaker_ids[0])
|
||||
assert len(d_vectors[0]) == 256
|
||||
d_vector1 = manager.get_mean_d_vector(manager.speaker_ids[0], num_samples=2, randomize=True)
|
||||
assert len(d_vector1) == 256
|
||||
d_vector2 = manager.get_mean_d_vector(manager.speaker_ids[0], num_samples=2, randomize=False)
|
||||
assert len(d_vector2) == 256
|
||||
assert np.sum(np.array(d_vector1) - np.array(d_vector2)) != 0
|
||||
|
||||
@@ -57,7 +57,7 @@ def test_speedy_speech():
|
||||
# with speaker embedding
|
||||
model = SpeedySpeech(num_chars, out_channels=80, hidden_channels=128, num_speakers=10, c_in_channels=256).to(device)
|
||||
model.forward(
|
||||
x_dummy, x_lengths, y_lengths, durations, cond_input={"x_vectors": torch.randint(0, 10, (B,)).to(device)}
|
||||
x_dummy, x_lengths, y_lengths, durations, cond_input={"d_vectors": torch.randint(0, 10, (B,)).to(device)}
|
||||
)
|
||||
o_de = outputs["model_outputs"]
|
||||
attn = outputs["alignments"]
|
||||
@@ -71,7 +71,7 @@ def test_speedy_speech():
|
||||
model = SpeedySpeech(
|
||||
num_chars, out_channels=80, hidden_channels=128, num_speakers=10, external_c=True, c_in_channels=256
|
||||
).to(device)
|
||||
model.forward(x_dummy, x_lengths, y_lengths, durations, cond_input={"x_vectors": torch.rand((B, 256)).to(device)})
|
||||
model.forward(x_dummy, x_lengths, y_lengths, durations, cond_input={"d_vectors": torch.rand((B, 256)).to(device)})
|
||||
o_de = outputs["model_outputs"]
|
||||
attn = outputs["alignments"]
|
||||
o_dr = outputs["durations_log"]
|
||||
|
||||
@@ -95,7 +95,7 @@ class MultiSpeakeTacotronTrainTest(unittest.TestCase):
|
||||
|
||||
criterion = MSELossMasked(seq_len_norm=False).to(device)
|
||||
criterion_st = nn.BCEWithLogitsLoss().to(device)
|
||||
model = Tacotron2(num_chars=24, r=c.r, num_speakers=5, speaker_embedding_dim=55).to(device)
|
||||
model = Tacotron2(num_chars=24, r=c.r, num_speakers=5, d_vector_dim=55).to(device)
|
||||
model.train()
|
||||
model_ref = copy.deepcopy(model)
|
||||
count = 0
|
||||
@@ -105,7 +105,7 @@ class MultiSpeakeTacotronTrainTest(unittest.TestCase):
|
||||
optimizer = optim.Adam(model.parameters(), lr=c.lr)
|
||||
for i in range(5):
|
||||
outputs = model.forward(
|
||||
input_dummy, input_lengths, mel_spec, mel_lengths, cond_input={"x_vectors": speaker_ids}
|
||||
input_dummy, input_lengths, mel_spec, mel_lengths, cond_input={"d_vectors": speaker_ids}
|
||||
)
|
||||
assert torch.sigmoid(outputs["stop_tokens"]).data.max() <= 1.0
|
||||
assert torch.sigmoid(outputs["stop_tokens"]).data.min() >= 0.0
|
||||
@@ -259,7 +259,7 @@ class SCGSTMultiSpeakeTacotronTrainTest(unittest.TestCase):
|
||||
stop_targets = (stop_targets.sum(2) > 0.0).unsqueeze(2).float().squeeze()
|
||||
criterion = MSELossMasked(seq_len_norm=False).to(device)
|
||||
criterion_st = nn.BCEWithLogitsLoss().to(device)
|
||||
model = Tacotron2(num_chars=24, r=c.r, num_speakers=5, speaker_embedding_dim=55, use_gst=True, gst=c.gst).to(
|
||||
model = Tacotron2(num_chars=24, r=c.r, num_speakers=5, d_vector_dim=55, use_gst=True, gst=c.gst).to(
|
||||
device
|
||||
)
|
||||
model.train()
|
||||
@@ -271,7 +271,7 @@ class SCGSTMultiSpeakeTacotronTrainTest(unittest.TestCase):
|
||||
optimizer = optim.Adam(model.parameters(), lr=c.lr)
|
||||
for i in range(5):
|
||||
outputs = model.forward(
|
||||
input_dummy, input_lengths, mel_spec, mel_lengths, cond_input={"x_vectors": speaker_embeddings}
|
||||
input_dummy, input_lengths, mel_spec, mel_lengths, cond_input={"d_vectors": speaker_embeddings}
|
||||
)
|
||||
assert torch.sigmoid(outputs["stop_tokens"]).data.max() <= 1.0
|
||||
assert torch.sigmoid(outputs["stop_tokens"]).data.min() >= 0.0
|
||||
|
||||
@@ -116,7 +116,7 @@ class MultiSpeakeTacotronTrainTest(unittest.TestCase):
|
||||
decoder_output_dim=c.audio["num_mels"],
|
||||
r=c.r,
|
||||
memory_size=c.memory_size,
|
||||
speaker_embedding_dim=55,
|
||||
d_vector_dim=55,
|
||||
).to(
|
||||
device
|
||||
) # FIXME: missing num_speakers parameter to Tacotron ctor
|
||||
@@ -130,7 +130,7 @@ class MultiSpeakeTacotronTrainTest(unittest.TestCase):
|
||||
optimizer = optim.Adam(model.parameters(), lr=c.lr)
|
||||
for _ in range(5):
|
||||
outputs = model.forward(
|
||||
input_dummy, input_lengths, mel_spec, mel_lengths, cond_input={"x_vectors": speaker_embeddings}
|
||||
input_dummy, input_lengths, mel_spec, mel_lengths, cond_input={"d_vectors": speaker_embeddings}
|
||||
)
|
||||
optimizer.zero_grad()
|
||||
loss = criterion(outputs["decoder_outputs"], mel_spec, mel_lengths)
|
||||
@@ -305,7 +305,7 @@ class SCGSTMultiSpeakeTacotronTrainTest(unittest.TestCase):
|
||||
gst=c.gst,
|
||||
r=c.r,
|
||||
memory_size=c.memory_size,
|
||||
speaker_embedding_dim=55,
|
||||
d_vector_dim=55,
|
||||
).to(
|
||||
device
|
||||
) # FIXME: missing num_speakers parameter to Tacotron ctor
|
||||
@@ -319,7 +319,7 @@ class SCGSTMultiSpeakeTacotronTrainTest(unittest.TestCase):
|
||||
optimizer = optim.Adam(model.parameters(), lr=c.lr)
|
||||
for _ in range(5):
|
||||
outputs = model.forward(
|
||||
input_dummy, input_lengths, mel_spec, mel_lengths, cond_input={"x_vectors": speaker_embeddings}
|
||||
input_dummy, input_lengths, mel_spec, mel_lengths, cond_input={"d_vectors": speaker_embeddings}
|
||||
)
|
||||
optimizer.zero_grad()
|
||||
loss = criterion(outputs["decoder_outputs"], mel_spec, mel_lengths)
|
||||
|
||||
Reference in New Issue
Block a user