Skip to main content

Text-to-Speech module for Illufly

Project description

Illufly TTS

高质量多语言文本转语音(TTS)系统

特性

  • 支持中文、英文和中英混合文本
  • 基于Kokoro模型的高质量语音合成
  • 模块化设计,易于扩展
  • 支持多种语音和音色
  • 提供完整的命令行工具

架构

系统由以下模块组成:

  1. 文本预处理模块

    • 语言分段器: 检测和分离混合文本中的不同语言
    • 文本规范化器: 处理数字、标点符号等
  2. G2P模块

    • 英文G2P: 将英文文本转换为音素
    • 中文G2P: 将中文文本转换为拼音和音素
    • 混合G2P: 处理混合语言文本
  3. 音频生成模块

    • Kokoro适配器: 连接自定义处理与Kokoro模型
    • 语音资源管理: 管理多种语音和音色
  4. 集成流水线

    • 标准流水线: 基本的TTS流程
    • 混合语言流水线: 专为混合语言文本优化

自定义词典

系统支持通过自定义词典来控制特定词汇的发音,这对于专有名词、行业术语或多音字特别有用。

词典位置

词典文件位于 src/illufly_tts/resources/dictionaries/ 目录:

  • chinese_dict.txt - 中文词汇的音素映射
  • english_dict.txt - 英文词汇的音素映射

词典格式

词典采用简单的文本格式,每行一个词条:

# 中文格式:词汇 音素1 音素2 ...
人工智能 r en2 g ong1 zh iii4 n eng2

# 英文格式:词汇 音素1 音素2 ...
AI ey ay

扩展词典

您可以通过以下方式扩展词典:

  1. 直接编辑现有词典文件
  2. 在代码中指定自定义词典路径:
from illufly_tts.g2p.mixed_g2p import MixedG2P

# 使用自定义词典
g2p = MixedG2P(dictionary_path="path/to/your/custom_dict.txt")

优先级

当词汇在词典中找到匹配项时,系统会优先使用词典中的发音,而不使用自动推导的发音。这允许您为任何生成不正确发音的词汇提供更精确的控制。

安装

环境要求

  • Python 3.8+
  • PyTorch 1.10+
  • CUDA (推荐,但非必须)

安装步骤

# 克隆仓库
git clone https://github.com/illufly/illufly-tts.git
cd illufly-tts

# 安装依赖
pip install -e .

# 开发环境安装
pip install -e ".[dev]"

使用方法

命令行工具

# 单句合成
illufly-tts --text "今天天气真好!" --model-path /path/to/model --voices-dir /path/to/voices --voice-id z001 --output output.wav

# 从文件读取
illufly-tts --file input.txt --model-path /path/to/model --voices-dir /path/to/voices --output output.wav

# 列出可用语音
illufly-tts --model-path /path/to/model --voices-dir /path/to/voices --list-voices

# 使用混合语言模式
illufly-tts --text "你好,Hello World!" --model-path /path/to/model --voices-dir /path/to/voices --mixed-language

编程接口

from illufly_tts import MixedLanguagePipeline

# 创建流水线
tts = MixedLanguagePipeline(
    model_path="/path/to/model",
    voices_dir="/path/to/voices"
)

# 生成语音
audio = tts.text_to_speech(
    text="今天天气真好!Hello World!",
    voice_id="z001",
    output_path="output.wav"
)

测试

单元测试

# 运行单元测试
pytest

# 运行覆盖率测试
pytest --cov=illufly_tts

集成测试

我们提供了一系列集成测试脚本,用于分步验证TTS系统的各个组件功能:

  1. 分步测试 - 逐步验证各模块效果:
# 运行所有测试
python tests/integration/test_processing_steps.py -m /path/to/model -v /path/to/voices

# 测试特定阶段
python tests/integration/test_processing_steps.py --stage segmenter -t "你好,测试文本。Hello, test text."
python tests/integration/test_processing_steps.py --stage normalizer -t "数字123转换测试"
python tests/integration/test_processing_steps.py --stage g2p -t "G2P测试文本"
python tests/integration/test_processing_steps.py --stage vocoder -m /path/to/model -v /path/to/voices
python tests/integration/test_processing_steps.py --stage pipeline -m /path/to/model -v /path/to/voices

# 详细日志
python tests/integration/test_processing_steps.py -m /path/to/model -v /path/to/voices --verbose
  1. 对比测试 - 比较官方与自定义实现:
# 运行所有对比测试
python tests/integration/test_comparison.py -m /path/to/model -v /path/to/voices

# 只比较文本规范化
python tests/integration/test_comparison.py --mode normalization -t "规范化对比测试123"

# 只比较流水线
python tests/integration/test_comparison.py --mode pipeline -m /path/to/model -v /path/to/voices
  1. 独立实现测试 - 测试完全独立的实现:
# 基本测试
python tests/integration/test_independent_pipeline.py -m /path/to/model -v /path/to/voices

# 分段处理
python tests/integration/test_independent_pipeline.py -m /path/to/model -v /path/to/voices --segmented

# 生成后播放
python tests/integration/test_independent_pipeline.py -m /path/to/model -v /path/to/voices --play

# 指定语音ID和语速
python tests/integration/test_independent_pipeline.py -m /path/to/model -v /path/to/voices --voice-id z001 --speed 1.2

所有测试脚本都会生成详细的日志和结果文件,方便排查问题和优化实现。

许可证

MIT

致谢

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

illufly_tts-0.1.2.tar.gz (3.1 MB view details)

Uploaded Source

Built Distribution

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

illufly_tts-0.1.2-py3-none-any.whl (3.1 MB view details)

Uploaded Python 3

File details

Details for the file illufly_tts-0.1.2.tar.gz.

File metadata

  • Download URL: illufly_tts-0.1.2.tar.gz
  • Upload date:
  • Size: 3.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.0 Darwin/24.3.0

File hashes

Hashes for illufly_tts-0.1.2.tar.gz
Algorithm Hash digest
SHA256 9a1707bb483110bf8f3a4c179ec3efbdbadb17689bccc905f8aca4436fb5076f
MD5 aad3db466c8ba4d6babde1d2267c675f
BLAKE2b-256 243411a9e1099f44ee2b2aa843afa4393e705d11e76bec37c2b29446d962cee0

See more details on using hashes here.

File details

Details for the file illufly_tts-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: illufly_tts-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.0 Darwin/24.3.0

File hashes

Hashes for illufly_tts-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e9c20315fe08e84e10739619f62ce0f8f1b62d55902c82b7ce57a5f388f84b75
MD5 3b27a1dc34c20fd606af801ec8c213aa
BLAKE2b-256 a6c04fe8c3503d573d29700180a554091a94d33ce2986c09f48ad7e6aea27e42

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