创建了完整的文本转语音工具,包括: - 后端:Go语言实现的HTTP服务(main.go) - 支持自定义API地址配置 - 提供/api/tts端点 - 兼容OpenAI TTS API格式 - 前端: - index.html:简洁大方的用户界面 - styles.css:现代渐变设计和响应式布局 - app.js:完整的交互逻辑和状态管理 - 配置: - config.example.json:API地址和端口配置示例 - 支持配置文件、环境变量和前端直接配置三种方式 - 文档: - README.md:详细的使用说明和API文档 功能特点: - ✅ 自定义API地址支持 - ✅ 多种声音模型(tts-1/tts-1-hd) - ✅ 6种语音类型选择 - ✅ 实时字符计数 - ✅ 音频播放和下载 - ✅ 本地存储API配置 - ✅ 友好的错误提示
345 lines
6.1 KiB
CSS
345 lines
6.1 KiB
CSS
/* 基础样式重置 */
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
/* 全局样式 */
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|
line-height: 1.6;
|
|
color: #333;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
min-height: 100vh;
|
|
}
|
|
|
|
/* 容器样式 */
|
|
.container {
|
|
max-width: 800px;
|
|
margin: 0 auto;
|
|
padding: 20px;
|
|
background: rgba(255, 255, 255, 0.95);
|
|
border-radius: 16px;
|
|
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
|
|
backdrop-filter: blur(10px);
|
|
-webkit-backdrop-filter: blur(10px);
|
|
margin-top: 20px;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
/* 头部样式 */
|
|
header {
|
|
text-align: center;
|
|
margin-bottom: 30px;
|
|
padding-bottom: 20px;
|
|
border-bottom: 2px solid #e0e0e0;
|
|
}
|
|
|
|
header h1 {
|
|
color: #2d3748;
|
|
font-size: 2.5rem;
|
|
font-weight: 700;
|
|
margin-bottom: 10px;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
-webkit-background-clip: text;
|
|
-webkit-text-fill-color: transparent;
|
|
background-clip: text;
|
|
}
|
|
|
|
.subtitle {
|
|
color: #718096;
|
|
font-size: 1.1rem;
|
|
font-weight: 400;
|
|
}
|
|
|
|
/* 主要内容区域 */
|
|
main {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 25px;
|
|
}
|
|
|
|
/* 各部分通用样式 */
|
|
section {
|
|
background: #f8fafc;
|
|
padding: 25px;
|
|
border-radius: 12px;
|
|
border: 1px solid #e2e8f0;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
section:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
|
|
}
|
|
|
|
section h2 {
|
|
color: #2d3748;
|
|
font-size: 1.5rem;
|
|
font-weight: 600;
|
|
margin-bottom: 20px;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
}
|
|
|
|
section h2::before {
|
|
content: '';
|
|
width: 4px;
|
|
height: 24px;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
border-radius: 2px;
|
|
}
|
|
|
|
/* 配置网格布局 */
|
|
.config-grid,
|
|
.params-grid,
|
|
.controls-grid {
|
|
display: grid;
|
|
grid-template-columns: 1fr;
|
|
gap: 20px;
|
|
}
|
|
|
|
@media (min-width: 600px) {
|
|
.config-grid,
|
|
.params-grid,
|
|
.controls-grid {
|
|
grid-template-columns: repeat(2, 1fr);
|
|
}
|
|
}
|
|
|
|
/* 表单组样式 */
|
|
.form-group {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 8px;
|
|
}
|
|
|
|
.form-group label {
|
|
font-weight: 500;
|
|
color: #4a5568;
|
|
font-size: 0.95rem;
|
|
}
|
|
|
|
/* 表单输入样式 */
|
|
.form-input,
|
|
.form-select {
|
|
padding: 12px 16px;
|
|
border: 2px solid #e2e8f0;
|
|
border-radius: 8px;
|
|
font-size: 1rem;
|
|
transition: all 0.3s ease;
|
|
background: white;
|
|
width: 100%;
|
|
}
|
|
|
|
.form-input:focus,
|
|
.form-select:focus {
|
|
outline: none;
|
|
border-color: #667eea;
|
|
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
|
}
|
|
|
|
.form-input::placeholder {
|
|
color: #a0aec0;
|
|
}
|
|
|
|
/* 文本输入区域 */
|
|
.text-input-container {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 10px;
|
|
}
|
|
|
|
#textInput {
|
|
padding: 16px;
|
|
border: 2px solid #e2e8f0;
|
|
border-radius: 8px;
|
|
font-size: 1rem;
|
|
font-family: inherit;
|
|
resize: vertical;
|
|
min-height: 150px;
|
|
transition: all 0.3s ease;
|
|
background: white;
|
|
}
|
|
|
|
#textInput:focus {
|
|
outline: none;
|
|
border-color: #667eea;
|
|
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
|
}
|
|
|
|
.text-info {
|
|
text-align: right;
|
|
color: #718096;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
/* 按钮样式 */
|
|
.btn {
|
|
padding: 12px 24px;
|
|
border: none;
|
|
border-radius: 8px;
|
|
font-size: 1rem;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 8px;
|
|
text-decoration: none;
|
|
}
|
|
|
|
.btn-primary {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
}
|
|
|
|
.btn-primary:hover:not(:disabled) {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
|
|
}
|
|
|
|
.btn-secondary {
|
|
background: #e2e8f0;
|
|
color: #4a5568;
|
|
}
|
|
|
|
.btn-secondary:hover:not(:disabled) {
|
|
background: #cbd5e0;
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.btn:disabled {
|
|
opacity: 0.6;
|
|
cursor: not-allowed;
|
|
transform: none;
|
|
}
|
|
|
|
/* 控制区域 */
|
|
.controls-section {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 15px;
|
|
}
|
|
|
|
.status {
|
|
padding: 12px 16px;
|
|
border-radius: 8px;
|
|
font-size: 0.95rem;
|
|
font-weight: 500;
|
|
text-align: center;
|
|
min-height: 44px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.status.success {
|
|
background: #c6f6d5;
|
|
color: #22543d;
|
|
border: 1px solid #9ae6b4;
|
|
}
|
|
|
|
.status.error {
|
|
background: #fed7d7;
|
|
color: #742a2a;
|
|
border: 1px solid #feb2b2;
|
|
}
|
|
|
|
.status.loading {
|
|
background: #ebf8ff;
|
|
color: #2a4365;
|
|
border: 1px solid #bee3f8;
|
|
}
|
|
|
|
/* 音频播放区域 */
|
|
.audio-player-container {
|
|
display: flex;
|
|
justify-content: center;
|
|
padding: 20px 0;
|
|
}
|
|
|
|
.audio-player {
|
|
width: 100%;
|
|
max-width: 100%;
|
|
height: 50px;
|
|
background: white;
|
|
border-radius: 25px;
|
|
border: 2px solid #e2e8f0;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.audio-player:focus {
|
|
outline: none;
|
|
border-color: #667eea;
|
|
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
|
|
}
|
|
|
|
/* 页脚样式 */
|
|
footer {
|
|
text-align: center;
|
|
margin-top: 30px;
|
|
padding-top: 20px;
|
|
border-top: 2px solid #e0e0e0;
|
|
color: #718096;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
/* 响应式设计 */
|
|
@media (max-width: 600px) {
|
|
.container {
|
|
margin: 10px;
|
|
padding: 15px;
|
|
}
|
|
|
|
header h1 {
|
|
font-size: 2rem;
|
|
}
|
|
|
|
section {
|
|
padding: 20px;
|
|
}
|
|
|
|
.btn {
|
|
padding: 10px 20px;
|
|
font-size: 0.95rem;
|
|
}
|
|
}
|
|
|
|
/* 动画效果 */
|
|
@keyframes fadeIn {
|
|
from {
|
|
opacity: 0;
|
|
transform: translateY(10px);
|
|
}
|
|
to {
|
|
opacity: 1;
|
|
transform: translateY(0);
|
|
}
|
|
}
|
|
|
|
section {
|
|
animation: fadeIn 0.5s ease-out;
|
|
}
|
|
|
|
/* 加载动画 */
|
|
.loading::after {
|
|
content: '';
|
|
display: inline-block;
|
|
width: 16px;
|
|
height: 16px;
|
|
border: 2px solid rgba(255, 255, 255, 0.3);
|
|
border-radius: 50%;
|
|
border-top-color: #fff;
|
|
animation: spin 1s ease-in-out infinite;
|
|
margin-left: 10px;
|
|
}
|
|
|
|
@keyframes spin {
|
|
to { transform: rotate(360deg); }
|
|
}
|