feat: 音频工具 — Piper本地TTS(中英语音+语速调节) + Whisper音频转文字(中英日粤+时间轴) + 声音克隆占位; 服务端全本地模型

This commit is contained in:
personal82555 committed 2026-10-12 11:52:53 +08:00
1 parent 6bc2120c05
commit 54fba4d97a
11 files changed
+831 -2

No files matched your search

+1
View File
@@ -23,6 +23,7 @@ const groups: { title: string; items: Item[] }[] = [
{ name: 'IT网站收藏', icon: '藏', desc: '内置 91 个精选开发站点(社区/文档/工具/AI/设计/视频/媒体平台),数据存用户本地,可自选目录', tag: '全新' },
{ name: '文档格式转换', icon: '转', desc: 'Word/PDF/TXT/RTF/ODT/EPUB/MOBI/AZW3/HTML 九格式互转,自建 calibre 引擎,批量打包下载', tag: '全新' },
{ name: '视频工具', icon: '视', desc: '格式转换、压缩、裁剪、旋转、变速、消音、提取音频、截图、GIF 互转等 11 个工具,服务端 ffmpeg 高速处理,最大 2GB', tag: '全新' },
{ name: '音频工具', icon: '音', desc: '文字转音频(本地神经音色,离线可用)、音频转文字(中英日粤自动检测,Whisper 引擎)、声音克隆(部署中),全部本地模型不外传', tag: '全新' },
],
},
{
+6
View File
@@ -54,6 +54,12 @@ const FEATURES: Feature[] = [
icon: '🎥',
points: ['格式转换/压缩/裁剪/旋转/变速/消音/提取音频/截图/GIF互转等 11 个工具', '服务端 ffmpeg 高速转码,最大支持 2GB 视频', '处理完在线预览,一键下载结果'],
},
{
path: '/audio-tools',
name: '音频工具',
icon: '🎙️',
points: ['文字转音频:本地神经 TTS,离线可用速度快', '音频转文字:Whisper 引擎,中英日粤自动检测带时间轴', '声音克隆:5 秒样本克隆音色(即将上线)'],
},
{
path: '/label-designer',
name: '面单设计',
+597
View File
@@ -0,0 +1,597 @@
<script setup lang="ts">
import { computed, ref } from 'vue';
import { useHead } from '@vueuse/head';
import { licenseHeaders } from '../license/license';
import GenHistory from '@/tools/gen-history/GenHistory.vue';
import { useGenHistory } from '@/tools/gen-history/gen-history';
useHead({ title: '音频工具 - IT-TOOLS-PRO' });
const genHist = useGenHistory('audio-tools');
// ============ 文字转音频 (TTS) ============
const VOICES = [
{ value: 'zh_CN-huayan-medium', label: '晓妍(女声·标准中文)' },
{ value: 'en_US-amy-medium', label: 'Amy(女声·英语)' },
];
const ttsText = ref('');
const ttsVoice = ref('zh_CN-huayan-medium');
const ttsRate = ref(0);
const ttsPitch = ref(0);
const ttsBusy = ref(false);
const ttsError = ref('');
const ttsUrl = ref('');
const ttsSize = ref(0);
const ttsName = ref('');
async function genTts() {
if (!ttsText.value.trim()) {
ttsError.value = '请输入文字内容';
return;
}
ttsBusy.value = true;
ttsError.value = '';
try {
const res = await fetch('/relay/tts', {
method: 'POST',
headers: { 'Content-Type': 'application/json', ...licenseHeaders() },
body: JSON.stringify({ text: ttsText.value, voice: ttsVoice.value, rate: ttsRate.value, pitch: ttsPitch.value }),
});
if (!res.ok) {
const b = await res.json().catch(() => ({}));
throw new Error(b.message || `合成失败(${res.status})`);
}
const blob = await res.blob();
if (ttsUrl.value) {
URL.revokeObjectURL(ttsUrl.value);
}
ttsUrl.value = URL.createObjectURL(blob);
ttsSize.value = blob.size;
const vn = VOICES.find(v => v.value === ttsVoice.value)?.label ?? '';
ttsName.value = `${vn} · ${ttsText.value.slice(0, 16)}…`;
genHist.add({ title: `TTS: ${ttsText.value.slice(0, 30)}`, detail: `${vn}(${(blob.size / 1024).toFixed(0)}KB)` });
}
catch (e: any) {
ttsError.value = String(e?.message || e);
}
finally {
ttsBusy.value = false;
}
}
function downloadTts() {
const a = document.createElement('a');
a.href = ttsUrl.value;
a.download = '语音合成.mp3';
a.click();
}
// ============ 音频转文字 (ASR) ============
const asrFile = ref<File | null>(null);
const asrInput = ref<HTMLInputElement>();
const asrLang = ref('');
const asrBusy = ref(false);
const asrError = ref('');
const asrText = ref('');
const asrSegments = ref<{ start: number; end: number; text: string }[]>([]);
const asrLangDetected = ref('');
const asrCopied = ref(false);
const asrSpent = ref(0);
function pickAsr() {
asrInput.value?.click();
}
function onAsrFile(e: Event) {
const input = e.target as HTMLInputElement;
asrFile.value = input.files?.[0] ?? null;
input.value = '';
asrText.value = '';
asrSegments.value = [];
}
function onAsrDrop(e: DragEvent) {
asrFile.value = e.dataTransfer?.files?.[0] ?? null;
asrText.value = '';
asrSegments.value = [];
}
function fmtTime(s: number) {
const m = Math.floor(s / 60);
const sec = (s % 60).toFixed(1);
return `${m}:${Number(sec) < 10 ? '0' : ''}${sec}`;
}
async function runAsr() {
if (!asrFile.value) {
asrError.value = '请先选择音频文件';
return;
}
asrBusy.value = true;
asrError.value = '';
const t0 = Date.now();
try {
const fd = new FormData();
fd.append('file', asrFile.value);
fd.append('language', asrLang.value);
const res = await fetch('/relay/asr', { method: 'POST', body: fd, headers: licenseHeaders() });
const b = await res.json().catch(() => ({}));
if (!res.ok) {
throw new Error(b.message || `识别失败(${res.status})`);
}
asrText.value = b.data?.text ?? '';
asrSegments.value = b.data?.segments ?? [];
asrLangDetected.value = b.data?.language ?? '';
asrSpent.value = Math.round((Date.now() - t0) / 1000);
genHist.add({ title: `语音识别: ${asrFile.value.name}`, detail: `${asrText.value.slice(0, 40)}…(${asrSpent.value}s)` });
}
catch (e: any) {
asrError.value = String(e?.message || e);
}
finally {
asrBusy.value = false;
}
}
async function copyAsr() {
try {
await navigator.clipboard.writeText(asrText.value);
asrCopied.value = true;
setTimeout(() => (asrCopied.value = false), 1500);
}
catch { /* ignore */ }
}
// ============ tabs ============
type TabId = 'tts' | 'asr' | 'clone';
const tab = ref<TabId>('tts');
const TABS: { id: TabId; name: string; icon: string; desc: string; status?: string }[] = [
{ id: 'tts', name: '文字转音频', icon: '🔊', desc: '输入文字一键生成语音,本地神经音色(中文/英语),语速可调' },
{ id: 'asr', name: '音频转文字', icon: '📝', desc: '上传音频/视频自动识别文字,中英日粤自动检测' },
{ id: 'clone', name: '声音克隆', icon: '🎭', desc: '上传几秒参考音频即可克隆音色朗读任意文本' },
];
const tabDesc = computed(() => TABS.find(t => t.id === tab.value)?.desc ?? '');
</script>
<template>
<div class="at-root">
<div class="at-hero">
<div class="at-hero-title">AudioKit · 音频工具箱</div>
<div class="at-hero-sub">
文字转音频、音频转文字、声音克隆——AI 语音三件套,服务端高速处理
</div>
</div>
<!-- tab cards -->
<div class="at-tabs">
<div
v-for="t in TABS"
:key="t.id"
class="at-tab"
:class="{ active: tab === t.id }"
@click="tab = t.id"
>
<span class="at-tab-icon">{{ t.icon }}</span>
<span class="at-tab-name">{{ t.name }}</span>
<span class="at-tab-desc">{{ t.desc }}</span>
</div>
</div>
<!-- TTS panel -->
<div v-if="tab === 'tts'" class="at-panel">
<div class="at-panel-title">
🔊 文字转音频 <span class="at-panel-sub">{{ tabDesc }}</span>
</div>
<textarea v-model="ttsText" class="at-textarea" rows="5" placeholder="输入要转换为语音的文字,最多 2000 字…" />
<div class="at-row">
<div class="at-field">
<label class="at-label">音色</label>
<select v-model="ttsVoice" class="at-select">
<option v-for="v in VOICES" :key="v.value" :value="v.value">{{ v.label }}</option>
</select>
</div>
<div class="at-field">
<label class="at-label">语速 {{ ttsRate > 0 ? '+' : '' }}{{ ttsRate }}%</label>
<input v-model.number="ttsRate" type="range" min="-50" max="100" step="5" class="at-slider">
</div>
</div>
<div class="at-actions">
<button class="at-btn" :disabled="ttsBusy || !ttsText.trim()" @click="genTts">
{{ ttsBusy ? '⏳ 合成中…' : '🚀 生成语音' }}
</button>
</div>
<div v-if="ttsError" class="at-error">{{ ttsError }}</div>
<div v-if="ttsUrl" class="at-result">
<audio :src="ttsUrl" controls class="at-audio" />
<div class="at-result-bar">
<span class="at-result-name">{{ ttsName }}({{ (ttsSize / 1024).toFixed(0) }} KB)</span>
<button class="at-btn at-btn-sm" @click="downloadTts">⬇ 下载 MP3</button>
</div>
</div>
</div>
<!-- ASR panel -->
<div v-if="tab === 'asr'" class="at-panel">
<div class="at-panel-title">
📝 音频转文字 <span class="at-panel-sub">{{ tabDesc }}</span>
</div>
<div class="at-drop" @click="pickAsr" @dragover.prevent @drop.prevent="onAsrDrop">
<input ref="asrInput" type="file" hidden accept="audio/*,.m4a,.wma,.opus,.mp4,.webm" @change="onAsrFile">
<template v-if="!asrFile">
<div class="at-drop-hint">📁 点击选择或拖拽音频/视频文件(最大 30MB)</div>
<div class="at-drop-sub">支持 MP3 / WAV / M4A / OGG / FLAC / AAC / MP4 / WEBM</div>
</template>
<div v-else class="at-file">
🎧 {{ asrFile.name }} <span class="at-file-size">({{ (asrFile.size / 1024 / 1024).toFixed(1) }} MB)</span>
<a href="javascript:;" class="at-clear" @click.stop="asrFile = null">✕ 换一个</a>
</div>
</div>
<div class="at-row">
<div class="at-field">
<label class="at-label">识别语言</label>
<select v-model="asrLang" class="at-select">
<option value="">自动检测</option>
<option value="zh">中文</option>
<option value="en">英语</option>
<option value="ja">日语</option>
<option value="yue">粤语</option>
</select>
</div>
</div>
<div class="at-actions">
<button class="at-btn" :disabled="asrBusy || !asrFile" @click="runAsr">
{{ asrBusy ? '⏳ 识别中(音频越长耗时越久)…' : '🚀 开始识别' }}
</button>
</div>
<div v-if="asrError" class="at-error">{{ asrError }}</div>
<div v-if="asrText" class="at-result">
<div class="at-result-bar">
<span class="at-result-name">
识别结果({{ asrSegments.length }} 段 · 检测语言 {{ asrLangDetected }} · 用时 {{ asrSpent }}s)
</span>
<button class="at-btn at-btn-sm" @click="copyAsr">{{ asrCopied ? '已复制 ✓' : '复制全文' }}</button>
</div>
<div class="at-asr-text">{{ asrText }}</div>
<div v-if="asrSegments.length" class="at-segments">
<div v-for="(s, i) in asrSegments.slice(0, 50)" :key="i" class="at-seg">
<span class="at-seg-time">{{ fmtTime(s.start) }}</span>
<span class="at-seg-text">{{ s.text }}</span>
</div>
</div>
</div>
</div>
<!-- clone panel -->
<div v-if="tab === 'clone'" class="at-panel">
<div class="at-panel-title">
🎭 声音克隆 <span class="at-panel-sub">{{ tabDesc }}</span>
</div>
<div class="at-soon">
<div class="at-soon-icon">🔧</div>
<div class="at-soon-title">声音克隆功能部署中,即将上线</div>
<div class="at-soon-desc">
基于 GPT-SoVITS 本地大模型:上传 5-10 秒参考音频即可克隆音色,让 AI 用你的声音朗读任意文本。
模型部署完成后本页面自动开放,无需更新站点。
</div>
<div class="at-soon-tips">
<div>✓ 支持中文零样本克隆(5 秒样本)</div>
<div>✓ 克隆音色可保存复用</div>
<div>✓ 本地模型推理,参考音频不外传</div>
</div>
</div>
</div>
<GenHistory tool="audio-tools" label="音频处理记录" class="mt-20px" />
</div>
</template>
<style lang="less" scoped>
.at-root {
max-width: 900px;
margin: 0 auto;
padding-bottom: 60px;
}
.at-hero {
text-align: center;
margin: 10px 0 22px;
.at-hero-title {
font-size: 24px;
font-weight: 800;
background: linear-gradient(48deg, #25636c 0%, #3b956f 55%, #14a058 100%);
-webkit-background-clip: text;
background-clip: text;
color: transparent;
}
.at-hero-sub {
margin-top: 8px;
font-size: 13px;
opacity: 0.6;
}
}
.at-tabs {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 10px;
margin-bottom: 16px;
.at-tab {
border: 1px solid rgba(128, 128, 128, 0.22);
border-radius: 12px;
padding: 12px 14px;
cursor: pointer;
transition: border-color 0.15s, box-shadow 0.15s;
display: flex;
flex-direction: column;
gap: 3px;
&:hover {
border-color: rgba(24, 160, 88, 0.5);
}
&.active {
border-color: #18a058;
box-shadow: 0 0 0 1px #18a058;
}
.at-tab-icon {
font-size: 22px;
}
.at-tab-name {
font-size: 14.5px;
font-weight: 700;
}
.at-tab-desc {
font-size: 11.5px;
opacity: 0.55;
line-height: 1.55;
}
}
}
.at-panel {
border: 1.5px solid rgba(24, 160, 88, 0.4);
border-radius: 14px;
padding: 18px 20px;
background: rgba(24, 160, 88, 0.03);
.at-panel-title {
font-size: 16px;
font-weight: 800;
margin-bottom: 12px;
.at-panel-sub {
font-size: 12px;
font-weight: 400;
opacity: 0.55;
margin-left: 8px;
}
}
}
.at-textarea {
width: 100%;
box-sizing: border-box;
border: 1px solid rgba(128, 128, 128, 0.35);
border-radius: 9px;
padding: 10px 12px;
font-size: 14px;
font-family: inherit;
resize: vertical;
outline: none;
margin-bottom: 12px;
&:focus {
border-color: #18a058;
}
}
.at-row {
display: flex;
gap: 18px;
flex-wrap: wrap;
margin-bottom: 12px;
.at-field {
min-width: 180px;
flex: 1;
.at-label {
display: block;
font-size: 12px;
opacity: 0.65;
margin-bottom: 4px;
}
.at-select {
width: 100%;
box-sizing: border-box;
border: 1px solid rgba(128, 128, 128, 0.35);
border-radius: 7px;
padding: 6px 10px;
font-size: 13px;
background: #fff;
outline: none;
}
.at-slider {
width: 100%;
}
}
}
.at-drop {
border: 1.5px dashed rgba(128, 128, 128, 0.4);
border-radius: 10px;
text-align: center;
padding: 16px;
cursor: pointer;
margin-bottom: 12px;
transition: border-color 0.15s;
&:hover {
border-color: #18a058;
}
.at-drop-hint {
font-size: 13.5px;
font-weight: 600;
}
.at-drop-sub {
font-size: 11.5px;
opacity: 0.5;
margin-top: 4px;
}
.at-file {
font-size: 13.5px;
font-weight: 600;
.at-file-size {
font-weight: 400;
opacity: 0.55;
}
.at-clear {
color: #d03050;
margin-left: 12px;
text-decoration: none;
font-weight: 400;
}
}
}
.at-actions {
margin-bottom: 6px;
}
.at-btn {
background: #18a058;
color: #fff;
border: none;
border-radius: 9px;
padding: 9px 26px;
font-size: 14px;
font-weight: 700;
cursor: pointer;
&:hover:not(:disabled) {
opacity: 0.85;
}
&:disabled {
opacity: 0.45;
cursor: not-allowed;
}
&.at-btn-sm {
padding: 6px 16px;
font-size: 12.5px;
}
}
.at-error {
color: #d03050;
font-size: 12.5px;
margin-top: 8px;
}
.at-result {
margin-top: 14px;
.at-audio {
width: 100%;
}
.at-result-bar {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-top: 8px;
flex-wrap: wrap;
.at-result-name {
font-size: 12.5px;
opacity: 0.7;
}
}
.at-asr-text {
background: rgba(128, 128, 128, 0.07);
border-radius: 9px;
padding: 12px 14px;
font-size: 13.5px;
line-height: 1.9;
white-space: pre-wrap;
margin-top: 10px;
}
.at-segments {
margin-top: 10px;
max-height: 240px;
overflow: auto;
border: 1px solid rgba(128, 128, 128, 0.18);
border-radius: 9px;
padding: 8px 12px;
.at-seg {
display: flex;
gap: 10px;
font-size: 12.5px;
padding: 3px 0;
.at-seg-time {
color: #18a058;
font-weight: 600;
flex-shrink: 0;
font-variant-numeric: tabular-nums;
}
.at-seg-text {
opacity: 0.85;
}
}
}
}
.at-soon {
text-align: center;
padding: 24px 10px;
.at-soon-icon {
font-size: 34px;
margin-bottom: 8px;
}
.at-soon-title {
font-size: 16px;
font-weight: 800;
margin-bottom: 8px;
}
.at-soon-desc {
font-size: 13px;
opacity: 0.65;
line-height: 1.8;
max-width: 480px;
margin: 0 auto 14px;
}
.at-soon-tips {
display: inline-block;
text-align: left;
font-size: 12.5px;
opacity: 0.75;
line-height: 2;
}
}
</style>
+12
View File
@@ -0,0 +1,12 @@
import { Microphone2 } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate } from '@/plugins/i18n.plugin';
export const tool = defineTool({
name: translate('tools.audio-tools.title'),
path: '/audio-tools',
description: translate('tools.audio-tools.description'),
keywords: ['audio', 'tts', 'speech', 'voice', 'asr', 'transcribe', 'clone', '语音', '文字转语音', '音频转文字', '声音克隆', '识别'],
component: () => import('./audio-tools.vue'),
icon: Microphone2,
});
+2 -1
View File
@@ -82,6 +82,7 @@ import { tool as pdfOcr } from './pdf-ocr';
import { tool as pdfTools } from './pdf-tools';
import { tool as imageTools } from './image-tools';
import { tool as videoTools } from './video-tools';
import { tool as audioTools } from './audio-tools';
import { tool as docConvert } from './doc-convert';
import { tool as aiRetouch } from './ai-retouch';
import { tool as wifiQrCodeGenerator } from './wifi-qr-code-generator';
@@ -153,7 +154,7 @@ export const toolsByCategory: ToolCategory[] = [
},
{
name: 'Images and videos',
components: [qrCodeGenerator, wifiQrCodeGenerator, batchBarcodeGenerator, codeReader, imageOcr, pdfOcr, pdfTools, imageTools, videoTools, docConvert, aiRetouch, labelDesigner, siteBookmarks, svgPlaceholderGenerator, cameraRecorder],
components: [qrCodeGenerator, wifiQrCodeGenerator, batchBarcodeGenerator, codeReader, imageOcr, pdfOcr, pdfTools, imageTools, videoTools, audioTools, docConvert, aiRetouch, labelDesigner, siteBookmarks, svgPlaceholderGenerator, cameraRecorder],
},
{
name: 'Development',
+1
View File
@@ -15,6 +15,7 @@ export const PROTECTED_TOOLS: Record<string, string> = {
'/image-tools': '图片工具',
'/pdf-tools': 'PDF工具',
'/video-tools': '视频工具',
'/audio-tools': '音频工具',
};
export const TRIAL_MS = 30 * 60 * 1000; // 每个功能免费 30 分钟