This commit is contained in:
2026-03-05 21:01:34 +08:00
parent 27d1c53b49
commit c07a61c424
21 changed files with 3061 additions and 1465 deletions

View File

@@ -5,50 +5,78 @@
</a-empty>
</div>
<div v-else class="voice-selector-with-preview">
<a-select
v-model:value="selectedVoiceId"
placeholder="请选择音色"
class="voice-select"
:options="voiceOptions"
@change="handleVoiceChange"
style="width: calc(100% - 80px)"
/>
<div v-else class="voice-selector-wrapper">
<!-- 选择器卡片 -->
<div class="voice-card" :class="{ 'has-audio': audioUrl }">
<div class="voice-card-header">
<div class="header-icon">
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M12 14C13.1046 14 14 13.1046 14 12C14 10.8954 13.1046 10 12 10C10.8954 10 10 10.8954 10 12C10 13.1046 10.8954 14 12 14Z" fill="currentColor"/>
<path d="M12 6C14.813 6 17.125 8.156 17.469 10.875C17.5 11.125 17.719 11.313 17.969 11.313H18.031C18.313 11.313 18.531 11.063 18.5 10.781C18.094 7.5 15.344 5 12 5C8.656 5 5.906 7.5 5.5 10.781C5.469 11.063 5.687 11.313 5.969 11.313H6.031C6.281 11.313 6.5 11.125 6.531 10.875C6.875 8.156 9.187 6 12 6Z" fill="currentColor" opacity="0.6"/>
<path d="M12 3C16.5 3 20.188 6.5 20.469 11C20.5 11.25 20.719 11.438 20.969 11.438H21.031C21.313 11.438 21.531 11.188 21.5 10.906C21.156 5.875 17 2 12 2C7 2 2.844 5.875 2.5 10.906C2.469 11.188 2.687 11.438 2.969 11.438H3.031C3.281 11.438 3.5 11.25 3.531 11C3.813 6.5 7.5 3 12 3Z" fill="currentColor" opacity="0.3"/>
</svg>
</div>
<span class="header-title">音色选择</span>
<span v-if="currentVoiceName" class="header-badge">{{ currentVoiceName }}</span>
</div>
<a-button
class="preview-button"
size="small"
:disabled="!selectedVoiceId || isPlayerInitializing"
:loading="previewLoadingVoiceId === selectedVoiceId"
@click="handleSynthesize"
>
<template #icon>
<SoundOutlined />
</template>
合成
</a-button>
<div class="voice-card-body">
<div class="select-wrapper">
<a-select
v-model:value="selectedVoiceId"
placeholder="请选择音色"
class="voice-select"
:options="voiceOptions"
@change="handleVoiceChange"
>
<template #suffixIcon>
<DownOutlined class="select-arrow" />
</template>
</a-select>
</div>
<a-button
class="synthesize-btn"
:class="{ 'btn-active': selectedVoiceId }"
:disabled="!selectedVoiceId || isPlayerInitializing"
:loading="previewLoadingVoiceId === selectedVoiceId"
@click="handleSynthesize"
>
<template #icon>
<SoundOutlined />
</template>
<span class="btn-text">合成试听</span>
</a-button>
</div>
</div>
<!-- 播放器区域 -->
<transition name="slide-fade">
<div v-if="audioUrl" class="player-section">
<div ref="playerContainer" class="aplayer-container"></div>
<div class="player-actions">
<a-button
type="text"
size="small"
@click="downloadAudio"
class="download-btn"
>
<template #icon>
<DownloadOutlined />
</template>
下载音频
</a-button>
</div>
</div>
</transition>
</div>
<!-- APlayer 播放器容器 -->
<div v-show="audioUrl" ref="playerContainer" class="aplayer-container"></div>
<!-- 下载按钮 -->
<a-button
v-show="audioUrl"
type="link"
size="small"
@click="downloadAudio"
class="download-link"
>
下载音频
</a-button>
</div>
</template>
<script setup>
import { ref, computed, onMounted, onBeforeUnmount, nextTick, watch } from 'vue'
import { Empty, message } from 'ant-design-vue'
import { SoundOutlined } from '@ant-design/icons-vue'
import { SoundOutlined, DownloadOutlined, DownOutlined } from '@ant-design/icons-vue'
import { useVoiceCopyStore } from '@/stores/voiceCopy'
import { useTTS, TTS_PROVIDERS } from '@/composables/useTTS'
import APlayer from 'aplayer'
@@ -294,46 +322,230 @@ onBeforeUnmount(() => {
})
</script>
<style scoped>
<style scoped lang="less">
.voice-selector {
width: 100%;
}
.empty-voices {
padding: 16px 0;
padding: 24px 0;
background: var(--color-surface);
border: 1px dashed var(--color-border);
border-radius: var(--radius-card);
border-radius: 12px;
}
/* 音色选择器和试听按钮的容器 */
.voice-selector-with-preview {
/* 容器 */
.voice-selector-wrapper {
display: flex;
flex-direction: column;
gap: 16px;
}
/* 音色卡片 */
.voice-card {
background: linear-gradient(135deg, rgba(59, 130, 246, 0.05) 0%, rgba(139, 92, 246, 0.05) 100%);
border: 1px solid rgba(59, 130, 246, 0.15);
border-radius: 12px;
padding: 16px;
transition: all 0.3s ease;
&:hover {
border-color: rgba(59, 130, 246, 0.3);
box-shadow: 0 4px 12px rgba(59, 130, 246, 0.1);
}
&.has-audio {
border-color: rgba(59, 130, 246, 0.4);
background: linear-gradient(135deg, rgba(59, 130, 246, 0.08) 0%, rgba(139, 92, 246, 0.08) 100%);
}
}
/* 卡片头部 */
.voice-card-header {
display: flex;
gap: 8px;
align-items: center;
width: 100%;
gap: 10px;
margin-bottom: 14px;
}
/* 下拉框样式 */
.voice-select {
flex: 1;
.header-icon {
width: 28px;
height: 28px;
border-radius: 8px;
background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
display: flex;
align-items: center;
justify-content: center;
color: white;
svg {
width: 16px;
height: 16px;
}
}
/* 试听按钮样式 */
.preview-button {
height: 32px;
.header-title {
font-size: 14px;
font-weight: 500;
color: var(--color-text);
}
.header-badge {
margin-left: auto;
padding: 2px 10px;
background: rgba(59, 130, 246, 0.1);
border-radius: 12px;
font-size: 12px;
color: #3b82f6;
font-weight: 500;
max-width: 120px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
/* APlayer 容器样式 */
.aplayer-container {
margin-top: 12px;
/* 卡片主体 */
.voice-card-body {
display: flex;
gap: 12px;
align-items: stretch;
}
/* 下载链接样式 */
.download-link {
margin-top: 8px;
padding: 0;
.select-wrapper {
flex: 1;
:deep(.ant-select) {
width: 100%;
height: 40px;
.ant-select-selector {
height: 40px !important;
border-radius: 10px !important;
border-color: rgba(59, 130, 246, 0.2) !important;
background: rgba(255, 255, 255, 0.8) !important;
transition: all 0.3s ease !important;
&:hover {
border-color: #3b82f6 !important;
}
}
&.ant-select-focused .ant-select-selector {
border-color: #3b82f6 !important;
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1) !important;
}
.ant-select-selection-item {
line-height: 38px !important;
}
.ant-select-selection-placeholder {
line-height: 38px !important;
}
}
}
.select-arrow {
color: #3b82f6;
transition: transform 0.3s ease;
}
/* 合成按钮 */
.synthesize-btn {
height: 40px;
padding: 0 20px;
border-radius: 10px;
border: none;
background: linear-gradient(135deg, #e2e8f0 0%, #cbd5e1 100%);
color: #64748b;
font-weight: 500;
display: flex;
align-items: center;
gap: 6px;
transition: all 0.3s ease;
white-space: nowrap;
&:hover:not(:disabled) {
background: linear-gradient(135deg, #cbd5e1 0%, #94a3b8 100%);
transform: translateY(-1px);
}
&:disabled {
opacity: 0.6;
cursor: not-allowed;
}
&.btn-active {
background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
color: white;
box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
&:hover:not(:disabled) {
background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4);
}
}
.btn-text {
font-size: 13px;
}
}
/* 播放器区域 */
.player-section {
background: rgba(255, 255, 255, 0.6);
border-radius: 12px;
padding: 14px;
border: 1px solid rgba(59, 130, 246, 0.1);
}
.aplayer-container {
:deep(.aplayer) {
border-radius: 10px;
box-shadow: none;
border: 1px solid rgba(0, 0, 0, 0.06);
.aplayer-body {
border-radius: 10px;
}
}
}
.player-actions {
margin-top: 10px;
display: flex;
justify-content: flex-end;
}
.download-btn {
color: #3b82f6;
font-size: 12px;
padding: 4px 8px;
height: auto;
transition: all 0.2s ease;
&:hover {
color: #2563eb;
background: rgba(59, 130, 246, 0.1);
}
}
/* 动画 */
.slide-fade-enter-active {
transition: all 0.3s ease-out;
}
.slide-fade-leave-active {
transition: all 0.2s ease-in;
}
.slide-fade-enter-from {
transform: translateY(-10px);
opacity: 0;
}
.slide-fade-leave-to {
transform: translateY(-10px);
opacity: 0;
}
</style>