python语音合成 标贝_GitHub - jiev/Tacotron-2-Chinese: 中文语音合成,改自 https://github.com/Rayhane-mamah/Tacotron-...

该博客介绍了如何使用 Tacotron-2-Chinese 进行中文语音合成,包括预训练模型下载、依赖安装、数据预处理、模型训练、语音合成等步骤。特别地,该模型使用了标贝数据集,并通过ffmpeg将音频采样率降低到36KHz。
摘要由CSDN通过智能技术生成

Tacotron-2-Chinese 中文语音合成

预训练模型下载

仅 Tacotron 频谱预测部分,无 WaveNet 声码器(实验中),可用 Griffin-Lim 合成语音(见下)。

使用标贝数据集训练,为避免爆显存用了 ffmpeg 把语料的采样率从 48KHz 降到了 36KHz,听感基本无区别。

安装依赖

安装 Python 3 和 Tensorflow 1.10(在 Tensorflow 1.14 上用 WaveNet 会有Bug,在 1.10 上正常)。

安装依赖:

apt-get install -y libasound-dev portaudio19-dev libportaudio2 libportaudiocpp0 ffmpeg libav-tools

若 libav-tools 安装失败则手动安装:

wget http://launchpadlibrarian.net/339874908/libav-tools_3.3.4-2_all.deb

dpkg -i libav-tools_3.3.4-2_all.deb

安装 requirements:

pip install -r requirements.txt

训练模型

下载 标贝数据集,解压至 Tacotron-2-Chinese 文件夹根目录。目录结构如下:

Tacotron-2-Chinese

|- BZNSYP

|- PhoneLabeling

|- ProsodyLabeling

|- Wave

用 ffmpeg 把 /BZNSYP/Wave/ 中的 wav 的采样率降到36KHz:

ffmpeg.exe -i 输入.wav -ar 36000 输出.wav

预处理数据:

python preprocess.py --dataset='Biaobei'

训练模型(自动从最新 Checkpoint 继续):

python train.py --model='Tacotron-2'

合成语音

用根目录的 sentences.txt 中的文本合成语音。

python synthesize.py --model='Tacotron-2' --text_list='sentences.txt'

若无 WaveNet 模型,仅有频谱预测模型,则仅由 Griffin-Lim 生成语音,输出至 /tacotron_output/logs-eval/wavs/ 文件夹中。

若有 WaveNet 模型,则 WaveNet 生成的语音位于 /wavenet_output/wavs/ 中。

Tacotron-2:

Tensorflow implementation of DeepMind's Tacotron-2. A deep neural network architecture described in this paper: Natural TTS synthesis by conditioning Wavenet on MEL spectogram predictions

This Repository contains additional improvements and attempts over the paper, we thus propose paper_hparams.py file which holds the exact hyperparameters to reproduce the paper results without any additional extras.

Suggested hparams.py file which is default in use, contains the hyperparameters with extras that proved to provide better results in most cases. Feel free to toy with the parameters as needed.

DIFFERENCES WILL BE HIGHLIGHTED IN DOCUMENTATION SHORTLY.

Repository Structure:

Tacotron-2

├──

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我们可以使用 Gradio 来为 CasRel 模型设计一个简单的界面,让用户能够输入文本,然后获取实体关系抽取的结果。 首先,我们需要安装 Gradio: ``` !pip install gradio ``` 接下来,我们可以使用以下代码为 CasRel 模型创建一个简单的界面: ```python import gradio as gr import torch from torch.utils.data import DataLoader from typing import List from transformers import BertTokenizer from casrel import CasRel # 加载模型和 tokenizer tokenizer = BertTokenizer.from_pretrained("bert-base-chinese") model = CasRel.from_pretrained("casrel") # 定义预测函数 def predict(texts: List[str]) -> List[str]: # 对文本进行编码 encoded_texts = tokenizer.batch_encode_plus( texts, padding=True, truncation=True, max_length=128, return_tensors="pt" ) # 使用模型进行预测 with torch.no_grad(): outputs = model( input_ids=encoded_texts["input_ids"], attention_mask=encoded_texts["attention_mask"], token_type_ids=encoded_texts["token_type_ids"] ) # 将预测结果转换为标签 labels = model.convert_outputs_to_labels(outputs) # 返回标签 return labels # 创建 Gradio 的界面 iface = gr.Interface( fn=predict, inputs=gr.inputs.Textbox(lines=5, label="输入文本"), outputs=gr.outputs.Textbox(label="实体关系抽取结果") ) # 运行界面 iface.launch() ``` 这个代码会创建一个文本框,让用户输入文本,然后点击“提交”按钮,模型将对文本进行实体关系抽取,并将结果显示在另一个文本框中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值