From 263754d9c513d7ddebc5434b5fc304291da91045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E9=94=A6=E5=BC=BA?= <1061669148@qq.com> Date: Sun, 16 Mar 2025 20:37:54 +0800 Subject: [PATCH] feat: add empty style option and conditionally include style in HttpTTS link generation --- web/static/js/app.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/web/static/js/app.js b/web/static/js/app.js index faa225d..af1868d 100644 --- a/web/static/js/app.js +++ b/web/static/js/app.js @@ -159,6 +159,12 @@ document.addEventListener('DOMContentLoaded', function () { return; } + // 添加清空选项 + const emptyOption = document.createElement('option'); + emptyOption.value = ""; + emptyOption.textContent = "-- 无风格 --"; + styleSelect.appendChild(emptyOption); + // 添加可用风格选项 voiceData.style_list.forEach(style => { const option = document.createElement('option'); @@ -211,7 +217,12 @@ document.addEventListener('DOMContentLoaded', function () { const apiKey = apiKeyInput.value.trim(); // 构建HttpTTS链接 - let httpTtsLink = `${window.location.origin}${config.basePath}/tts?t=${text}&v=${voice}&r=${rate}&p=${pitch}&s=${style}`; + let httpTtsLink = `${window.location.origin}${config.basePath}/tts?t=${text}&v=${voice}&r=${rate}&p=${pitch}`; + + // 只有当style不为空时才添加 + if (style) { + httpTtsLink += `&s=${style}`; + } // 添加API Key参数(如果有) if (apiKey) { @@ -292,11 +303,15 @@ document.addEventListener('DOMContentLoaded', function () { const params = new URLSearchParams({ t: text, v: voice, - s: style, r: rate, p: pitch }); + // 只有当style不为空时才添加 + if (style) { + params.append('s', style); + } + // 添加API Key参数(如果有) if (apiKey) { params.append('api_key', apiKey);