Skip to main content

DiffSinger UTAU inference toolkit with CLI

Project description

DiffSinger UTAU

DiffSinger UTAU 推理工具包,提供命令行工具和 Python API 进行语音合成。 基于 diffsinger 项目,兼容 OpenUtau 声库。

功能特性

  • 完整的 DiffSinger 推理流程:时长预测 → 音高预测 → 方差预测 → 声学模型 → 声码器
  • 支持多语言和多说话人
  • 提供命令行工具和 Python API
  • 支持音高移调、性别控制等参数调节

安装

由于历史原因,强依赖 PyTorch 1.13,因此建议使用 Python 3.8。

从 PyPI 安装

pip install diffsinger-utau

从源码安装

# 克隆仓库
git clone https://github.com/bingcheng1998/diffsinger_utau.git
cd diffsinger-utau

# 创建虚拟环境(推荐使用 Python 3.8)
conda create -n diffsinger python=3.8
conda activate diffsinger

# 安装依赖
pip install -e .

使用方法

下载声库

什么是声库?声库可以理解为歌唱者的模型,有着各自的音色等特性。

社区提供了DiffSinger自制声库分享,如果你不确定下载哪个,推荐从zhibin club下载姜柯JiangKe声库开始尝试。

下载声库后,需要解压,解压缩后的路径可以作为程序参数进行推理。

下载示例 ds 文件

什么是 ds 文件?ds 文件是修改后缀后的标准json文件,内容为歌曲的内容,包含歌词、音高等内容。

社区提供了示例文件,建议从示例文件推理开始尝试。

命令行工具

# 基本用法
dsutau diffsinger_utau/samples/07_春江花月夜.ds

# 指定语音库和参数
dsutau diffsinger_utau/samples/07_春江花月夜.ds \
  --voice-bank /Users/bc/Music/Singers/Junninghua_v1.4.0_DiffSinger_OpenUtau  \
  --lang zh \
  --speaker "jiangke" \
  --key-shift 2 \
  --pitch-steps 10 \
  --variance-steps 10 \
  --acoustic-steps 20 \
  --gender 0.0 \
  --output output/pred_all

Python API

from pathlib import Path
from diffsinger_utau.voice_bank import PredAll
from diffsinger_utau.voice_bank.commons.ds_reader import DSReader

# 初始化预测器
voice_bank = Path("artifacts/JiangKe_DiffSinger_CE_25.06")
predictor = PredAll(voice_bank)

# 读取 DS 文件
ds = DSReader("samples/07_春江花月夜.ds").read_ds()[0]

# 修改歌词
ds.replace("SP 可爱小狗汪汪叫 SP")

# 执行完整推理
results = predictor.predict_full_pipeline(
    ds=ds,
    lang="zh",
    speaker=None,  # 随机选择说话人
    key_shift=0,
    pitch_steps=10,
    variance_steps=10,
    acoustic_steps=50,
    gender=0.0,
    output_dir="output/pred_all",
    save_intermediate=True,
)

print(f"生成音频: {results['audio_path']}")

参数说明

  • --voice-bank: 语音库目录路径
  • --lang: 语言代码(默认: zh)
  • --speaker: 说话人名称(不指定则随机选择)
  • --key-shift: 音高移调半音数(默认: 0)
  • --pitch-steps: 音高扩散采样步数(默认: 10)
  • --variance-steps: 方差扩散采样步数(默认: 10)
  • --acoustic-steps: 声学模型扩散采样步数(默认: 50)
  • --gender: 性别参数 [-1, 1],-1为男性化,1为女性化(默认: 0)
  • --output: 输出目录(默认: output/pred_all)
  • --no-intermediate: 不保存中间结果文件

输出文件

推理完成后会在输出目录生成以下文件:

  • step1_duration.ds: 时长预测结果
  • step2_pitch.ds: 音高预测结果
  • step3_variance.ds: 方差预测结果
  • step4_mel_data.json: Mel数据(JSON格式)
  • step5_final_audio.wav: 最终音频文件
  • complete_prediction.ds: 完整预测结果

系统要求

  • Python 3.8
  • 支持的操作系统:Windows, macOS, Linux
  • 内存:建议 8GB 以上
  • 存储:至少 2GB 可用空间

依赖项

  • numpy>=1.21,<1.25
  • librosa>=0.9,<0.10
  • PyYAML>=6.0
  • onnxruntime>=1.12,<1.17
  • torch>=1.10,<2.0
  • pypinyin>=0.40
  • scipy>=1.7

开发

# 安装开发依赖
pip install -e ".[dev]"

# 运行测试
pytest

# 代码格式化
black voice_bank/

# 代码检查
flake8 voice_bank/

许可证

MIT License

贡献

欢迎提交 Issue 和 Pull Request!

更新日志

v0.1.2

v0.1.0

  • 初始版本
  • 支持完整的 DiffSinger 推理流程
  • 提供命令行工具和 Python API

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

diffsinger_utau-0.2.0.tar.gz (484.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

diffsinger_utau-0.2.0-py3-none-any.whl (504.5 kB view details)

Uploaded Python 3

File details

Details for the file diffsinger_utau-0.2.0.tar.gz.

File metadata

  • Download URL: diffsinger_utau-0.2.0.tar.gz
  • Upload date:
  • Size: 484.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for diffsinger_utau-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b99dc7b3911eadfb51a56b28af9d711b78b470f1a479813302d4a350122dfd13
MD5 8383e13ec1bdb701ccedcc6140193b6f
BLAKE2b-256 132d3bdefd9bdb21b35305f8c29ce8099cc0ef467d74249ec953209e5e2cbe1c

See more details on using hashes here.

File details

Details for the file diffsinger_utau-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for diffsinger_utau-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 78a332b75bf9887b51038f0449f73d62f926b86f8ed1c97ea475ca6a5d398cf3
MD5 0edc2e0640b7cae427bf28728adf7ded
BLAKE2b-256 9c6d1ea02e4232fe5d1803f6db6d9d39b9d404dfd0921569a969d6f0284e6743

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page