File size: 11,143 Bytes
7e9192a 24437ee 7e9192a 24437ee 7e9192a a2e2aa0 24437ee 8b86e7b a2e2aa0 24437ee a2e2aa0 24437ee a2e2aa0 24437ee a2e2aa0 24437ee a2e2aa0 24437ee a2e2aa0 24437ee a2e2aa0 24437ee a2e2aa0 24437ee a2e2aa0 24437ee a2e2aa0 24437ee a2e2aa0 24437ee a2e2aa0 24437ee a2e2aa0 24437ee a2e2aa0 24437ee a2e2aa0 8b86e7b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
"""
Genie TTS Hugging Face Spaces Deployment - Main Application
重构后的主应用文件,仅包含Gradio界面定义和应用启动逻辑
模块化重构后的架构:
- installer.py: 依赖管理
- config.py: 配置常量
- tts_engine.py: TTS核心功能
- ui_utils.py: UI辅助函数
- app.py: 主应用界面(当前文件)
"""
import gradio as gr
import logging
import warnings
from tts_engine import tts_interface
from ui_utils import clear_all, load_example, create_tts_wrapper, create_system_status_display
from config import APP_TITLE, APP_DESCRIPTION, EXAMPLE_TEXTS, UI_CONFIG, UI_TEXT, GRADIO_THEME
# 设置日志
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# 禁用一些警告
warnings.filterwarnings("ignore", category=FutureWarning)
warnings.filterwarnings("ignore", category=UserWarning)
# 创建UI函数
tts_wrapper = create_tts_wrapper(tts_interface)
get_system_status = create_system_status_display(tts_interface)
def create_interface():
"""创建Gradio界面"""
# 定义界面
with gr.Blocks(
title=APP_TITLE,
theme=gr.themes.Soft(),
css="""
.gradio-container {
max-width: 1200px !important;
}
.status-success {
color: #28a745 !important;
}
.status-error {
color: #dc3545 !important;
}
"""
) as demo:
gr.Markdown(f"""
# {APP_TITLE}
{APP_DESCRIPTION}
<div style="background: linear-gradient(90deg, #667eea 0%, #764ba2 100%); padding: 1rem; border-radius: 10px; color: white; margin: 1rem 0;">
<strong>🌟 功能特点</strong><br>
✅ CPU 优化推理,无需 GPU<br>
✅ 基于 GPT-SoVITS V2 技术<br>
✅ 支持长文本自动分句<br>
✅ 实时音频流输出
</div>
**📖 使用说明:** 选择角色模型 → 输入日语文本 → 点击合成按钮 → 获得高质量语音
""")
# 系统状态显示
system_status = get_system_status()
if "🔴" in system_status:
status_color = "#ff4444"
status_text = "服务不可用"
details = ("Hugging Face Spaces环境限制导致PyAudio依赖安装失败。<br>"
"💡 <strong>解决方案:</strong> 请在本地环境运行此应用以获得完整功能。")
else:
status_color = "#44ff44"
status_text = "服务正常"
details = "Genie TTS引擎已成功加载,可以正常使用。"
gr.Markdown(f"""
<div style="background: {status_color}20; border-left: 4px solid {status_color}; padding: 1rem; margin: 1rem 0; border-radius: 0 8px 8px 0;">
<strong>{system_status}</strong><br>
<small>{details}</small>
</div>
""")
with gr.Tab("🎵 语音合成") as tts_tab:
with gr.Row():
with gr.Column(scale=1):
# 角色选择
with gr.Group():
gr.Markdown("### 👤 角色设置")
character_dropdown = gr.Dropdown(
choices=tts_interface.available_characters,
value=tts_interface.available_characters[0],
label=UI_TEXT["character_label"],
info="当前可用的预训练角色模型",
interactive=True
)
# 文本输入
with gr.Group():
gr.Markdown("### 📝 文本输入")
text_input = gr.Textbox(
lines=5,
label=UI_TEXT["text_label"],
placeholder=UI_TEXT["text_placeholder"],
info="💡 支持日语文本,建议输入完整的句子以获得更好的效果",
show_copy_button=True
)
# 控制按钮
with gr.Row():
submit_btn = gr.Button(
UI_TEXT["submit_button"],
variant="primary",
size="lg",
scale=2
)
clear_btn = gr.Button(
UI_TEXT["clear_button"],
variant="secondary",
scale=1
)
with gr.Column(scale=1):
# 音频输出
with gr.Group():
gr.Markdown("### 🔊 音频输出")
audio_output = gr.Audio(
label=UI_TEXT["audio_label"],
type="filepath",
interactive=False,
show_download_button=True
)
# 状态显示
status_output = gr.Textbox(
label=UI_TEXT["status_label"],
interactive=False,
show_copy_button=False
)
# 示例和教程标签页
with gr.Tab("📚 示例与教程") as examples_tab:
gr.Markdown("### 🎯 快速示例")
gr.Markdown("点击下面的示例可以快速体验不同类型的文本合成效果:")
# 示例网格
with gr.Row():
with gr.Column():
gr.Markdown("**🌅 问候语**")
gr.Examples(
examples=EXAMPLE_TEXTS[:3],
inputs=[text_input, character_dropdown],
outputs=[text_input, character_dropdown, status_output],
fn=load_example,
run_on_click=True
)
with gr.Column():
gr.Markdown("**💭 情感表达**")
gr.Examples(
examples=[
["どうしようかな……やっぱりやりたいかも……!", "misono_mika"],
["うーん、これは難しいですね", "misono_mika"],
["わあ、すごいですね!", "misono_mika"]
],
inputs=[text_input, character_dropdown],
outputs=[text_input, character_dropdown, status_output],
fn=load_example,
run_on_click=True
)
with gr.Column():
gr.Markdown("**🎭 日常对话**")
gr.Examples(
examples=[
["ありがとうございます", "misono_mika"],
["さようなら、また明日", "misono_mika"],
["お先に失礼します", "misono_mika"]
],
inputs=[text_input, character_dropdown],
outputs=[text_input, character_dropdown, status_output],
fn=load_example,
run_on_click=True
)
gr.Markdown("""
### 📋 使用技巧
1. **文本长度**: 建议单次输入文本长度在 100 字以内,过长的文本会自动分句处理
2. **标点符号**: 适当使用标点符号(。!?)可以改善语音的自然度
3. **特殊符号**: 支持省略号(……)和感叹号(!)等情感表达
4. **处理时间**: 首次加载角色需要下载模型(约30秒),后续合成较快(5-10秒)
### 🔧 技术说明
- **模型架构**: 基于 Transformer 的端到端语音合成
- **采样率**: 32kHz,支持高质量音频输出
- **推理方式**: CPU 优化的 ONNX 模型,适合云端部署
- **内存占用**: 约 500MB RAM,支持并发处理
""")
# 关于标签页
with gr.Tab("ℹ️ 关于项目") as about_tab:
gr.Markdown("""
### 🔍 项目信息
**Genie TTS** 是基于 GPT-SoVITS V2 架构的轻量级语音合成引擎,专门为 CPU 推理优化。
#### 📊 技术规格
| 项目 | 规格 |
|------|------|
| **基础模型** | GPT-SoVITS V2 |
| **推理框架** | ONNX Runtime |
| **支持语言** | 日语 (Japanese) |
| **音频格式** | WAV, 32kHz |
| **推理设备** | CPU (无需 GPU) |
| **模型大小** | ~200MB |
| **内存需求** | ~500MB RAM |
#### 🔗 相关链接
- 🏠 [项目主页](https://github.com/High-Logic/Genie)
- 🤗 [Hugging Face 模型](https://huggingface.co/High-Logic/Genie)
- 📖 [GPT-SoVITS 官方](https://github.com/RVC-Boss/GPT-SoVITS)
- 💬 [问题反馈](https://github.com/High-Logic/Genie/issues)
#### 🙏 致谢
感谢以下项目和开发者:
- [High-Logic](https://github.com/High-Logic) 团队开发的 Genie TTS
- [RVC-Boss](https://github.com/RVC-Boss) 团队的 GPT-SoVITS 项目
- Hugging Face 提供的模型托管和 Spaces 平台
#### ⚖️ 免责声明
本应用仅用于演示和研究目的。请合理使用,生成的语音内容责任由使用者承担。
""")
# 绑定事件
submit_btn.click(
fn=tts_wrapper,
inputs=[text_input, character_dropdown],
outputs=[audio_output, status_output],
show_progress="full",
queue=True
)
clear_btn.click(
fn=clear_all,
outputs=[text_input, audio_output, status_output]
)
return demo
# 启动应用
if __name__ == "__main__":
demo = create_interface()
# 处理Gradio主题兼容性
launch_config = UI_CONFIG.copy()
try:
# 尝试使用主题参数(适用于较新版本的Gradio)
import gradio as gr
if hasattr(gr.Blocks, 'launch') and 'theme' in gr.Blocks.launch.__code__.co_varnames:
launch_config['theme'] = GRADIO_THEME
except:
# 如果出现错误,忽略主题设置
pass
demo.launch(**launch_config) |