文档整理: - 重写 game/操作说明.md 为项目主文档(6游戏/6手势/旁白/模型生成音频/TTS两步流程) - 归档过时文档至 other_docs/(林夏原始设计、旧执行文档) - 新增 docs/音频制作执行手册.md(从零制作游戏音频的完整流程) - docs/ 下保留旁白音色提示词、音频脚本 代码清理: - 删除旧架构死代码: story.js / gestures.js / profile.js - 删除耦合旧架构的过时测试目录 game/tests/ 脚本配置修正: - check_tts_env.sh: 启动脚本路径 AutoVideo → tts-server(实际位置) - gen_narrator_samples.py: 硬编码地址改为环境变量,默认对齐 tts-server 端口 8000
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
// utils.js — 工具函数
|
|
|
|
const DEV = new URLSearchParams(location.search).has('dev');
|
|
const TEST = new URLSearchParams(location.search).has('test');
|
|
|
|
const sleep = ms => new Promise(r => setTimeout(r, ms));
|
|
|
|
function dbg(msg) {
|
|
const el = document.getElementById('dbg');
|
|
if (el && el.style.display !== 'none') el.textContent = msg;
|
|
}
|
|
|
|
// TTS — 仅用于朗读文字消息内容,不用于任何 UI 反馈
|
|
const TTS = {
|
|
_voices: [],
|
|
init() {
|
|
if (!window.speechSynthesis) return;
|
|
const load = () => { this._voices = speechSynthesis.getVoices(); };
|
|
load();
|
|
speechSynthesis.onvoiceschanged = load;
|
|
},
|
|
_pick() {
|
|
return this._voices.find(v => v.lang.startsWith('zh') || v.name.includes('Chinese'))
|
|
|| this._voices[0] || null;
|
|
},
|
|
get available() { return !!window.speechSynthesis; },
|
|
speak(text, { rate = 0.85, volume = 0.8 } = {}) {
|
|
return new Promise(resolve => {
|
|
if (!window.speechSynthesis) { resolve(false); return; }
|
|
speechSynthesis.cancel();
|
|
const u = new SpeechSynthesisUtterance(text);
|
|
u.lang = 'zh-CN'; u.rate = rate; u.volume = volume;
|
|
const v = this._pick();
|
|
if (v) u.voice = v;
|
|
u.onend = () => resolve(true);
|
|
u.onerror = () => resolve(false);
|
|
speechSynthesis.speak(u);
|
|
});
|
|
},
|
|
stop() { if (window.speechSynthesis) speechSynthesis.cancel(); },
|
|
};
|