Skip to content

Conversation

@duwenhan2byte
Copy link
Collaborator

@duwenhan2byte duwenhan2byte commented Aug 12, 2025

Summary by CodeRabbit

  • New Features

    • Add support for voice emotions in speech synthesis with optional emotion and intensity controls.
    • Voice profiles now indicate supported emotions with recommended intensity ranges.
    • Real-time audio outputs can include emotion metadata for richer playback.
  • Chores

    • Bump SDK version to 1.3.8.
    • Add changelog entries documenting voice emotion support.

@CLAassistant
Copy link

CLAassistant commented Aug 12, 2025

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link

coderabbitai bot commented Aug 12, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Adds voice-emotion support to the JS SDK: three changelog entries; package version bump; optional emotion and emotion_scale on speech requests; new emotion metadata types for voices; websocket OutputAudio extended with emotion_config.

Changes

Cohort / File(s) Summary
Changelogs
common/changes/@coze/api/feat-voice-emotion_2025-08-12-08-11.json, common/changes/@coze/api/feat-voice-emotion_2025-08-12-08-14.json, common/changes/@coze/api/feat-voice-emotion_2025-08-12-08-15.json
Add changeset entries for @coze/api: minor change "support voice emotions" (author email present).
Package version
packages/coze-js/package.json
Bump version 1.3.7 → 1.3.8 (version field only).
Speech request
packages/coze-js/src/resources/audio/speech/speech.ts
CreateSpeechReq adds optional emotion?: string and emotion_scale?: number; create() forwards params as before.
Voice metadata
packages/coze-js/src/resources/audio/voices/voices.ts
New exported Interval and EmotionInfo interfaces; Voice gains optional support_emotions?: EmotionInfo[].
Websocket audio output
packages/coze-js/src/resources/websockets/types.ts
OutputAudio adds optional emotion_config?: { emotion?: string; emotion_scale?: number }.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant SDK as coze-js (Speech)
  participant API
  rect rgb(235,245,255)
  Client->>SDK: create({ text, voice_id, emotion?, emotion_scale? })
  SDK->>API: POST /audio/speech (payload includes emotion fields)
  API-->>SDK: Audio response
  SDK-->>Client: Return audio data/stream
  end
Loading
sequenceDiagram
  participant Client
  participant SDK as coze-js (WS)
  participant Server
  rect rgb(245,255,235)
  Client->>SDK: Open WS, request audio
  Server-->>SDK: OutputAudio { ..., emotion_config? }
  SDK-->>Client: Emit OutputAudio with emotion_config
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Pay attention to public type additions (interfaces and request fields) for backward compatibility and correct exports.
  • Verify documentation/comments (Chinese wording) and default sample_rate behavior in create() remains unchanged.
  • Confirm package.json version bump is intentional and matches release process.

Possibly related PRs

Suggested reviewers

  • tomasyu985
  • Tecvan-fe

Poem

I twitch my ears at tones anew,
Small hops of feeling threaded through.
Emotions mapped in scale and name,
Voices dance and call my name.
I nibble bytes and hum with glee. 🐇🎶

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e1fa501 and 95138de.

📒 Files selected for processing (7)
  • common/changes/@coze/api/feat-voice-emotion_2025-08-12-08-11.json (1 hunks)
  • common/changes/@coze/api/feat-voice-emotion_2025-08-12-08-14.json (1 hunks)
  • common/changes/@coze/api/feat-voice-emotion_2025-08-12-08-15.json (1 hunks)
  • packages/coze-js/package.json (1 hunks)
  • packages/coze-js/src/resources/audio/speech/speech.ts (1 hunks)
  • packages/coze-js/src/resources/audio/voices/voices.ts (2 hunks)
  • packages/coze-js/src/resources/websockets/types.ts (1 hunks)

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.

@duwenhan2byte duwenhan2byte force-pushed the feat/voice-emotion branch 2 times, most recently from 645bb66 to e1fa501 Compare August 12, 2025 08:15
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (6)
packages/coze-js/src/resources/websockets/types.ts (1)

521-527: Clarify docs, add bounds, and consider extracting a reusable EmotionConfig type

Good addition. Two suggestions:

  • Documentation: add English and specify bounds/default for emotion_scale to align with speech.ts.
  • Type reuse: consider a shared EmotionConfig type to avoid divergence across modules.

Apply doc improvements:

-  /** 输出语音的情感配置 */
+  /** 输出语音的情感配置 | Emotion configuration for the output audio */
   emotion_config?: {
-    /** 情感 */
+    /** 情感 | Emotion name (should be one of the voice's supported emotions) */
     emotion?: string;
-    /** 情绪值 */
+    /** 情绪值,范围 [1,5],默认为 4,通常保留一位小数即可 | Emotion intensity in [1,5], default 4 (usually one decimal place is sufficient) */
     emotion_scale?: number;
   };

Optional: extract and reuse a shared type to keep REST/WebSocket in sync.

// e.g. in a shared types module (resources/audio/types.ts)
export interface EmotionConfig {
  emotion?: string;
  emotion_scale?: number; // [1,5], default 4
}

// Then here:
emotion_config?: EmotionConfig;
common/changes/@coze/api/feat-voice-emotion_2025-08-12-08-11.json (1)

1-11: Nit: prefer sentence case in changelog comments

For consistency with typical changelog styles, consider capitalizing the first letter.

-      "comment": "support voice emotions",
+      "comment": "Support voice emotions",
packages/coze-js/src/resources/audio/speech/speech.ts (1)

46-49: Document bounds/default and add English to match file style; optionally validate input

  • Add English and specify bounds/default for emotion_scale to align with WebSocket docs and improve DX.
  • Optional: clamp or validate emotion_scale in create() to avoid server-side validation errors.

Doc improvements:

-  /** 情感,默认为空 */
+  /** 情感(可选)| Emotion (optional). Should match one of the voice's supported emotions if provided. */
   emotion?: string;
-  /** 情感强度,[1,5],默认为4,通常保留一位小数即可 */
+  /** 情感强度 | Emotion intensity in [1,5], default 4 (usually one decimal place is sufficient). */
   emotion_scale?: number;

Optional validation (outside the selected range), e.g. clamp before sending:

// Inside create()
const payload = {
  ...params,
  sample_rate: params.sample_rate || 24000,
  ...(typeof params.emotion_scale === 'number'
    ? { emotion_scale: Math.min(5, Math.max(1, params.emotion_scale)) }
    : {}),
};
const response = await this._client.post<CreateSpeechReq, ArrayBuffer>(
  apiUrl,
  payload,
  false,
  mergeConfig(options, { responseType: 'arraybuffer' }),
);
packages/coze-js/src/resources/audio/voices/voices.ts (3)

106-111: Add concise bilingual docs for Interval to improve discoverability

Adding minimal JSDoc helps SDK users understand the semantics quickly.

-export interface Interval {
-  min?: number;
-  max?: number;
-  default?: number;
-}
+/** 数值区间(闭区间)| Numeric interval (inclusive) */
+export interface Interval {
+  /** 最小值 | Minimum value (inclusive) */
+  min?: number;
+  /** 最大值 | Maximum value (inclusive) */
+  max?: number;
+  /** 默认值 | Default value */
+  default?: number;
+}

112-117: Doc the emotion fields and relate the scale interval to the [1,5] guidance

This connects voice metadata with request parameters.

-export interface EmotionInfo {
-  emotion?: string;
-  display_name?: string;
-  emotion_scale_interval?: Interval;
-}
+export interface EmotionInfo {
+  /** 情感标识 | Emotion identifier (e.g., neutral/happy/sad) */
+  emotion?: string;
+  /** 展示名称 | Human-readable display name */
+  display_name?: string;
+  /** 情感强度区间 | Allowed emotion intensity interval (typically within [1,5]) */
+  emotion_scale_interval?: Interval;
+}

140-142: Add English to the new Voice.support_emotions field doc

Keeps the file’s bilingual doc style consistent.

-  /** 支持的情感列表 */
+  /** Supported emotions of this voice | 支持的情感列表 */
   support_emotions?: EmotionInfo[];
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3068887 and da74135.

📒 Files selected for processing (5)
  • common/changes/@coze/api/feat-voice-emotion_2025-08-12-08-11.json (1 hunks)
  • packages/coze-js/package.json (3 hunks)
  • packages/coze-js/src/resources/audio/speech/speech.ts (1 hunks)
  • packages/coze-js/src/resources/audio/voices/voices.ts (2 hunks)
  • packages/coze-js/src/resources/websockets/types.ts (1 hunks)
🔇 Additional comments (5)
packages/coze-js/package.json (5)

3-3: Version bump looks good

Minor version bump to 1.3.6 is appropriate for additive, non-breaking API surface (new optional fields).


25-30: Dist-based exports for "." look correct

The CJS/ESM/types entries point to dist and align with main/module/types below.


31-34: Please verify ws-tools types path (duplicated segment may be unintended)

The types path contains "ws-tools/ws-tools/index.d.ts". This duplication may be accidental and could break TS type resolution after publish, depending on build output structure. Recommend verifying the actual dist output before release.

If build output places d.ts at dist/types/ws-tools/index.d.ts, apply:

     "./ws-tools": {
       "require": "./dist/cjs/ws-tools/index.js",
       "import": "./dist/esm/ws-tools/index.mjs",
-      "types": "./dist/types/ws-tools/ws-tools/index.d.ts"
+      "types": "./dist/types/ws-tools/index.d.ts"
     }

Action:

  • Build locally and inspect the generated types under packages/coze-js/dist/types/ws-tools/.
  • Ensure the exports.types path matches the actual layout.

45-55: Align typesVersions with actual d.ts output layout

The typesVersions mapping for "ws-tools" mirrors the same duplicated path. Please verify generated paths and update if necessary to avoid TS resolution issues.

If the real output is dist/types/ws-tools/index.d.ts:

   "typesVersions": {
     "*": {
       ".": [
         "dist/types/index.d.ts"
       ],
       "ws-tools": [
-        "dist/types/ws-tools/ws-tools/index.d.ts"
+        "dist/types/ws-tools/index.d.ts"
       ]
     }
   },

112-116: cozePublishConfig.types for ws-tools likely needs the same path correction

Keep internal publish config consistent with package.exports/typesVersions.

       "./ws-tools": {
         "require": "./dist/cjs/ws-tools/index.js",
         "import": "./dist/esm/ws-tools/index.mjs",
-        "types": "./dist/types/ws-tools/ws-tools/index.d.ts"
+        "types": "./dist/types/ws-tools/index.d.ts"
       }

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
common/changes/@coze/api/feat-voice-emotion_2025-08-12-08-15.json (1)

5-6: Tighten up the changelog comment for clarity.

Use imperative, concise phrasing and reference the surface area touched to make release notes more informative.

Apply this diff to refine the comment:

-      "comment": "support voice emotions",
+      "comment": "Support voice emotions across speech and voice APIs.",
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between da74135 and e1fa501.

📒 Files selected for processing (7)
  • common/changes/@coze/api/feat-voice-emotion_2025-08-12-08-11.json (1 hunks)
  • common/changes/@coze/api/feat-voice-emotion_2025-08-12-08-14.json (1 hunks)
  • common/changes/@coze/api/feat-voice-emotion_2025-08-12-08-15.json (1 hunks)
  • packages/coze-js/package.json (2 hunks)
  • packages/coze-js/src/resources/audio/speech/speech.ts (1 hunks)
  • packages/coze-js/src/resources/audio/voices/voices.ts (2 hunks)
  • packages/coze-js/src/resources/websockets/types.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • common/changes/@coze/api/feat-voice-emotion_2025-08-12-08-14.json
  • packages/coze-js/package.json
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/coze-js/src/resources/websockets/types.ts
  • packages/coze-js/src/resources/audio/speech/speech.ts
  • packages/coze-js/src/resources/audio/voices/voices.ts
  • common/changes/@coze/api/feat-voice-emotion_2025-08-12-08-11.json
🔇 Additional comments (2)
common/changes/@coze/api/feat-voice-emotion_2025-08-12-08-15.json (2)

1-11: Well-formed change file.

JSON structure and Rush/Beachball change fields look correct: top-level packageName/email plus a single minor change entry.


1-11: All checks passed for the @coze/api voice‐emotion change

  • Change file is correctly scoped to @coze/api (located under packages/coze-js with name @coze/api).
  • The package exposes new emotion APIs (emotion, emotion_scale, support_emotions, emotion_config), so bumping the minor version is appropriate.
  • No other feat-voice-emotion_*.json files were found—no deduplication needed.

@Tecvan-fe Tecvan-fe enabled auto-merge November 3, 2025 06:24
@Tecvan-fe Tecvan-fe added this pull request to the merge queue Nov 3, 2025
Merged via the queue into coze-dev:main with commit ad4c087 Nov 3, 2025
2 of 3 checks passed
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.

4 participants