Skip to content

豆包语音2.0音色支持情感,情绪,音量 - #2068

Merged
creamlike1024 merged 3 commits into
QuantumNous:mainfrom
feitianbubu:pr/doubao-speech-emotion
Oct 18, 2025
Merged

creamlike1024 merged 3 commits into
QuantumNous:mainfrom
feitianbubu:pr/doubao-speech-emotion

Conversation

@feitianbubu

@feitianbubu feitianbubu commented Oct 17, 2025 •

Copy link
Copy Markdown
Member

每个音色能支持的情感不同,
具体参考音色情感列表: https://www.volcengine.com/docs/6561/1257544
开心(happy),悲伤(sad),生气(angry),惊讶(surprised),恐惧(fear)...
所有在openai标准之外的参数按原厂格式写在metadata里, 支持所有格式
音色示例: 通过调整emotion参数

  1. 开心的女声
{
  "input": "你是一个好孩子",
  "model": "seed-tts-1.1",
  "response_format": "mp3",
  "speed": 1,
  "voice": "zh_female_shuangkuaisisi_emo_v2_mars_bigtts",
  "metadata":{
    "audio":{
      "emotion_scale":5,
      "enable_emotion":true,
      "emotion":"happy"
    }
  }
}
  1. 悲伤的女声
{
  "input": "你是一个好孩子",
  "model": "seed-tts-1.1",
  "response_format": "mp3",
  "speed": 1,
  "voice": "zh_female_shuangkuaisisi_emo_v2_mars_bigtts",
  "metadata":{
    "audio":{
      "emotion_scale":5,
      "enable_emotion":true,
      "emotion":"sad"
    }
  }
}

Summary by CodeRabbit

  • New Features

    • Audio requests now support instructions, streaming format specification, and custom metadata parameters
    • Enhanced audio configuration flexibility with new optional fields
  • Changes

    • Updated audio speed parameter to use direct values instead of automatic normalization

@coderabbitai

coderabbitai Bot commented Oct 17, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

The 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

Cohort / File(s) Summary
DTO Extension
dto/audio.go
Added three new optional fields to AudioRequest: Instructions (string), StreamFormat (string), and Metadata (json.RawMessage); imported encoding/json.
Volcengine Adapter Refactor
relay/channel/volcengine/adaptor.go, relay/channel/volcengine/tts.go
Updated ConvertAudioRequest to use request.Speed directly instead of mapSpeedRatio; added metadata unmarshalling into volcRequest struct; removed now-unused mapSpeedRatio function that previously clamped speed values.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • creamlike1024

Poem

🐰 Hark! New fields bloom in AudioRequest's heart,
Instructions and Metadata now play their part,
No clamping, just truth—speeds flow unbound,
Volcengine whispers secrets profound,
Audio flows freer, clearer, and true! 🎙️✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "豆包语音2.0音色支持情感选择" (Doubao Speech 2.0 Voice Support Emotion Selection) directly relates to the PR's stated objective of adding emotion selection support for the 豆包语音 2.0 TTS integration. The code changes enable this feature by adding a Metadata field to the AudioRequest struct and implementing metadata unmarshalling in the volcengine adaptor, allowing vendor-specific emotion parameters to be passed through. The title is clear, specific, and not vague; it accurately conveys the feature objective from the developer's perspective.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@feitianbubu feitianbubu changed the title 豆包语音2.0音色支持情感选择 豆包语音2.0音色支持情感,情绪,音量 Oct 17, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1ec664a and 525ca09.

📒 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, and Metadata fields enables flexible vendor-specific configuration. Using json.RawMessage for Metadata is 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 that mapSpeedRatio() removal is compatible with Volcengine API constraints.

The change removes the mapSpeedRatio() function, now passing request.Speed directly 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.

Comment on lines +78 to +83
// 同步扩展字段的厂商自定义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)
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

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.AppID and App.Token (lines 57-58)
  • App.Cluster (line 59)
  • User.UID (line 62)
  • Request.Model and Request.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.

Suggested change
// 同步扩展字段的厂商自定义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.

@creamlike1024
creamlike1024 merged commit 7156bf2 into QuantumNous:main Oct 18, 2025
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
…-emotion

豆包语音2.0音色支持情感,情绪,音量
jiutubaba pushed a commit to jiutubaba/fx-api that referenced this pull request May 17, 2026
…easoning-items-from-input

fix(openai): drop reasoning items from /v1/responses input on OAuth path
salem-2007 added a commit to salem-2007/new-api that referenced this pull request Sep 10, 2026
…-emotion

豆包语音2.0音色支持情感,情绪,音量
junjundesk pushed a commit to junjundesk/new-api that referenced this pull request Oct 3, 2026
…-emotion

豆包语音2.0音色支持情感,情绪,音量
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants