fastspeech2 conformer with hifigan
简介
核心亮点
- 非自回归架构,实现极速语音合成推理
- Conformer 增强语调自然度,告别机械音
- HiFi-GAN 声码器确保输出音频高保真
- 适配 ESPnet 生态,适合工业级 TTS 部署
使用方法
# 安装 Hugging Face transformers
pip install transformers torch
# 使用 transformers 加载模型
from transformers import AutoModel, AutoTokenizer
model = AutoModel.from_pretrained("espnet/fastspeech2_conformer_with_hifigan")
tokenizer = AutoTokenizer.from_pretrained("espnet/fastspeech2_conformer_with_hifigan")
Hugging Face 下载
我们推荐使用命令行或者 Hugging Face Hub SDK 来进行模型的下载。
操作指引:在下载前,请先通过如下命令安装 huggingface_hub:
pip install -U huggingface_hub
命令行下载
下载完整模型库
huggingface-cli download espnet/fastspeech2_conformer_with_hifigan
下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)
huggingface-cli download espnet/fastspeech2_conformer_with_hifigan config.json --local-dir ./dir
SDK 下载
# 模型下载
from huggingface_hub import snapshot_download
model_dir = snapshot_download('espnet/fastspeech2_conformer_with_hifigan')
Git 下载
请确保 lfs 已经被正确安装
git lfs install
git clone https://huggingface.co/espnet/fastspeech2_conformer_with_hifigan
如果您希望跳过 lfs 大文件下载,可以使用如下命令
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/espnet/fastspeech2_conformer_with_hifigan
模型文件托管在 Hugging Face Hub,使用 HF CLI / SDK / Git 直接下载,不经过本站。
PyTorch / Transformers 使用
安装 Transformers
pip install -U transformers torch
模型加载和推理
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained('espnet/fastspeech2_conformer_with_hifigan')
tokenizer = AutoTokenizer.from_pretrained('espnet/fastspeech2_conformer_with_hifigan')
完整文档
---
license: apache-2.0
language:
- en
library_name: transformers
---
FastSpeech2ConformerWithHifiGan
<!-- Provide a quick summary of what the model is/does. -->
This model combines FastSpeech2Conformer and FastSpeech2ConformerHifiGan into one model for a simpler and more convenient usage.
FastSpeech2Conformer is a non-autoregressive text-to-speech (TTS) model that combines the strengths of FastSpeech2 and the conformer architecture to generate high-quality speech from text quickly and efficiently, and the HiFi-GAN vocoder is used to turn generated mel-spectrograms into speech waveforms.
🤗 Transformers Usage
You can run FastSpeech2Conformer locally with the 🤗 Transformers library.
1. First install the 🤗 Transformers library and g2p-en:
pip install --upgrade pip
pip install --upgrade transformers g2p-en2. Run inference via the Transformers modelling code with the model and hifigan combined
from transformers import FastSpeech2ConformerTokenizer, FastSpeech2ConformerWithHifiGan
import soundfile as sf
tokenizer = FastSpeech2ConformerTokenizer.from_pretrained("espnet/fastspeech2_conformer")
inputs = tokenizer("Hello, my dog is cute.", return_tensors="pt")
input_ids = inputs["input_ids"]
model = FastSpeech2ConformerWithHifiGan.from_pretrained("espnet/fastspeech2_conformer_with_hifigan")
output_dict = model(input_ids, return_dict=True)
waveform = output_dict["waveform"]
sf.write("speech.wav", waveform.squeeze().detach().numpy(), samplerate=22050)