fix duration TTS tool - combines intelligent TTS with LLM
Project description
SOGA TTS - 固定时长语音合成
生成指定时长的语音文件,支持智能文本优化和精确时长控制。
安装
pip install soga_tts
基本使用
命令行(最简单)
soga_tts "Hello world" --duration 5.0 # 生成5秒语音,默认使用本地ollma的gemma3:4b模型,请事先安装
soga_tts "Hello world" --duration 5.0 --no-llm # 不使用LLM,直接生成语音,通过强制拉伸的方式来控制时长
Python API
from soga_tts import soga_tts
# 最简单的用法
text, audio_path, duration = soga_tts("Hello world", 5.0)
print(f"音频文件: {audio_path}")
高级用法
异常处理
from soga_tts import soga_tts
from soga_tts.fixed_duration_tts import TTSPrecisionError
try:
text, audio_path, duration = soga_tts("Hello", 10.0, tolerance_pct=5.0)
except TTSPrecisionError as e:
print(f"精度不够: {e.error_pct:.1f}% (要求: 5.0%)")
from soga_tts import soga_tts
from soga_tts.fixed_duration_tts import TTSPrecisionError
try:
text, audio_path, duration = soga_tts("Hello", 10.0, tolerance_pct=5.0)
except TTSPrecisionError as e:
print(f"精度不够: {e.error_pct:.1f}% (要求: 5.0%)")
自定义LLM服务
# 使用OpenAI
soga_tts "Hello" --duration 5.0 \
--llm-url "https://api.openai.com/v1" \
--llm-key "your-key" \
--llm-model "gpt-3.5-turbo"
# 使用Ollama(默认)
soga_tts "Hello" --duration 5.0
参数调整
soga_tts(
text="Hello world",
target_duration=10.0,
tolerance_pct=3.0, # 误差容忍度
max_rounds=5, # 最大优化回合
force_exact_duration=True # 音频缩放
)
常见问题
1. Ollama连接失败
# 启动Ollama服务
ollama serve
# 检查服务状态
curl http://localhost:11434/api/tags
2. 精度不够怎么办?
- 使用更宽松的容差:
--tolerance 10.0 - 增加优化回合数:
--max-rounds 20 - 启用音频缩放(默认开启)
3. 速度太慢?
- 使用
--no-llm跳过文本优化 - 减少回合数:
--max-rounds 3 - 使用本地Ollama而不是远程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
soga_tts-0.1.1.tar.gz
(15.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
soga_tts-0.1.1-py3-none-any.whl
(10.0 kB
view details)
File details
Details for the file soga_tts-0.1.1.tar.gz.
File metadata
- Download URL: soga_tts-0.1.1.tar.gz
- Upload date:
- Size: 15.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cc953f57c624e7993ef0c6221b1ea45933afe37778fbdeefb66fea42cf16338
|
|
| MD5 |
51d4ea7f0a17d21a63fcf70f32638f97
|
|
| BLAKE2b-256 |
0ae71e771d4d8e856e21174dd167289f4ab264897b2af3ae31dfe269b49a5c51
|
File details
Details for the file soga_tts-0.1.1-py3-none-any.whl.
File metadata
- Download URL: soga_tts-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c77991b6440be4c65379bd2f9bb45e8475bdd059e918b830bda7b2d3919f3596
|
|
| MD5 |
22de0b349d473c838da59255ed71bfb9
|
|
| BLAKE2b-256 |
32cdca0bf578525c65b94a43addee76db90a91b61ae64e1f19289363f4339b8d
|