Repository navigation
豆包语音2.0音色支持情感,情绪,音量 - #2068
豆包语音2.0音色支持情感,情绪,音量#2068
Conversation
WalkthroughThe AudioRequest DTO is enhanced with three new fields (Instructions, StreamFormat, Metadata) to support richer audio configuration. The Volcengine adapter is updated to use raw speed values directly instead of clamping and to synchronize vendor-specific metadata through unmarshalling, eliminating the now-unused speed mapping function. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
dto/audio.go(1 hunks)relay/channel/volcengine/adaptor.go(2 hunks)relay/channel/volcengine/tts.go(0 hunks)
💤 Files with no reviewable changes (1)
- relay/channel/volcengine/tts.go
🧰 Additional context used
🧬 Code graph analysis (2)
dto/audio.go (1)
dto/openai_request.go (1)
ResponseFormat(14-17)
relay/channel/volcengine/adaptor.go (1)
common/json.go (1)
Unmarshal(9-11)
🔇 Additional comments (2)
dto/audio.go (1)
4-5: LGTM! Struct fields properly added to support vendor-specific metadata.The addition of
Instructions,StreamFormat, andMetadatafields enables flexible vendor-specific configuration. Usingjson.RawMessageforMetadatais the correct approach for allowing arbitrary vendor formats to be passed through without strict schema validation at this layer.Also applies to: 12-19
relay/channel/volcengine/adaptor.go (1)
50-50: Verify thatmapSpeedRatio()removal is compatible with Volcengine API constraints.The change removes the
mapSpeedRatio()function, now passingrequest.Speeddirectly to Volcengine without validation. OpenAI TTS API accepts speed in the range 0.25–4.0, but Volcengine API documentation shows conflicting limits (0.2–3.0 or 0.25–4.0 depending on endpoint). Without the old transformation function and no upstream validation in the adaptor, speeds at the upper end of OpenAI's range (e.g., 3.5–4.0) could exceed Volcengine's maximum if its true limit is 3.0, causing API failures.Confirm:
- What constraints did
mapSpeedRatio()enforce?- The exact speed limit for your specific Volcengine TTS endpoint.
- Whether error handling exists downstream to gracefully reject invalid speeds.
| // 同步扩展字段的厂商自定义metadata | ||
| if len(request.Metadata) > 0 { | ||
| if err = json.Unmarshal(request.Metadata, &volcRequest); err != nil { | ||
| return nil, fmt.Errorf("error unmarshalling metadata to volcengine request: %w", err) | ||
| } | ||
| } |
There was a problem hiding this comment.
Critical: Metadata unmarshalling can override authentication and critical fields.
The metadata is unmarshalled directly into volcRequest after authentication fields (AppID, Token) and other critical fields are set. This allows user-supplied metadata to overwrite any field in the struct, including:
App.AppIDandApp.Token(lines 57-58)App.Cluster(line 59)User.UID(line 62)Request.ModelandRequest.Operation(lines 74-73)
This creates a security risk where malicious users could inject arbitrary values into these fields.
Apply this diff to restrict metadata to only the Audio field:
- // 同步扩展字段的厂商自定义metadata
- if len(request.Metadata) > 0 {
- if err = json.Unmarshal(request.Metadata, &volcRequest); err != nil {
- return nil, fmt.Errorf("error unmarshalling metadata to volcengine request: %w", err)
- }
- }
+ // 同步扩展字段的厂商自定义metadata - only allow Audio field overrides
+ if len(request.Metadata) > 0 {
+ var audioMetadata struct {
+ Audio VolcengineTTSAudio `json:"audio"`
+ }
+ if err = json.Unmarshal(request.Metadata, &audioMetadata); err != nil {
+ return nil, fmt.Errorf("error unmarshalling metadata to volcengine request: %w", err)
+ }
+ // Merge only the Audio fields from metadata
+ if err = json.Unmarshal(request.Metadata, &audioMetadata); err == nil {
+ volcRequest.Audio = audioMetadata.Audio
+ }
+ }Alternatively, if you need more flexibility, create an allowlist of safe fields that can be overridden (e.g., only emotion-related fields within Audio).
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // 同步扩展字段的厂商自定义metadata | |
| if len(request.Metadata) > 0 { | |
| if err = json.Unmarshal(request.Metadata, &volcRequest); err != nil { | |
| return nil, fmt.Errorf("error unmarshalling metadata to volcengine request: %w", err) | |
| } | |
| } | |
| // 同步扩展字段的厂商自定义metadata - only allow Audio field overrides | |
| if len(request.Metadata) > 0 { | |
| var audioMetadata struct { | |
| Audio VolcengineTTSAudio `json:"audio"` | |
| } | |
| if err = json.Unmarshal(request.Metadata, &audioMetadata); err != nil { | |
| return nil, fmt.Errorf("error unmarshalling metadata to volcengine request: %w", err) | |
| } | |
| volcRequest.Audio = audioMetadata.Audio | |
| } |
🤖 Prompt for AI Agents
In relay/channel/volcengine/adaptor.go around lines 78 to 83, untrusted
request.Metadata is currently unmarshalled directly into volcRequest which
allows overriding critical auth and routing fields; change the logic to only
accept the Audio field (or an explicit allowlist) from metadata: unmarshal
request.Metadata into a narrow temporary type or a map, extract and assign only
the permitted Audio sub-structure (or only the whitelisted keys) onto
volcRequest, and reject or ignore any other fields so AppID, Token, Cluster,
User.UID, Request.Model, Request.Operation and other sensitive fields cannot be
overwritten.
…-emotion 豆包语音2.0音色支持情感,情绪,音量
…easoning-items-from-input fix(openai): drop reasoning items from /v1/responses input on OAuth path
…-emotion 豆包语音2.0音色支持情感,情绪,音量
…-emotion 豆包语音2.0音色支持情感,情绪,音量
每个音色能支持的情感不同,
具体参考音色情感列表: https://www.volcengine.com/docs/6561/1257544
开心(happy),悲伤(sad),生气(angry),惊讶(surprised),恐惧(fear)...
所有在openai标准之外的参数按原厂格式写在metadata里, 支持所有格式
音色示例: 通过调整emotion参数
Summary by CodeRabbit
New Features
Changes