66 lines
2.2 KiB
Python
66 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
简化的Fish Speech语音生成脚本
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
def generate_speech(text, reference_audio, output_file, reference_text="登鹳雀楼,白日依山尽,黄河入海流。欲穷千里目,更上一层楼。"):
|
|
"""使用Fish Speech生成语音"""
|
|
|
|
print("🎤 准备生成语音...")
|
|
print(f"📝 文本: {text}")
|
|
print(f"🎵 参考音频: {reference_audio}")
|
|
|
|
# 检查文件是否存在
|
|
if not Path(reference_audio).exists():
|
|
print(f"❌ 参考音频不存在: {reference_audio}")
|
|
return False
|
|
|
|
# 使用Fish Speech命令行工具
|
|
fish_speech_dir = Path("/root/tts/fish-speech")
|
|
|
|
# 构建命令
|
|
cmd = [
|
|
sys.executable, "-m", "fish_speech.convers",
|
|
"--text", text,
|
|
"--reference_audio", reference_audio,
|
|
"--reference_text", reference_text,
|
|
"--output", output_file,
|
|
"--llama-checkpoint-path", str(fish_speech_dir / "checkpoints/fish-speech-1.5/model.pth"),
|
|
"--decoder-checkpoint-path", str(fish_speech_dir / "checkpoints/fish-speech-1.5/firefly-gan-vq-fsq-8x1024-21hz-generator.pth"),
|
|
"--device", "cpu"
|
|
]
|
|
|
|
print("🚀 开始生成...")
|
|
try:
|
|
result = subprocess.run(cmd, cwd=str(fish_speech_dir), capture_output=True, text=True, timeout=300)
|
|
|
|
if result.returncode == 0:
|
|
print(f"✅ 生成成功: {output_file}")
|
|
return True
|
|
else:
|
|
print(f"❌ 生成失败: {result.stderr}")
|
|
return False
|
|
|
|
except subprocess.TimeoutExpired:
|
|
print("❌ 生成超时")
|
|
return False
|
|
except Exception as e:
|
|
print(f"❌ 生成错误: {e}")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
# 测试生成
|
|
test_text = "海内存知己,天涯若比邻。"
|
|
reference_audio = "/root/tts/ben_guanquelou.wav"
|
|
output_file = "/root/tts/audio/output/huaineizhiji_test.wav"
|
|
|
|
success = generate_speech(test_text, reference_audio, output_file)
|
|
if success:
|
|
print("🎉 语音生成完成!")
|
|
else:
|
|
print("💔 语音生成失败!") |