コード例 #1
0
 def __init__(self, name):
     self._action_name = name
     self.tacotron2 = Tacotron2()
     self.feedback = tacotron2_ros.msg.TTSFeedback()
     self.result = tacotron2_ros.msg.TTSResult()
     self.server = actionlib.SimpleActionServer(self._action_name, tacotron2_ros.msg.TTSAction, execute_cb=self.execute_cb, auto_start=False)
     self.server.start()
コード例 #2
0
def evluate(test_data_generator, vocab_size, config, test_batchs):
    # 模型初始化
    tacotron2 = Tacotron2(vocab_size, config)
    path = config.checkpoingt_dir
    checkpoint = load_checkpoint(tacotron2, path, config)
    print('已恢复至最新的检查点!')
    j = 0
    score_sum = 0
    for batch, (input_ids, mel_gts,
                mel_len_wav) in zip(range(test_batchs), test_data_generator):
        for i in range(input_ids.shape[0]):
            new_input_ids = input_ids[i]
            new_input_ids = tf.expand_dims(new_input_ids, axis=0)
            mel_outputs, mel_outputs_postnet, gate_outputs, alignments = tacotron2.inference(
                new_input_ids)
            mel2 = mel_gts[i]
            mel2 = tf.expand_dims(mel2, axis=0)
            mel2 = tf.transpose(mel2, [0, 2, 1])
            score = spec_distance(mel_outputs_postnet, mel2)
            score_sum += score
            j = j + 1
            print('第{}个样本的欧式距离为:{}'.format(j, score))
    print("样本平均欧式距离为:", score_sum / j)
コード例 #3
0
    return data


if __name__ == "__main__":
    config = Tacotron2Config()
    # 检查点路径
    path = config.checkpoingt_dir

    # 字典路径
    save_path_dictionary = config.save_path_dictionary

    # 恢复字典
    tokenizer, vocab_size = get_tokenizer_keras(save_path_dictionary)

    # 模型初始化
    tacotron2 = Tacotron2(vocab_size, config)

    # 加载检查点
    checkpoint = load_checkpoint(tacotron2, path, config)
    print('已恢复至最新的检查点!')

    # 用于命名
    i = 0
    # 抓取文本数据
    while True:
        i = i+1
        b = str(i)
        print("请输入您要合成的话,输入ESC结束:")
        seq = input()
        if seq == 'ESC':
            break
コード例 #4
0
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import torch
import numpy as np
from tacotron2 import Tacotron2
from .args import DefaultArgument

batch_size = 3
seq_length = 3

inputs = torch.LongTensor(
    np.arange(batch_size * seq_length).reshape(batch_size, seq_length))
input_lengths = torch.LongTensor([3, 3, 2])
targets = torch.FloatTensor(batch_size, 100, 80).uniform_(-0.1, 0.1)

args = DefaultArgument()
model = Tacotron2(args)
output = model(inputs, targets, input_lengths)

print(model)
print(output)
コード例 #5
0
    args = parser.parse_args()

    if args.wandb:
        import wandb

        wandb.init(project='tacotron 2')

    import warnings

    warnings.simplefilter(action='ignore', category=FutureWarning)

    torch.backends.cudnn.deterministic = True

    device = 'cuda'
    model = Tacotron2(conf)
    dataset = TTSDataset('kss.lmdb')

    indices = list(range(len(dataset)))
    random.seed(17)
    random.shuffle(indices)
    train_ind = indices[200:]
    valid_ind = indices[:200]

    train_set = Subset(dataset, train_ind)
    valid_set = Subset(dataset, valid_ind)

    train_loader = DataLoader(train_set,
                              batch_size=64,
                              shuffle=True,
                              num_workers=4,
コード例 #6
0
        state, losses = optimize_step(sub_inputs, state, sub_target)
        state = to_np(state)

        for name, value in losses.items():
            total_loss.setdefault(name, 0.)
            total_loss[name] += value * tf.cast((end - start), tf.float32)

    total_loss = {
        k: v / tf.cast(n_frames, tf.float32)
        for k, v in total_loss.items()
    }

    return total_loss


model = Tacotron2(vocab_size=148)
loss_fn = TacotronLoss()
optimizer = tf.keras.optimizers.Adam()

batch_size = 64
length = 400

txt_inp = tf.ones((batch_size, 150), dtype=tf.int32)
mel_inp = tf.ones((batch_size, length, 80), dtype=tf.float32)
gate_inp = tf.ones((batch_size, length), dtype=tf.float32)

_ = model((txt_inp, mel_inp))

batch = ((txt_inp, mel_inp), (mel_inp, gate_inp))

loss = train_step(model, loss_fn, optimizer, batch)
コード例 #7
0
 def __init__(self):
     rospy.init_node("tacotron2")
     self.tacotron2 = Tacotron2()
     sub = rospy.Subscriber("/tacotron2/tts", String, self.callback)
     rospy.spin()