diff --git a/components.d.ts b/components.d.ts index 41477bc..1d0ac5d 100644 --- a/components.d.ts +++ b/components.d.ts @@ -210,6 +210,7 @@ declare module '@vue/runtime-core' { RouterView: typeof import('vue-router')['RouterView'] RsaKeyPairGenerator: typeof import('./src/tools/rsa-key-pair-generator/rsa-key-pair-generator.vue')['default'] SafelinkDecoder: typeof import('./src/tools/safelink-decoder/safelink-decoder.vue')['default'] + SealMaker: typeof import('./src/tools/seal-maker/seal-maker.vue')['default'] SiteBookmarks: typeof import('./src/tools/site-bookmarks/site-bookmarks.vue')['default'] SlugifyString: typeof import('./src/tools/slugify-string/slugify-string.vue')['default'] SpanCopyable: typeof import('./src/components/SpanCopyable.vue')['default'] diff --git a/docker/it-tools-relay/server.py b/docker/it-tools-relay/server.py index 3f4bc61..87ed224 100644 --- a/docker/it-tools-relay/server.py +++ b/docker/it-tools-relay/server.py @@ -44,7 +44,7 @@ AUTH_PASS = os.environ.get("AUTH_PASS", "") PROJECT_NAME = os.environ.get("PROJECT_NAME", "IT-Tools") TRIAL_FILE = os.environ.get("TRIAL_FILE", "/app/data/trials.json") TRIAL_MS = int(os.environ.get("TRIAL_MS_MIN", "30")) * 60 * 1000 -PROTECTED_TOOLS = {"translator", "image-ocr", "pdf-ocr", "ai-retouch", "label-designer", "doc-convert", "image-tools", "pdf-tools", "video-tools", "audio-tools"} +PROTECTED_TOOLS = {"translator", "image-ocr", "pdf-ocr", "ai-retouch", "label-designer", "doc-convert", "image-tools", "pdf-tools", "video-tools", "audio-tools", "seal-maker"} MACHINE_RE = re.compile(r"^\d{10,16}$") # verify() messages that unconditionally block activation @@ -1469,6 +1469,76 @@ class Handler(BaseHTTPRequestHandler): except Exception as e: # noqa: BLE001 self._reply(500, json.dumps({"code": 500, "message": "合成失败: " + str(e)[:200]}, ensure_ascii=False).encode("utf-8"), "application/json") + def _handle_clone(self): + import audio_ops + import uuid as _uuid + parsed = parse.urlparse(self.path) + machine = self.headers.get("X-Machine-Id", "") + status = check(machine, "audio-tools") + if status != 200: + self._reply(403, json.dumps({"code": 403, "message": "需要授权或免费试用已结束"}, ensure_ascii=False).encode("utf-8"), "application/json") + return + + if parsed.path == "/clone/prepare": + # multipart: reference audio -> stored for the voice-clone pipeline + try: + ctype = self.headers.get("Content-Type", "") + length = int(self.headers.get("Content-Length") or 0) + if length > 35 * 1024 * 1024: + self._reply(413, json.dumps({"code": 413, "message": "参考音频过大"}, ensure_ascii=False).encode(), "application/json") + return + raw = self.rfile.read(length) if length else b"" + env = {"REQUEST_METHOD": "POST", "CONTENT_TYPE": ctype, "CONTENT_LENGTH": str(length)} + fs = cgi.FieldStorage(fp=io.BytesIO(raw), environ=env, keep_blank_values=True) + fobj = fs["file"] if ("file" in fs.keys()) else None + if fobj is None or not fobj.filename: + self._reply(400, json.dumps({"code": 400, "message": "缺少参考音频文件"}, ensure_ascii=False).encode(), "application/json") + return + ref = audio_ops.clone_prepare(fobj.file.read(), os.path.basename(fobj.filename)) + log_usage(machine, "audio-tools-clone") + body = {"code": 200, "message": "ok", "data": {"ref_file": ref}} + self._reply(200, json.dumps(body, ensure_ascii=False).encode("utf-8"), "application/json") + except ValueError as e: + self._reply(400, json.dumps({"code": 400, "message": str(e)}, ensure_ascii=False).encode("utf-8"), "application/json") + except Exception as e: # noqa: BLE001 + self._reply(500, json.dumps({"code": 500, "message": "上传失败: " + str(e)[:200]}, ensure_ascii=False).encode("utf-8"), "application/json") + return + + if parsed.path == "/clone/tts": + try: + length = int(self.headers.get("Content-Length") or 0) + raw = self.rfile.read(length) if length else b"{}" + pl = json.loads(raw.decode("utf-8") or "{}") + out_path = "/tmp/clone-" + _uuid.uuid4().hex[:10] + ".wav" + try: + audio_ops.clone_tts( + str(pl.get("ref_file") or ""), + str(pl.get("prompt_text") or ""), + str(pl.get("text") or ""), + str(pl.get("text_lang") or "zh"), + str(pl.get("prompt_lang") or "zh"), + out_path, + ) + with open(out_path, "rb") as f: + out = f.read() + finally: + try: + os.remove(out_path) + except Exception: + pass + self.send_response(200) + self.send_header("Content-Type", "audio/wav") + self.send_header("Content-Length", str(len(out))) + self.end_headers() + self.wfile.write(out) + except ValueError as e: + self._reply(400, json.dumps({"code": 400, "message": str(e)}, ensure_ascii=False).encode("utf-8"), "application/json") + except Exception as e: # noqa: BLE001 + self._reply(500, json.dumps({"code": 500, "message": "克隆合成失败: " + str(e)[:200]}, ensure_ascii=False).encode("utf-8"), "application/json") + return + + self._reply(404, b"not found") + def _handle_asr(self): import audio_ops import uuid as _uuid @@ -1533,6 +1603,9 @@ class Handler(BaseHTTPRequestHandler): if parsed.path == "/asr": self._handle_asr() return + if parsed.path.startswith("/clone"): + self._handle_clone() + return if parsed.path == "/video": self._handle_video() return diff --git a/locales/en.yml b/locales/en.yml index 426eec3..4470765 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -275,6 +275,9 @@ tools: title: Image OCR description: Extract text from images with OCR - click, drag & drop or paste a screenshot, get recognized lines with confidence scores, copy or download as TXT. + seal-maker: + title: 'Seal maker' + description: 'Generate official seals and stamp them onto images and PDFs (cross-page seal), all local in browser' audio-tools: title: 'Audio tools' description: 'Text to speech, speech to text, voice clone - AI audio toolkit' diff --git a/locales/zh.yml b/locales/zh.yml index 5b2034a..fef7ecf 100644 --- a/locales/zh.yml +++ b/locales/zh.yml @@ -272,6 +272,9 @@ tools: title: 图片OCR文字识别 description: 上传、拖拽或粘贴截图识别图片中的文字,逐行输出识别结果和置信度,支持复制全部和下载TXT。 + seal-maker: + title: '印章生成器' + description: '生成圆形公章/专用章(弧形文字+五角星),一键盖章到图片与 PDF(骑缝章/角章),全程浏览器本地处理' audio-tools: title: '音频工具' description: '文字转音频(14 种音色)、音频转文字(中英日粤自动检测)、声音克隆等 AI 语音工具' diff --git a/src/layouts/tool.layout.vue b/src/layouts/tool.layout.vue index 1dae17d..93b3159 100644 --- a/src/layouts/tool.layout.vue +++ b/src/layouts/tool.layout.vue @@ -40,7 +40,7 @@ useHead(head); const { t } = useI18n(); // 宽屏工具:不受 600px 限宽,占满可用宽度(画布/多栏类工具) -const WIDE_TOOLS = new Set(['/label-designer', '/json-prettify', '/pdf-tools', '/image-tools', '/doc-convert', '/video-tools']); +const WIDE_TOOLS = new Set(['/label-designer', '/json-prettify', '/pdf-tools', '/image-tools', '/doc-convert', '/video-tools', '/seal-maker']); const isWide = computed(() => WIDE_TOOLS.has(route.path)); const i18nKey = computed(() => route.path.trim().replace('/', '')); diff --git a/src/tools/audio-tools/audio-tools.vue b/src/tools/audio-tools/audio-tools.vue index bcf1425..aa62d12 100644 --- a/src/tools/audio-tools/audio-tools.vue +++ b/src/tools/audio-tools/audio-tools.vue @@ -143,6 +143,111 @@ async function copyAsr() { catch { /* ignore */ } } +// ============ 声音克隆 (voice clone) ============ +const clRef = ref(null); +const clRefInput = ref(); +const clRefFile = ref(''); // ref_file id from server +const clPrompt = ref(''); +const clText = ref(''); +const clLang = ref('zh'); +const clBusy = ref(false); +const clUploading = ref(false); +const clError = ref(''); +const clResultUrl = ref(''); +const clResultSize = ref(0); +const clSpent = ref(0); + +function pickClRef() { + clRefInput.value?.click(); +} + +function onClRef(e: Event) { + const input = e.target as HTMLInputElement; + clRef.value = input.files?.[0] ?? null; + input.value = ''; + clRefFile.value = ''; + clError.value = ''; +} + +function onClDrop(e: DragEvent) { + clRef.value = e.dataTransfer?.files?.[0] ?? null; + clRefFile.value = ''; + clError.value = ''; +} + +async function uploadClRef() { + if (!clRef.value) { + clError.value = '请先选择参考音频'; + return; + } + clUploading.value = true; + clError.value = ''; + try { + const fd = new FormData(); + fd.append('file', clRef.value); + const res = await fetch('/relay/clone/prepare', { method: 'POST', body: fd, headers: licenseHeaders() }); + const b = await res.json().catch(() => ({})); + if (!res.ok) { + throw new Error(b.message || `上传失败(${res.status})`); + } + clRefFile.value = b.data.ref_file; + } + catch (e: any) { + clError.value = String(e?.message || e); + } + finally { + clUploading.value = false; + } +} + +async function runClone() { + if (!clRefFile.value) { + clError.value = '请先上传参考音频'; + return; + } + clBusy.value = true; + clError.value = ''; + const t0 = Date.now(); + try { + const res = await fetch('/relay/clone/tts', { + method: 'POST', + headers: { 'Content-Type': 'application/json', ...licenseHeaders() }, + body: JSON.stringify({ + ref_file: clRefFile.value, + prompt_text: clPrompt.value, + text: clText.value, + text_lang: clLang.value, + prompt_lang: clLang.value, + }), + }); + if (!res.ok) { + const b = await res.json().catch(() => ({})); + throw new Error(b.message || `合成失败(${res.status})`); + } + const blob = await res.blob(); + if (clResultUrl.value) { + URL.revokeObjectURL(clResultUrl.value); + } + clResultUrl.value = URL.createObjectURL(blob); + clResultSize.value = blob.size; + clSpent.value = Math.round((Date.now() - t0) / 1000); + genHist.add({ title: `声音克隆: ${clText.value.slice(0, 24)}`, detail: `${(blob.size / 1024).toFixed(0)}KB(${clSpent.value}s)` }); + } + catch (e: any) { + clError.value = String(e?.message || e); + } + finally { + clBusy.value = false; + } +} + +function downloadClone() { + const a = document.createElement('a'); + a.href = clResultUrl.value; + a.download = '克隆语音.wav'; + a.click(); +} + // ============ tabs ============ type TabId = 'tts' | 'asr' | 'clone'; const tab = ref('tts'); @@ -268,17 +373,60 @@ const tabDesc = computed(() => TABS.find(t => t.id === tab.value)?.desc ?? '');
🎭 声音克隆 {{ tabDesc }}
-
-
🔧
-
声音克隆功能部署中,即将上线
-
- 基于 GPT-SoVITS 本地大模型:上传 5-10 秒参考音频即可克隆音色,让 AI 用你的声音朗读任意文本。 - 模型部署完成后本页面自动开放,无需更新站点。 + + +
+
① 上传参考音频(5-10 秒清晰人声,本地 GPT-SoVITS 模型克隆音色)
+
+ + +
+ 🎙️ {{ clRef.name }} ({{ (clRef.size / 1024 / 1024).toFixed(1) }} MB) + ✕ +
-
-
✓ 支持中文零样本克隆(5 秒样本)
-
✓ 克隆音色可保存复用
-
✓ 本地模型推理,参考音频不外传
+ +
+ + +
+
② 填写参考音频里说的话(提升克隆相似度的关键)
+