transformer_tts.py 2.0 KB
Newer Older
L
lifuchen 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# 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.
L
lifuchen 已提交
14 15
import paddle.fluid.dygraph as dg
import paddle.fluid as fluid
L
lifuchen 已提交
16 17
from parakeet.models.transformer_tts.encoder import Encoder
from parakeet.models.transformer_tts.decoder import Decoder
L
lifuchen 已提交
18

L
lifuchen 已提交
19

L
lifuchen 已提交
20 21 22
class TransformerTTS(dg.Layer):
    def __init__(self, config):
        super(TransformerTTS, self).__init__()
L
lifuchen 已提交
23 24
        self.encoder = Encoder(config['embedding_size'], config['hidden_size'])
        self.decoder = Decoder(config['hidden_size'], config)
L
lifuchen 已提交
25 26
        self.config = config

27 28 29 30 31 32 33 34 35 36 37 38 39
    def forward(self,
                characters,
                mel_input,
                pos_text,
                pos_mel,
                dec_slf_mask,
                enc_slf_mask=None,
                enc_query_mask=None,
                enc_dec_mask=None,
                dec_query_slf_mask=None,
                dec_query_mask=None):
        key, attns_enc = self.encoder(
            characters, pos_text, mask=enc_slf_mask, query_mask=enc_query_mask)
L
lifuchen 已提交
40

L
lifuchen 已提交
41
        mel_output, postnet_output, attn_probs, stop_preds, attns_dec = self.decoder(
42 43 44 45 46 47 48 49 50
            key,
            key,
            mel_input,
            pos_mel,
            mask=dec_slf_mask,
            zero_mask=enc_dec_mask,
            m_self_mask=dec_query_slf_mask,
            m_mask=dec_query_mask)
        return mel_output, postnet_output, attn_probs, stop_preds, attns_enc, attns_dec
L
lifuchen 已提交
51

L
lifuchen 已提交
52
        return mel_output, postnet_output, attn_probs, stop_preds, attns_enc, attns_dec