324 lines
21 KiB
HTML
324 lines
21 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="zh-CN">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>API文档 - TTS服务</title>
|
||
<script src="https://cdn.tailwindcss.com"></script>
|
||
<link rel="icon" type="image/svg+xml" href="{{.BasePath}}/static/icons/favicon.svg">
|
||
<meta name="description" content="TTS服务API文档">
|
||
</head>
|
||
<body class="text-gray-800 p-4 font-sans">
|
||
<div class="max-w-4xl mx-auto">
|
||
<header class="text-center mb-8 py-4">
|
||
<h1 class="text-4xl font-bold mb-2 text-gray-800">TTS服务 API文档</h1>
|
||
<p class="text-xl text-gray-600 mb-4">快速、高质量的文本转语音API服务</p>
|
||
<nav class="flex justify-center mt-4">
|
||
<a href="{{.BasePath}}/" class="mx-2 px-3 py-1 rounded text-blue-500 hover:bg-blue-500 hover:text-white transition-colors">主页</a>
|
||
<a href="{{.BasePath}}/api-doc" class="mx-2 px-3 py-1 rounded bg-blue-500 text-white">API文档</a>
|
||
</nav>
|
||
</header>
|
||
|
||
<main>
|
||
<section class="bg-white rounded-lg shadow-md p-6 mb-6">
|
||
<h2 class="text-2xl font-bold mb-4 pb-2 border-b border-gray-200 text-gray-800">API概述</h2>
|
||
<p class="mb-3">TTS服务API提供了简单而强大的方式将文本转换为自然语音。我们支持多种语言和声音,并允许您调节语速、语调以适应不同场景需求。</p>
|
||
<p class="mb-3">基础URL: <code class="bg-gray-100 px-2 py-1 rounded text-sm font-mono">{{.BasePath}}</code></p>
|
||
<p class="mb-3">所有API请求均使用HTTP协议,返回标准HTTP状态码表示请求结果。</p>
|
||
</section>
|
||
|
||
<section class="bg-white rounded-lg shadow-md p-6 mb-6">
|
||
<h2 class="text-2xl font-bold mb-4 pb-2 border-b border-gray-200 text-gray-800">文本转语音 API</h2>
|
||
|
||
<h3 class="text-xl font-semibold text-blue-600 mt-6 mb-2">端点</h3>
|
||
<code class="block bg-gray-100 p-3 rounded text-sm font-mono mb-4">GET {{.BasePath}}/tts</code>
|
||
|
||
<h3 class="text-xl font-semibold text-blue-600 mt-6 mb-2">参数</h3>
|
||
<div class="overflow-x-auto">
|
||
<table class="min-w-full bg-white mb-6">
|
||
<thead>
|
||
<tr>
|
||
<th class="py-3 px-4 bg-gray-100 font-semibold text-sm text-left border-b">参数</th>
|
||
<th class="py-3 px-4 bg-gray-100 font-semibold text-sm text-left border-b">类型</th>
|
||
<th class="py-3 px-4 bg-gray-100 font-semibold text-sm text-left border-b">必选</th>
|
||
<th class="py-3 px-4 bg-gray-100 font-semibold text-sm text-left border-b">描述</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td class="py-2 px-4 border-b"><code class="bg-gray-100 px-1 rounded text-sm font-mono">t</code></td>
|
||
<td class="py-2 px-4 border-b">string</td>
|
||
<td class="py-2 px-4 border-b">是</td>
|
||
<td class="py-2 px-4 border-b">要转换的文本(需要进行URL编码)</td>
|
||
</tr>
|
||
<tr>
|
||
<td class="py-2 px-4 border-b"><code class="bg-gray-100 px-1 rounded text-sm font-mono">v</code></td>
|
||
<td class="py-2 px-4 border-b">string</td>
|
||
<td class="py-2 px-4 border-b">否</td>
|
||
<td class="py-2 px-4 border-b">语音名称,使用short_name格式,默认: {{.DefaultVoice}}。可通过/voices接口获取所有可用语音</td>
|
||
</tr>
|
||
<tr>
|
||
<td class="py-2 px-4 border-b"><code class="bg-gray-100 px-1 rounded text-sm font-mono">r</code></td>
|
||
<td class="py-2 px-4 border-b">string</td>
|
||
<td class="py-2 px-4 border-b">否</td>
|
||
<td class="py-2 px-4 border-b">语速调整,范围: -100%到100%,默认: {{.DefaultRate}}。正值加快语速,负值减慢语速</td>
|
||
</tr>
|
||
<tr>
|
||
<td class="py-2 px-4 border-b"><code class="bg-gray-100 px-1 rounded text-sm font-mono">p</code></td>
|
||
<td class="py-2 px-4 border-b">string</td>
|
||
<td class="py-2 px-4 border-b">否</td>
|
||
<td class="py-2 px-4 border-b">语调调整,范围: -100%到100%,默认: {{.DefaultPitch}}。正值提高语调,负值降低语调</td>
|
||
</tr>
|
||
<tr>
|
||
<td class="py-2 px-4 border-b"><code class="bg-gray-100 px-1 rounded text-sm font-mono">o</code></td>
|
||
<td class="py-2 px-4 border-b">string</td>
|
||
<td class="py-2 px-4 border-b">否</td>
|
||
<td class="py-2 px-4 border-b">输出音频格式,默认: {{.DefaultFormat}}。详见下方支持的格式列表</td>
|
||
</tr>
|
||
<tr>
|
||
<td class="py-2 px-4 border-b"><code class="bg-gray-100 px-1 rounded text-sm font-mono">s</code></td>
|
||
<td class="py-2 px-4 border-b">string</td>
|
||
<td class="py-2 px-4 border-b">否</td>
|
||
<td class="py-2 px-4 border-b">情感风格,可用值取决于所选语音的style_list属性。例如:"cheerful"、"sad"等</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
|
||
<h3 class="text-xl font-semibold text-blue-600 mt-6 mb-2">示例请求</h3>
|
||
<pre class="bg-gray-800 text-gray-100 p-4 rounded overflow-x-auto mb-4"><code>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"</code></pre>
|
||
|
||
<h3 class="text-xl font-semibold text-blue-600 mt-6 mb-2">另一个示例(带情感风格)</h3>
|
||
<pre class="bg-gray-800 text-gray-100 p-4 rounded overflow-x-auto mb-4"><code>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"</code></pre>
|
||
|
||
<h3 class="text-xl font-semibold text-blue-600 mt-6 mb-2">响应</h3>
|
||
<p class="mb-3">返回音频文件,内容类型取决于请求的输出格式。正常响应状态码为200。</p>
|
||
|
||
<h3 class="text-xl font-semibold text-blue-600 mt-6 mb-2">错误响应</h3>
|
||
<p class="mb-3">如果请求参数有误或服务出现问题,将返回对应的HTTP错误码和错误消息。</p>
|
||
<div class="overflow-x-auto">
|
||
<table class="min-w-full bg-white mb-6">
|
||
<thead>
|
||
<tr>
|
||
<th class="py-3 px-4 bg-gray-100 font-semibold text-sm text-left border-b">状态码</th>
|
||
<th class="py-3 px-4 bg-gray-100 font-semibold text-sm text-left border-b">描述</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td class="py-2 px-4 border-b">400</td>
|
||
<td class="py-2 px-4 border-b">参数错误或缺失必要参数</td>
|
||
</tr>
|
||
<tr>
|
||
<td class="py-2 px-4 border-b">404</td>
|
||
<td class="py-2 px-4 border-b">请求的资源不存在</td>
|
||
</tr>
|
||
<tr>
|
||
<td class="py-2 px-4 border-b">500</td>
|
||
<td class="py-2 px-4 border-b">服务器内部错误</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</section>
|
||
|
||
<section class="bg-white rounded-lg shadow-md p-6 mb-6">
|
||
<h2 class="text-2xl font-bold mb-4 pb-2 border-b border-gray-200 text-gray-800">获取可用语音 API</h2>
|
||
|
||
<h3 class="text-xl font-semibold text-blue-600 mt-6 mb-2">端点</h3>
|
||
<code class="block bg-gray-100 p-3 rounded text-sm font-mono mb-4">GET {{.BasePath}}/voices</code>
|
||
|
||
<h3 class="text-xl font-semibold text-blue-600 mt-6 mb-2">参数</h3>
|
||
<div class="overflow-x-auto">
|
||
<table class="min-w-full bg-white mb-6">
|
||
<thead>
|
||
<tr>
|
||
<th class="py-3 px-4 bg-gray-100 font-semibold text-sm text-left border-b">参数</th>
|
||
<th class="py-3 px-4 bg-gray-100 font-semibold text-sm text-left border-b">类型</th>
|
||
<th class="py-3 px-4 bg-gray-100 font-semibold text-sm text-left border-b">必选</th>
|
||
<th class="py-3 px-4 bg-gray-100 font-semibold text-sm text-left border-b">描述</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td class="py-2 px-4 border-b"><code class="bg-gray-100 px-1 rounded text-sm font-mono">locale</code></td>
|
||
<td class="py-2 px-4 border-b">string</td>
|
||
<td class="py-2 px-4 border-b">否</td>
|
||
<td class="py-2 px-4 border-b">筛选特定语言的语音,例如:zh-CN(中文)、en-US(英文)</td>
|
||
</tr>
|
||
<tr>
|
||
<td class="py-2 px-4 border-b"><code class="bg-gray-100 px-1 rounded text-sm font-mono">gender</code></td>
|
||
<td class="py-2 px-4 border-b">string</td>
|
||
<td class="py-2 px-4 border-b">否</td>
|
||
<td class="py-2 px-4 border-b">筛选特定性别的语音,可选值:Male(男性)、Female(女性)</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
|
||
<h3 class="text-xl font-semibold text-blue-600 mt-6 mb-2">示例请求</h3>
|
||
<pre class="bg-gray-800 text-gray-100 p-4 rounded overflow-x-auto mb-4"><code>curl "{{.BasePath}}/voices?locale=zh-CN&gender=Female"</code></pre>
|
||
|
||
<h3 class="text-xl font-semibold text-blue-600 mt-6 mb-2">响应</h3>
|
||
<p class="mb-3">返回JSON格式的可用语音列表:</p>
|
||
<pre class="bg-gray-800 text-gray-100 p-4 rounded overflow-x-auto mb-4"><code>[
|
||
{
|
||
"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"]
|
||
},
|
||
...
|
||
]</code></pre>
|
||
<p class="mb-3">响应字段说明:</p>
|
||
<ul class="list-disc pl-5 mb-4 space-y-1">
|
||
<li><span class="font-semibold">name</span>:语音的完整名称</li>
|
||
<li><span class="font-semibold">display_name</span>:显示用名称(拉丁字符)</li>
|
||
<li><span class="font-semibold">local_name</span>:本地化名称</li>
|
||
<li><span class="font-semibold">short_name</span>:简短名称(用于API调用的v参数)</li>
|
||
<li><span class="font-semibold">gender</span>:性别(Male或Female)</li>
|
||
<li><span class="font-semibold">locale</span>:语言代码</li>
|
||
<li><span class="font-semibold">locale_name</span>:语言本地化名称</li>
|
||
<li><span class="font-semibold">style_list</span>:支持的情感风格列表(如有)</li>
|
||
</ul>
|
||
</section>
|
||
|
||
<section class="bg-white rounded-lg shadow-md p-6 mb-6">
|
||
<h2 class="text-2xl font-bold mb-4 pb-2 border-b border-gray-200 text-gray-800">兼容OpenAI接口 API</h2>
|
||
|
||
<h3 class="text-xl font-semibold text-blue-600 mt-6 mb-2">语音合成</h3>
|
||
<code class="block bg-gray-100 p-3 rounded text-sm font-mono mb-4">POST {{.BasePath}}/v1/audio/speech</code>
|
||
|
||
<h3 class="text-xl font-semibold text-blue-600 mt-6 mb-2">请求体 (JSON)</h3>
|
||
<div class="overflow-x-auto">
|
||
<table class="min-w-full bg-white mb-6">
|
||
<thead>
|
||
<tr>
|
||
<th class="py-3 px-4 bg-gray-100 font-semibold text-sm text-left border-b">参数</th>
|
||
<th class="py-3 px-4 bg-gray-100 font-semibold text-sm text-left border-b">类型</th>
|
||
<th class="py-3 px-4 bg-gray-100 font-semibold text-sm text-left border-b">必选</th>
|
||
<th class="py-3 px-4 bg-gray-100 font-semibold text-sm text-left border-b">描述</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td class="py-2 px-4 border-b"><code class="bg-gray-100 px-1 rounded text-sm font-mono">model</code></td>
|
||
<td class="py-2 px-4 border-b">string</td>
|
||
<td class="py-2 px-4 border-b">是</td>
|
||
<td class="py-2 px-4 border-b">当前仅支持值: "tts-1"</td>
|
||
</tr>
|
||
<tr>
|
||
<td class="py-2 px-4 border-b"><code class="bg-gray-100 px-1 rounded text-sm font-mono">input</code></td>
|
||
<td class="py-2 px-4 border-b">string</td>
|
||
<td class="py-2 px-4 border-b">是</td>
|
||
<td class="py-2 px-4 border-b">要转换的文本内容</td>
|
||
</tr>
|
||
<tr>
|
||
<td class="py-2 px-4 border-b"><code class="bg-gray-100 px-1 rounded text-sm font-mono">voice</code></td>
|
||
<td class="py-2 px-4 border-b">string</td>
|
||
<td class="py-2 px-4 border-b">是</td>
|
||
<td class="py-2 px-4 border-b">声音名称,使用Microsoft语音格式,例如:ja-JP-KeitaNeural、zh-CN-XiaoxiaoNeural</td>
|
||
</tr>
|
||
<tr>
|
||
<td class="py-2 px-4 border-b"><code class="bg-gray-100 px-1 rounded text-sm font-mono">speed</code></td>
|
||
<td class="py-2 px-4 border-b">number</td>
|
||
<td class="py-2 px-4 border-b">否</td>
|
||
<td class="py-2 px-4 border-b">语速调整,范围: 0.5到2.0,默认: 1.0</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
|
||
<h3 class="text-xl font-semibold text-blue-600 mt-6 mb-2">示例请求</h3>
|
||
<pre class="bg-gray-800 text-gray-100 p-4 rounded overflow-x-auto mb-4"><code>curl -X POST "{{.BasePath}}/v1/audio/speech" \
|
||
-H "Content-Type: application/json" \
|
||
-d '{
|
||
"model": "tts-1",
|
||
"input": "你好,世界!",
|
||
"voice": "zh-CN-XiaoxiaoNeural"
|
||
}'</code></pre>
|
||
|
||
<h3 class="text-xl font-semibold text-blue-600 mt-6 mb-2">另一个示例(带速度调整)</h3>
|
||
<pre class="bg-gray-800 text-gray-100 p-4 rounded overflow-x-auto mb-4"><code>curl -X POST "{{.BasePath}}/v1/audio/speech" \
|
||
-H "Content-Type: application/json" \
|
||
-d '{
|
||
"model": "tts-1",
|
||
"input": "こんにちは、世界!",
|
||
"voice": "ja-JP-NanamiNeural",
|
||
"speed": 1.2
|
||
}'</code></pre>
|
||
|
||
<h3 class="text-xl font-semibold text-blue-600 mt-6 mb-2">响应</h3>
|
||
<p class="mb-3">返回音频文件,内容类型取决于请求的输出格式。正常响应状态码为200。</p>
|
||
|
||
<h3 class="text-xl font-semibold text-blue-600 mt-6 mb-2">错误响应</h3>
|
||
<p class="mb-3">如果请求有误,将返回JSON格式的错误信息:</p>
|
||
<pre class="bg-gray-800 text-gray-100 p-4 rounded overflow-x-auto mb-4"><code>{
|
||
"error": {
|
||
"message": "错误信息描述",
|
||
"type": "错误类型",
|
||
"code": "错误代码"
|
||
}
|
||
}</code></pre>
|
||
</section>
|
||
|
||
<section class="bg-white rounded-lg shadow-md p-6 mb-6">
|
||
<h2 class="text-2xl font-bold mb-4 pb-2 border-b border-gray-200 text-gray-800">支持的输出格式</h2>
|
||
<div class="overflow-x-auto">
|
||
<table class="min-w-full bg-white mb-6">
|
||
<thead>
|
||
<tr>
|
||
<th class="py-3 px-4 bg-gray-100 font-semibold text-sm text-left border-b">格式名称</th>
|
||
<th class="py-3 px-4 bg-gray-100 font-semibold text-sm text-left border-b">描述</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr>
|
||
<td class="py-2 px-4 border-b"><code class="bg-gray-100 px-1 rounded text-sm font-mono">audio-16khz-32kbitrate-mono-mp3</code></td>
|
||
<td class="py-2 px-4 border-b">MP3格式,16kHz, 32kbps</td>
|
||
</tr>
|
||
<tr>
|
||
<td class="py-2 px-4 border-b"><code class="bg-gray-100 px-1 rounded text-sm font-mono">audio-16khz-64kbitrate-mono-mp3</code></td>
|
||
<td class="py-2 px-4 border-b">MP3格式,16kHz, 64kbps</td>
|
||
</tr>
|
||
<tr>
|
||
<td class="py-2 px-4 border-b"><code class="bg-gray-100 px-1 rounded text-sm font-mono">audio-16khz-128kbitrate-mono-mp3</code></td>
|
||
<td class="py-2 px-4 border-b">MP3格式,16kHz, 128kbps</td>
|
||
</tr>
|
||
<tr>
|
||
<td class="py-2 px-4 border-b"><code class="bg-gray-100 px-1 rounded text-sm font-mono">audio-24khz-48kbitrate-mono-mp3</code></td>
|
||
<td class="py-2 px-4 border-b">MP3格式,24kHz, 48kbps</td>
|
||
</tr>
|
||
<tr>
|
||
<td class="py-2 px-4 border-b"><code class="bg-gray-100 px-1 rounded text-sm font-mono">audio-24khz-96kbitrate-mono-mp3</code></td>
|
||
<td class="py-2 px-4 border-b">MP3格式,24kHz, 96kbps</td>
|
||
</tr>
|
||
<tr>
|
||
<td class="py-2 px-4 border-b"><code class="bg-gray-100 px-1 rounded text-sm font-mono">audio-24khz-160kbitrate-mono-mp3</code></td>
|
||
<td class="py-2 px-4 border-b">MP3格式,24kHz, 160kbps</td>
|
||
</tr>
|
||
<tr>
|
||
<td class="py-2 px-4 border-b"><code class="bg-gray-100 px-1 rounded text-sm font-mono">riff-16khz-16bit-mono-pcm</code></td>
|
||
<td class="py-2 px-4 border-b">WAV格式,16kHz</td>
|
||
</tr>
|
||
<tr>
|
||
<td class="py-2 px-4 border-b"><code class="bg-gray-100 px-1 rounded text-sm font-mono">riff-24khz-16bit-mono-pcm</code></td>
|
||
<td class="py-2 px-4 border-b">WAV格式,24kHz</td>
|
||
</tr>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</section>
|
||
</main>
|
||
|
||
<footer class="text-center mt-10 py-4 text-gray-600 text-sm">
|
||
<p>© 2025 TTS服务 | <a href="{{.BasePath}}/" class="text-blue-500 hover:underline">返回主页</a></p>
|
||
</footer>
|
||
</div>
|
||
</body>
|
||
</html>
|