From 1edb4273ddd9b31305ee33c7e4e49f5571688dea Mon Sep 17 00:00:00 2001 From: zuoban <1061669148@qq.com> Date: Sun, 29 Jun 2025 11:49:53 +0800 Subject: [PATCH] feat: remove API documentation tab and update README for deployment instructions --- README.md | 2 +- internal/http/handlers/pages.go | 21 - internal/http/routes/routes.go | 3 - web/templates/api-doc.html | 737 -------------------------------- web/templates/index.html | 36 +- 5 files changed, 8 insertions(+), 791 deletions(-) delete mode 100644 web/templates/api-doc.html diff --git a/README.md b/README.md index dc57110..498c63d 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ docker run -d -p 8080:8080 --name=tts zuoban/zb-tts ``` -部署完成后,访问 `http://localhost:8080` 使用 Web 界面,或通过 `http://localhost:8080/api-doc` 查看 API 文档。部署完成后,访问 `http://localhost:8080` 使用 Web 界面,或通过 `http://localhost:8080/api-doc` 查看 API 文档。 +部署完成后,访问 `http://localhost:8080` 使用 Web 界面。 ### Cloudflare Worker 部署 diff --git a/internal/http/handlers/pages.go b/internal/http/handlers/pages.go index 5b866f5..f69c5e4 100644 --- a/internal/http/handlers/pages.go +++ b/internal/http/handlers/pages.go @@ -47,24 +47,3 @@ func (h *PagesHandler) HandleIndex(c *gin.Context) { return } } - -// HandleAPIDoc 处理API文档请求 -func (h *PagesHandler) HandleAPIDoc(c *gin.Context) { - // 准备模板数据 - data := map[string]interface{}{ - "BasePath": h.config.Server.BasePath, - "DefaultVoice": h.config.TTS.DefaultVoice, - "DefaultRate": h.config.TTS.DefaultRate, - "DefaultPitch": h.config.TTS.DefaultPitch, - "DefaultFormat": h.config.TTS.DefaultFormat, - } - - // 设置内容类型 - c.Header("Content-Type", "text/html; charset=utf-8") - - // 渲染模板 - if err := h.templates.ExecuteTemplate(c.Writer, "api-doc.html", data); err != nil { - c.AbortWithStatusJSON(500, gin.H{"error": "模板渲染失败: " + err.Error()}) - return - } -} diff --git a/internal/http/routes/routes.go b/internal/http/routes/routes.go index 16d8829..2b0b7fc 100644 --- a/internal/http/routes/routes.go +++ b/internal/http/routes/routes.go @@ -43,9 +43,6 @@ func SetupRoutes(cfg *config.Config, ttsService tts.Service) (*gin.Engine, error // 设置主页路由 baseRouter.GET("/", pagesHandler.HandleIndex) - // 设置API文档路由 - baseRouter.GET("/api-doc", pagesHandler.HandleAPIDoc) - // 设置TTS API路由 - 添加认证中间件 baseRouter.POST("/tts", middleware.TTSAuth(cfg.TTS.ApiKey), ttsHandler.HandleTTS) diff --git a/web/templates/api-doc.html b/web/templates/api-doc.html deleted file mode 100644 index fb57fbd..0000000 --- a/web/templates/api-doc.html +++ /dev/null @@ -1,737 +0,0 @@ - - - - - - API文档 - TTS服务 - - - - - - - -
-
-
-
-
-
-
-
-
-
-
- -
-
-
-

TTS服务 API文档

-

快速、高质量的文本转语音API服务

- - - -
- -
-
-

API概述

-

TTS服务API提供了简单而强大的方式将文本转换为自然语音。我们支持多种语言和声音,并允许您调节语速、语调以适应不同场景需求。

-

基础URL: {{.BasePath}}

-

所有API请求均使用HTTP协议,返回标准HTTP状态码表示请求结果。

-
- - -
-

文本转语音 API

- -

端点

- GET {{.BasePath}}/tts - -

参数

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
参数类型必选描述
tstring要转换的文本(需要进行URL编码)
vstring语音名称,使用short_name格式,默认: {{.DefaultVoice}}。可通过/voices接口获取所有可用语音
rstring语速调整,范围: -100%到100%,默认: {{.DefaultRate}}。正值加快语速,负值减慢语速
pstring语调调整,范围: -100%到100%,默认: {{.DefaultPitch}}。正值提高语调,负值降低语调
ostring输出音频格式,默认: {{.DefaultFormat}}。详见下方支持的格式列表
sstring情感风格,可用值取决于所选语音的style_list属性。例如:"cheerful"、"sad"等
-
- -

示例请求

-
curl "{{.BasePath}}/tts?t=%E4%BD%A0%E5%A5%BD%EF%BC%8C%E4%B8%96%E7%95%8C&v=zh-CN-XiaoxiaoNeural&r=0%25&p=0%25"
- -

另一个示例(带情感风格)

-
curl "{{.BasePath}}/tts?t=%E4%BB%8A%E5%A4%A9%E5%A4%A9%E6%B0%94%E7%9C%9F%E5%A5%BD&v=zh-CN-XiaoxiaoNeural&s=cheerful"
- -

响应

-

返回音频文件,内容类型取决于请求的输出格式。正常响应状态码为200。

- -

错误响应

-

如果请求参数有误或服务出现问题,将返回对应的HTTP错误码和错误消息。

-
- - - - - - - - - - - - - - - - - - - - - -
状态码描述
400参数错误或缺失必要参数
404请求的资源不存在
500服务器内部错误
-
-
- -
-

获取可用语音 API

- -

端点

- GET {{.BasePath}}/voices - -

参数

-
- - - - - - - - - - - - - - - - - - - - - - - -
参数类型必选描述
localestring筛选特定语言的语音,例如:zh-CN(中文)、en-US(英文)
genderstring筛选特定性别的语音,可选值:Male(男性)、Female(女性)
-
- -

示例请求

-
curl "{{.BasePath}}/voices?locale=zh-CN&gender=Female"
- -

响应

-

返回JSON格式的可用语音列表:

-
[
-  {
-    "name": "Microsoft Server Speech Text to Speech Voice (zh-CN, XiaoxiaoNeural)",
-    "display_name": "Xiaoxiao",
-    "local_name": "晓晓",
-    "short_name": "zh-CN-XiaoxiaoNeural",
-    "gender": "Female",
-    "locale": "zh-CN",
-    "locale_name": "中文(中国)",
-    "style_list": ["cheerful", "sad", "angry", "fearful", "disgruntled"]
-  },
-  ...
-]
-

响应字段说明:

-
    -
  • name:语音的完整名称
  • -
  • display_name:显示用名称(拉丁字符)
  • -
  • local_name:本地化名称
  • -
  • short_name:简短名称(用于API调用的v参数)
  • -
  • gender:性别(Male或Female)
  • -
  • locale:语言代码
  • -
  • locale_name:语言本地化名称
  • -
  • style_list:支持的情感风格列表(如有)
  • -
-
- -
-

兼容OpenAI接口 API

- -

语音合成

- POST {{.BasePath}}/v1/audio/speech - -

请求体 (JSON)

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
参数类型必选描述
modelstring当前仅支持值: "tts-1"
inputstring要转换的文本内容
voicestring声音名称,使用Microsoft语音格式,例如:ja-JP-KeitaNeural、zh-CN-XiaoxiaoNeural
speednumber语速调整,范围: 0.5到2.0,默认: 1.0
-
- -

示例请求

-
curl -X POST "{{.BasePath}}/v1/audio/speech" \
-  -H "Content-Type: application/json" \
-  -d '{
-    "model": "tts-1",
-    "input": "你好,世界!",
-    "voice": "zh-CN-XiaoxiaoNeural"
-  }'
- -

另一个示例(带速度调整)

-
curl -X POST "{{.BasePath}}/v1/audio/speech" \
-  -H "Content-Type: application/json" \
-  -d '{
-    "model": "tts-1",
-    "input": "こんにちは、世界!",
-    "voice": "ja-JP-NanamiNeural",
-    "speed": 1.2
-  }'
- -

响应

-

返回音频文件,内容类型取决于请求的输出格式。正常响应状态码为200。

- -

错误响应

-

如果请求有误,将返回JSON格式的错误信息:

-
{
-  "error": {
-    "message": "错误信息描述",
-    "type": "错误类型",
-    "code": "错误代码"
-  }
-}
-
- -
-

支持的输出格式

-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
格式名称描述
audio-16khz-32kbitrate-mono-mp3MP3格式,16kHz, 32kbps
audio-16khz-64kbitrate-mono-mp3MP3格式,16kHz, 64kbps
audio-16khz-128kbitrate-mono-mp3MP3格式,16kHz, 128kbps
audio-24khz-48kbitrate-mono-mp3MP3格式,24kHz, 48kbps
audio-24khz-96kbitrate-mono-mp3MP3格式,24kHz, 96kbps
audio-24khz-160kbitrate-mono-mp3MP3格式,24kHz, 160kbps
riff-16khz-16bit-mono-pcmWAV格式,16kHz
riff-24khz-16bit-mono-pcmWAV格式,24kHz
-
-
-
- - -
-
- - - - diff --git a/web/templates/index.html b/web/templates/index.html index 05ea30f..344745e 100644 --- a/web/templates/index.html +++ b/web/templates/index.html @@ -116,7 +116,7 @@ box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1); } - /* 为滑块输入元素添加毛玻璃效果 - 更新样式 */ + /* 为滑块输入元素添加毛玻璃效�� - 更新样式 */ input[type="range"] { -webkit-appearance: none; appearance: none; @@ -980,30 +980,7 @@

文本转语音 (TTS)

将文本转换为自然流畅的语音

- -
- - - - - - - - 主页 - - - - - - - - API文档 - -
+
@@ -1075,7 +1052,7 @@ @@ -1170,7 +1147,7 @@
@@ -1259,7 +1236,7 @@ // 创建渐变背景,从中间的0点向两边扩散 let gradient; if (val < 0) { - // 负值 - 从中点到左侧 + // 负值 - 从中��到左侧 const middlePos = 50; // 0值在滑块中间 const fillPos = middlePos + (percentage / 2); // 填充位置 gradient = `linear-gradient(to right, rgba(59, 130, 246, 0.1) ${fillPos}%, rgba(13, 47, 98, 0.2) ${fillPos}%)`; @@ -1310,4 +1287,5 @@ }); - \ No newline at end of file + +