From 3356e267db3b0edb0ec687232c2734b895fbbdad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E9=94=A6=E5=BC=BA?= <1061669148@qq.com> Date: Tue, 11 Mar 2025 19:36:17 +0800 Subject: [PATCH] feat: add OpenAI compatible TTS endpoint and update documentation --- workers/src/index.js | 119 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 117 insertions(+), 2 deletions(-) diff --git a/workers/src/index.js b/workers/src/index.js index d154af4..a4ce9d7 100644 --- a/workers/src/index.js +++ b/workers/src/index.js @@ -86,6 +86,11 @@ async function handleRequest(request) { return response; } + // 添加 OpenAI 兼容接口路由 + if (path === '/v1/audio/speech' || path === '/audio/speech') { + return await handleOpenAITTS(request); + } + if(path === '/voices') { const l = (requestUrl.searchParams.get('l') || '').toLowerCase(); const f = requestUrl.searchParams.get('f'); @@ -260,7 +265,7 @@ async function handleRequest(request) {
@@ -301,7 +306,7 @@ async function handleRequest(request) {

- 支持 SSML 标签,可以精确控制语音合成效果 + 支持 SSML 标签和 OpenAI 兼容接口

@@ -325,6 +330,31 @@ async function handleRequest(request) {
  • p: 音调调整 (-100~100) [可选]
  • +

    OpenAI 兼容接口

    + /v1/audio/speech 或 /audio/speech +

    使用方式与 OpenAI TTS API 相同,支持以下参数:

    + + +
    +

    示例请求:

    + +curl ${baseUrl}/v1/audio/speech \\ + -H "Authorization: Bearer your-secret-api-key" \\ + -H "Content-Type: application/json" \\ + -d '{ + "model": "tts-1", + "input": "这是一个语音合成测试", + "voice": "alloy" + }' + +
    +

    获取语音列表 API

    /voices?l={locale}&f={format}