GPT-SoVITS

model arch

VITS

  • S1 model: AR model–ssl tokens
  • S2 model: VITS,ssl 已经是mel 长度线性相关,MRTE(ssl_codes_embs, text, global_mel_emb)模块,将文本加强相关,学到一个参考结果

S1 Model

class Text2SemanticDecoder()
	def forward_old(self, x, x_lens, y, y_lens, bert_feature):
        """
        x: phoneme_ids
        y: semantic_ids
        bert_feature: 已经根据word2phn 扩展成和x等长
        train : y+EOS,已知长度;
        infer : AR 预测,预测EOS 终止;如果没有,到预设最大长度,终止;
        """
        # phn torch.Size([20, 99]) bert_feature torch.Size([20, 1024, 99])
        
        x = self.ar_text_embedding(x)
        x = x + self.bert_proj(bert_feature.transpose(1, 2))
        x = self.ar_text_position(x)
        x_mask = make_pad_mask(x_lens)

        y_mask = make_pad_mask(y_lens)
        y_mask_int = y_mask.type(torch.int64)
        codes = y.type(torch.int64) * (1 - y_mask_int)

        # Training
        # AR Decoder: SinePositionalEmbedding
        y, targets = self.pad_y_eos(codes, y_mask_int, eos_id=self.EOS)
        x_len = x_lens.max()
        y_len = y_lens.max()
        y_emb = self.ar_audio_embedding(y)
        y_pos = self.ar_audio_position(y_emb)

        xy_padding_mask = torch.concat([x_mask, y_mask], dim=1)
        ar_xy_padding_mask = xy_padding_mask

        x_attn_mask = F.pad(
            torch.zeros((x_len, x_len), dtype=torch.bool, device=x.device),
            (0, y_len),
            value=True,
        )
        y_attn_mask = F.pad(
            torch.triu(
                torch.ones(y_len, y_len, dtype=torch.bool, device=x.device),
                diagonal=1,
            ),
            (x_len, 0),
            value=False,
        )
        xy_attn_mask = torch.concat([x_attn_mask, y_attn_mask], dim=0)
        bsz, src_len = x.shape[0], x_len + y_len
        _xy_padding_mask = (
            ar_xy_padding_mask.view(bsz, 1, 1, src_len)
            .expand(-1, self.num_head, -1, -1)
            .reshape(bsz * self.num_head, 1, src_len)
        )
        xy_attn_mask = xy_attn_mask.logical_or(_xy_padding_mask)
        new_attn_mask = torch.zeros_like(xy_attn_mask, dtype=x.dtype)
        new_attn_mask.masked_fill_(xy_attn_mask, float("-inf"))
        xy_attn_mask = new_attn_mask
        # x 和完整的 y 一次性输入模型
        xy_pos = torch.concat([x, y_pos], dim=1)
        xy_dec, _ = self.h(
            (xy_pos, None),
            mask=xy_attn_mask,
        )
        logits = self.ar_predict_layer(xy_dec[:, x_len:]).permute(0, 2, 1)
        # loss
        # from feiteng: 每次 duration 越多, 梯度更新也应该更多, 所以用 sum
        loss = F.cross_entropy(logits, targets, reduction="sum")
        acc = self.ar_accuracy_metric(logits.detach(), targets).item()
        return loss, acc

S2 model

class Encoder()
    def forward(self, ssl, y_lengths, text, text_lengths, speed=1,test=None):
        '''
		y_lengths: mel_length
        ge : ref_encoder_outputs
        '''
        ge = self.ref_enc(y * y_mask, y_mask)
		ssl = self.ssl_proj(ssl)
            quantized, codes, commit_loss, quantized_list = self.quantizer(
                ssl, layers=[0]
            )

        if self.semantic_frame_rate == "25hz":
            quantized = F.interpolate(
                quantized, size=int(quantized.shape[-1] * 2), mode="nearest"
            )
     
        y = self.encoder_ssl(y * y_mask, y_mask)

        text_mask = torch.unsqueeze(
            commons.sequence_mask(text_lengths, text.size(1)), 1
        ).to(y.dtype)
        if test == 1:
            text[:, :] = 0
        text = self.text_embedding(text).transpose(1, 2)
        text = self.encoder_text(text * text_mask, text_mask)
        y = self.mrte(y, y_mask, text, text_mask, ge)
        # self.encoder_ssl, self.encoder_text, self.encoder2 结构一样
        y = self.encoder2(y * y_mask, y_mask)
        if(speed!=1):
            y = F.interpolate(y, size=int(y.shape[-1] / speed)+1, mode="linear")
            y_mask = F.interpolate(y_mask, size=y.shape[-1], mode="nearest")
        stats = self.proj(y) * y_mask
        m, logs = torch.split(stats, self.out_channels, dim=1)
        return y, m, logs, y_mask
### GPT-SOVITS 技术概述 GPT-SOVITS 是一种结合了生成预训练模型 (GPT) 和声码器 SOVITS 的技术框架,旨在提升语音合成的质量和效率。SOVITS 模型通过引入变分自编码器(VAE)来捕捉音频特征中的潜在变量分布,从而提高了音质的真实感[^2]。 ### 实现细节 #### 数据准备阶段 为了构建高质量的语音合成系统,数据准备至关重要。WebUI 工具提供了集成的功能模块,支持自动化处理流程: - **语音伴奏分离**:利用先进的信号处理算法将原始录音文件分为纯净的人声音轨和其他背景噪音部分。 - **自动训练集分割**:根据设定的标准对大量未标记的数据样本进行分类整理,形成适合机器学习使用的结构化集合。 - **中文 ASR 及文本标注**:提供针对汉语环境优化的文字转录服务以及人工辅助下的精细化标签编辑功能,确保每一段音频都有精确对应的书面表述。 ```bash # 使用 WebUI 工具安装命令示例 pip install webui-toolkit ``` #### 训练过程说明 在完成上述准备工作之后,可以开始着手于核心组件——即 GPTSOVITS 结合体本身的学习迭代工作当中去。具体来说就是先基于大规模语料库预先调整好语言理解层面上的能力;再借助精心挑选出来的多维度频谱片段作为输入源驱动声学建模环节向前推进直至收敛稳定为止。 ```python from transformers import AutoModelForCausalLM, AutoTokenizer tokenizer = AutoTokenizer.from_pretrained('gpt_model_path') model = AutoModelForCausalLM.from_pretrained('gpt_model_path') def generate_text(prompt): inputs = tokenizer(prompt, return_tensors="pt") outputs = model.generate(**inputs) result = tokenizer.decode(outputs[0], skip_special_tokens=True) return result ``` 对于想要深入了解并实际操作这套系统的开发者而言,除了掌握必要的编程技能之外,还需要注重培养良好的沟通技巧,在团队协作过程中能够清晰阐述自己的思路和技术方案,这对于项目的成功实施同样重要[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值