Add doubao asr|增加豆包语音识别模型支持 - #3330
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughAdds Volcengine ASR (audio transcription) support: new ASR request/response types and build/handle logic, adapter branching for a transcription relay mode, audio format detection, header/URL routing, and updated OpenAPI description for the transcription endpoint. (50 words) Changes
Sequence DiagramsequenceDiagram
participant Client
participant Relay as Relay Adapter\n(Volcengine)
participant ASR as Volcengine ASR\nService
Client->>Relay: POST /v1/audio/transcriptions (multipart/form + file)
Relay->>Relay: buildASRRequest() - parse form, read file, base64 encode, detect format, resolve model
Relay->>Relay: ConvertAudioRequest() - branch on RelayModeAudioTranscription, set responseFormat context
Relay->>Relay: SetupRequestHeader() - set ASR-specific headers (X-Api-*)
Relay->>ASR: POST bigmodel/recognize/flash (JSON body + headers)
ASR-->>Relay: HTTP response (X-Api-Status-Code, code, result.text)
Relay->>Relay: handleASRResponse() - unmarshal, extract transcript, format as JSON or plain text
Relay-->>Client: Transcription response (transcript [+ usage])
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip CodeRabbit can scan for known vulnerabilities in your dependencies using OSV Scanner.OSV Scanner will automatically detect and report security vulnerabilities in your project's dependencies. No additional configuration is required. |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
relay/channel/volcengine/asr.go (1)
178-201: Note:srtandvttresponse formats are not supported.OpenAI Whisper supports
srtandvttformats in addition tojson,verbose_json, andtext. These are handled gracefully with an error message, which is acceptable. Consider documenting this limitation if users expect full Whisper API compatibility.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@relay/channel/volcengine/asr.go` around lines 178 - 201, The ASR handler's responseFormat switch (checking variable responseFormat in volcengine ASR code) does not support "srt" and "vtt"; add explicit documentation and a clearer error message: update the project docs/README and the comment for the volcengine ASR handler to state that "srt" and "vtt" are not supported, and modify the unsupported-response_format error text returned by this switch to list the unsupported formats (e.g., include "srt" and "vtt") so callers see that limitation when invoking the handler.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@relay/channel/volcengine/asr.go`:
- Around line 134-143: In handleASRResponse ensure resp.Body is always closed by
moving the defer resp.Body.Close() to immediately after obtaining resp (before
calling io.ReadAll); this guarantees the response body is closed even if
io.ReadAll(resp.Body) returns an error so that no resource leak occurs when
handling volcengine ASR responses.
---
Nitpick comments:
In `@relay/channel/volcengine/asr.go`:
- Around line 178-201: The ASR handler's responseFormat switch (checking
variable responseFormat in volcengine ASR code) does not support "srt" and
"vtt"; add explicit documentation and a clearer error message: update the
project docs/README and the comment for the volcengine ASR handler to state that
"srt" and "vtt" are not supported, and modify the unsupported-response_format
error text returned by this switch to list the unsupported formats (e.g.,
include "srt" and "vtt") so callers see that limitation when invoking the
handler.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c5ba1ceb-709f-4a7b-9f80-91ed72ed142c
📒 Files selected for processing (4)
docs/openapi/relay.jsonrelay/channel/volcengine/adaptor.gorelay/channel/volcengine/asr.gorelay/channel/volcengine/constants.go
…formats in ASR handling
This comment was marked as spam.
This comment was marked as spam.
|
主分支里好像没更新这块的内容,不过好在我在你的分支里找到了这段代码,感谢大佬解决了这个问题 |
|
但是目前new-api在语音这块的计费还没办法按小时计费,而且目前豆包语音也不是异步实现的,还要改好多 |
51fdfc5 to
2b6f1df
Compare
改动描述
为
VolcEngine渠道新增了 Doubao ASR 支持,使项目可以通过现有 OpenAI 兼容接口/v1/audio/transcriptions转发到豆包语音识别服务,实现“上传音频文件,返回转录文本”。实现目标是保持用户侧调用方式不变:
multipart/form-dataappid|access_token配置方式改动内容
relay/channel/volcengine/asr.goRelayModeAudioTranscription下:filerelay/channel/volcengine/adaptor.go/v1/audio/transcriptions对应的 VolcEngine 分支:X-Api-App-Key/X-Api-Access-Key/X-Api-Resource-Id/X-Api-Request-Id/X-Api-Sequenceresponse_format映射回 OpenAI 兼容输出relay/channel/volcengine/constants.gobigmodel(doubao asr 默认模型名称) 加入 VolcEngine 模型列表,便于渠道配置和模型选择docs/openapi/relay.json/v1/audio/transcriptions说明中补充:该接口除 Whisper 外,也可通过 VolcEngine/Doubao 语音渠道转发到豆包 ASR接口映射说明
客户端入口仍为:
POST /v1/audio/transcriptions本 PR 内部映射到 Doubao 官方 flash ASR 接口:
POST https://openspeech.bytedance.com/api/v3/auc/bigmodel/recognize/flash当前支持的返回格式:
response_format为空或json:返回{"text":"..."}response_format=text:返回纯文本参考的 Doubao 官方文档
另外也核对了标准版两段式接口文档,但考虑到该方式需要调两次api(submit/query)缺乏通用性,因此本 PR 未采用该方案:
为什么采用极速版接口
/v1/audio/transcriptions的同步接口语义,即一次请求直接返回结果测试方案
已执行:
结果:
已执行:
结果:
使用真实 Doubao 凭证和测试音频文件,直接请求官方 ASR 接口:
X-Api-Status-Code: 20000000欢迎语使用阿里云。本地启动后可这样验证:
预期结果:
{"text":"欢迎使用阿里云。"}客户端测试
Summary by CodeRabbit
New Features
Documentation