Files
voiceScript/pc-voice/config.html
T

386 lines
15 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pc-voice 参数控制台</title>
<style>
:root {
--bg: #0f1115; --panel: #181c22; --panel2: #1f242c;
--text: #e8eaed; --muted: #9aa3af; --accent: #2dd4bf; --accent2: #f59e0b;
--border: #2a313b; --track: #2a313b;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
background: var(--bg); color: var(--text);
font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
padding: 24px; line-height: 1.6;
}
header { margin-bottom: 20px; }
h1 { font-size: 22px; font-weight: 700; }
h1 .tag { color: var(--accent); }
.sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.layout { display: grid; grid-template-columns: 1fr 380px; gap: 20px; align-items: start; }
@media (max-width: 960px) { .layout { grid-template-columns: 1fr; } }
.card {
background: var(--panel); border: 1px solid var(--border);
border-radius: 12px; padding: 18px 20px; margin-bottom: 16px;
}
.card h2 { font-size: 15px; margin-bottom: 12px; color: var(--accent); font-weight: 600; }
.card h2 small { color: var(--muted); font-weight: 400; font-size: 12px; }
.row { display: grid; grid-template-columns: 190px 1fr 92px; gap: 12px; align-items: center; padding: 7px 0; }
.row .name { font-size: 13px; }
.row .name .hint { display: block; color: var(--muted); font-size: 11px; }
.row .val { font-family: Consolas, monospace; font-size: 13px; color: var(--accent2); text-align: right; }
input[type=range] { width: 100%; accent-color: var(--accent); height: 22px; cursor: pointer; }
.switch { display: flex; align-items: center; gap: 10px; padding: 8px 0; cursor: pointer; user-select: none; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.presets { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.preset {
background: var(--panel2); border: 1px solid var(--border); border-radius: 10px;
padding: 12px; cursor: pointer; transition: border-color .15s;
}
.preset:hover { border-color: var(--accent); }
.preset .pname { font-size: 14px; font-weight: 600; margin-bottom: 8px; }
.preset .prow { display: flex; gap: 6px; align-items: center; font-size: 11px; color: var(--muted); margin-top: 4px; }
.preset input {
width: 62px; background: var(--bg); color: var(--text); border: 1px solid var(--border);
border-radius: 6px; padding: 3px 6px; font-family: Consolas, monospace; font-size: 12px;
}
.preset .apply { margin-top: 8px; font-size: 11px; color: var(--accent); }
pre#preview {
background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
padding: 12px; font-family: Consolas, monospace; font-size: 11px;
max-height: 320px; overflow: auto; white-space: pre-wrap; color: #b7c3d0;
}
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
button {
background: var(--accent); color: #04211d; border: 0; border-radius: 8px;
padding: 9px 16px; font-size: 13px; font-weight: 600; cursor: pointer;
}
button:hover { filter: brightness(1.1); }
button.ghost { background: var(--panel2); color: var(--text); border: 1px solid var(--border); }
.tip { color: var(--muted); font-size: 12px; margin-top: 10px; }
.tip code { background: var(--panel2); padding: 1px 6px; border-radius: 4px; color: var(--accent2); }
details { margin-top: 8px; }
summary { cursor: pointer; font-size: 13px; color: var(--accent); }
table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 12px; }
th, td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; }
th { background: var(--panel2); color: var(--muted); font-weight: 600; }
.ok { color: var(--accent); font-size: 12px; min-height: 18px; margin-top: 8px; }
</style>
</head>
<body>
<header>
<h1>pc-voice <span class="tag">参数控制台</span></h1>
<div class="sub">所有可配置项可视化调校 → 下载 voice_config.json 放到 pc-voice.exe 同目录 → 工具 2 秒内热生效(无需重启)</div>
</header>
<div class="layout">
<main>
<div class="card">
<h2>音色参数 <small>决定"像不像女声"</small></h2>
<div class="row">
<div class="name">音调<span class="hint">男变女约 +5~+12 半音(目标模式下失效)</span></div>
<input type="range" id="pitchSemitones" min="0" max="24" step="0.5">
<div class="val" id="pitchSemitones_v"></div>
</div>
<label class="switch">
<input type="checkbox" id="targetMode">
<span>目标音高模式(输出锚定下方 Hz,深沉嗓音自动多补,推荐)</span>
</label>
<div class="row">
<div class="name">目标音高<span class="hint">御姐≈205,少女≈240,萝莉≈280</span></div>
<input type="range" id="targetF0Hz" min="150" max="300" step="5">
<div class="val" id="targetF0Hz_v"></div>
</div>
<div class="row">
<div class="name">共振峰搬移<span class="hint">1.15~1.25 自然区间,防小黄人核心</span></div>
<input type="range" id="formantRatio" min="1" max="1.4" step="0.01">
<div class="val" id="formantRatio_v"></div>
</div>
<div class="row">
<div class="name">效果强度<span class="hint">整体效果按比例缩放</span></div>
<input type="range" id="strength" min="0" max="1" step="0.01">
<div class="val" id="strength_v"></div>
</div>
<div class="row">
<div class="name">输出增益<span class="hint">爆音就降,太小就升</span></div>
<input type="range" id="outputGain" min="0.1" max="2" step="0.05">
<div class="val" id="outputGain_v"></div>
</div>
</div>
<div class="card">
<h2>高级参数 <small>音质微调(不对劲时查下方速查表)</small></h2>
<div class="row">
<div class="name">亮度 EQ 频点</div>
<input type="range" id="eqFreqHz" min="500" max="8000" step="100">
<div class="val" id="eqFreqHz_v"></div>
</div>
<div class="row">
<div class="name">亮度 EQ 增益<span class="hint">女声"空气感"</span></div>
<input type="range" id="eqGainDb" min="0" max="10" step="0.5">
<div class="val" id="eqGainDb_v"></div>
</div>
<div class="row">
<div class="name">噪声门阈值<span class="hint">越低越灵敏,防切字</span></div>
<input type="range" id="gateThreshold" min="0" max="0.01" step="0.0005">
<div class="val" id="gateThreshold_v"></div>
</div>
<div class="row">
<div class="name">基频检测下限</div>
<input type="range" id="f0MinHz" min="40" max="200" step="5">
<div class="val" id="f0MinHz_v"></div>
</div>
<div class="row">
<div class="name">基频检测上限</div>
<input type="range" id="f0MaxHz" min="300" max="800" step="10">
<div class="val" id="f0MaxHz_v"></div>
</div>
<div class="row">
<div class="name">参数平滑<span class="hint">越小越平滑,防颤音</span></div>
<input type="range" id="smoothing" min="0.001" max="0.1" step="0.001">
<div class="val" id="smoothing_v"></div>
</div>
<label class="switch">
<input type="checkbox" id="bypass">
<span>旁路直通(干声 A/B 对比,同延迟)</span>
</label>
</div>
<div class="card">
<h2>症状速查表 <small>听感不对就查这里</small></h2>
<table>
<tr><th>症状</th><th>调什么</th></tr>
<tr><td>像小黄人 / 卡通音</td><td>↑ 共振峰搬移(1.20→1.25),别只加音调</td></tr>
<tr><td>还是男声 / 不够亮</td><td>↑ 音调(+9→+12)+ ↑ EQ 增益</td></tr>
<tr><td>电音 / 机械感</td><td>↓ 参数平滑(0.05→0.02);音调降到 +7</td></tr>
<tr><td>说话头尾被吞</td><td>↓ 噪声门阈值(0.006→0.003)</td></tr>
<tr><td>颤音 / 变调抖动</td><td>↓ 参数平滑(0.05→0.02)</td></tr>
<tr><td>变调飘忽不稳</td><td>收窄基频范围(如 80~350)</td></tr>
<tr><td>对方说太响 / 太轻</td><td>输出增益(0.1~2.0)</td></tr>
</table>
</div>
</main>
<aside>
<div class="card">
<h2>预设 <small>点卡片立即应用,数值可改</small></h2>
<div class="presets" id="presets"></div>
</div>
<div class="card">
<h2>voice_config.json</h2>
<pre id="preview"></pre>
<div class="btns">
<button onclick="downloadCfg()">⬇ 下载配置</button>
<button class="ghost" onclick="copyCfg()">复制 JSON</button>
<button class="ghost" onclick="document.getElementById('fileIn').click()">导入配置</button>
<button class="ghost" onclick="resetCfg()">恢复默认</button>
<input type="file" id="fileIn" accept=".json" style="display:none" onchange="importCfg(this)">
</div>
<div class="ok" id="okMsg"></div>
<div class="tip">
下载后把 <code>voice_config.json</code> 放到 <code>pc-voice.exe</code> 同目录(或 <code>--config</code> 指定路径),
工具每 2 秒检测文件变化自动生效——<b>改完保存即变声,不用重启</b>。<br><br>
预设对应运行中快捷键 <code>1/2/3/4</code>,这里改了数值,快捷键就是新值。
</div>
</div>
</aside>
</div>
<script>
const DEFAULTS = {
pitchSemitones: 9, formantRatio: 1.20, strength: 1,
eqFreqHz: 3000, eqGainDb: 3, gateThreshold: 0.006,
f0MinHz: 65, f0MaxHz: 500, smoothing: 0.05,
outputGain: 1, bypass: false,
targetMode: true, targetF0Hz: 205,
presets: [
{ name: "少女", pitchSemitones: 9, formantRatio: 1.20 },
{ name: "御姐", pitchSemitones: 7, formantRatio: 1.15 },
{ name: "萝莉", pitchSemitones: 12, formantRatio: 1.25 },
{ name: "中性女", pitchSemitones: 5, formantRatio: 1.12 },
],
};
let cfg = structuredClone(DEFAULTS);
const FMT = {
pitchSemitones: v => "+" + Number(v).toFixed(1) + " 半音",
formantRatio: v => "×" + Number(v).toFixed(2),
strength: v => Math.round(v * 100) + "%",
outputGain: v => "×" + Number(v).toFixed(2),
eqFreqHz: v => Number(v).toFixed(0) + " Hz",
eqGainDb: v => "+" + Number(v).toFixed(1) + " dB",
gateThreshold: v => Number(v).toFixed(4),
f0MinHz: v => Number(v).toFixed(0) + " Hz",
f0MaxHz: v => Number(v).toFixed(0) + " Hz",
smoothing: v => Number(v).toFixed(3),
targetF0Hz: v => Number(v).toFixed(0) + " Hz",
};
const SLIDER_KEYS = Object.keys(FMT);
function buildSliders() {
for (const k of SLIDER_KEYS) {
const el = document.getElementById(k);
el.value = cfg[k];
el.addEventListener("input", () => {
cfg[k] = parseFloat(el.value);
render();
});
}
document.getElementById("bypass").addEventListener("change", e => {
cfg.bypass = e.target.checked;
render();
});
document.getElementById("targetMode").addEventListener("change", e => {
cfg.targetMode = e.target.checked;
render();
});
}
function buildPresets() {
const wrap = document.getElementById("presets");
wrap.innerHTML = "";
cfg.presets.forEach((p, i) => {
const div = document.createElement("div");
div.className = "preset";
div.innerHTML = `
<div class="pname">${p.name}</div>
<div class="prow">音调 <input type="number" min="0" max="24" step="0.5" value="${p.pitchSemitones}" data-i="${i}" data-k="pitchSemitones"></div>
<div class="prow">共振峰 <input type="number" min="1" max="1.4" step="0.01" value="${p.formantRatio}" data-i="${i}" data-k="formantRatio"></div>
<div class="apply">▶ 点卡片应用此预设</div>`;
div.addEventListener("click", () => applyPreset(i));
div.querySelectorAll("input").forEach(inp => {
inp.addEventListener("click", e => e.stopPropagation());
inp.addEventListener("input", e => {
cfg.presets[i][e.target.dataset.k] = parseFloat(e.target.value) || 0;
render();
});
});
wrap.appendChild(div);
});
}
function applyPreset(i) {
const p = cfg.presets[i];
cfg.pitchSemitones = p.pitchSemitones;
cfg.formantRatio = p.formantRatio;
document.getElementById("pitchSemitones").value = cfg.pitchSemitones;
document.getElementById("formantRatio").value = cfg.formantRatio;
render();
msg("已应用预设:" + p.name);
}
function buildJson() {
return JSON.stringify({
params: {
pitchSemitones: cfg.pitchSemitones,
formantRatio: cfg.formantRatio,
strength: cfg.strength,
eqFreqHz: cfg.eqFreqHz,
eqGainDb: cfg.eqGainDb,
gateThreshold: cfg.gateThreshold,
f0MinHz: cfg.f0MinHz,
f0MaxHz: cfg.f0MaxHz,
smoothing: cfg.smoothing,
bypass: cfg.bypass,
outputGain: cfg.outputGain,
targetMode: cfg.targetMode,
targetF0Hz: cfg.targetF0Hz,
},
presets: cfg.presets.map(p => ({
name: p.name,
pitchSemitones: p.pitchSemitones,
formantRatio: p.formantRatio,
})),
version: 1,
}, null, 2);
}
function render() {
for (const k of SLIDER_KEYS) {
document.getElementById(k + "_v").textContent = FMT[k](cfg[k]);
document.getElementById(k).value = cfg[k];
}
document.getElementById("bypass").checked = cfg.bypass;
document.getElementById("targetMode").checked = cfg.targetMode;
document.getElementById("preview").textContent = buildJson();
}
function msg(t) {
const el = document.getElementById("okMsg");
el.textContent = t;
setTimeout(() => { if (el.textContent === t) el.textContent = ""; }, 3000);
}
function downloadCfg() {
const blob = new Blob([buildJson()], { type: "application/json" });
const a = document.createElement("a");
a.href = URL.createObjectURL(blob);
a.download = "voice_config.json";
a.click();
URL.revokeObjectURL(a.href);
msg("已下载 voice_config.json → 放到 pc-voice.exe 同目录");
}
function copyCfg() {
navigator.clipboard.writeText(buildJson()).then(() => msg("JSON 已复制到剪贴板"));
}
function importCfg(input) {
const f = input.files[0];
if (!f) return;
const reader = new FileReader();
reader.onload = () => {
try {
const j = JSON.parse(reader.result);
const p = j.params || {};
for (const k of SLIDER_KEYS) {
if (typeof p[k] === "number") cfg[k] = p[k];
}
if (typeof p.bypass === "boolean") cfg.bypass = p.bypass;
if (typeof p.targetMode === "boolean") cfg.targetMode = p.targetMode;
if (Array.isArray(j.presets)) {
j.presets.slice(0, 4).forEach((sp, i) => {
if (typeof sp.pitchSemitones === "number") cfg.presets[i].pitchSemitones = sp.pitchSemitones;
if (typeof sp.formantRatio === "number") cfg.presets[i].formantRatio = sp.formantRatio;
if (typeof sp.name === "string" && sp.name) cfg.presets[i].name = sp.name;
});
}
buildPresets();
render();
msg("配置已导入");
} catch (e) {
msg("导入失败:不是合法的 voice_config.json");
}
input.value = "";
};
reader.readAsText(f);
}
function resetCfg() {
cfg = structuredClone(DEFAULTS);
buildPresets();
render();
msg("已恢复默认参数");
}
buildSliders();
buildPresets();
render();
</script>
</body>
</html>