feat: 新增音频格式与采样率配置,完善OpenAI兼容格式映射

1.  新增BYTEDANCE_TTS_FORMAT和BYTEDANCE_TTS_SAMPLE_RATE环境变量配置
2.  实现OpenAI TTS格式到火山API格式的映射转换
3.  自动处理wav格式:内部用pcm请求后封装标准WAV头
4.  动态设置响应Content-Type,适配不同输出格式
5.  更新文档与配置示例,完善日志与错误处理
This commit is contained in:
sun
2026-06-27 23:28:35 +08:00
parent 82cc68e7ee
commit 21b86bfcfe
7 changed files with 269 additions and 82 deletions
+8 -2
View File
@@ -115,8 +115,14 @@ func OpenaiTTSHandler(w http.ResponseWriter, r *http.Request) {
speed = common.MaxSpeed
}
// 将 OpenAI response_format 映射为火山 API 支持的格式
var requestFormat string
if req.ResponseFormat != "" {
requestFormat = volcano.MapOpenAIFormat(req.ResponseFormat)
}
ttsStart := time.Now()
result, err := volcano.Synthesis(&setting.TTSConfig, volcanoClient, req.Input, speed, req.Voice)
result, err := volcano.Synthesis(&setting.TTSConfig, volcanoClient, req.Input, speed, req.Voice, requestFormat)
duration := time.Since(ttsStart)
if err != nil {
@@ -129,7 +135,7 @@ func OpenaiTTSHandler(w http.ResponseWriter, r *http.Request) {
service.GlobalStats.AddRequest(true, duration, "")
w.Header().Set("Content-Type", "audio/wav")
w.Header().Set("Content-Type", volcano.FormatContentType(result.Format))
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(result.AudioData)))
w.Header().Set("X-Request-Id", result.ReqID)
w.WriteHeader(http.StatusOK)