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.6.
    • Add changelog entries documenting voice emotion support.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

coderabbitai bot commented Aug 12, 2025

Walkthrough

Adds voice-emotion support to the JS SDK: new changelog entries; minor package version bump; optional emotion fields on speech requests; voice metadata advertising supported emotions; 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.5 → 1.3.6 (no public API changes; newline EOF).
Speech request
packages/coze-js/src/resources/audio/speech/speech.ts
CreateSpeechReq adds optional emotion?: string and emotion_scale?: number; create() forwards params unchanged.
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

  Client->>SDK: create({ text, voice_id, emotion?, emotion_scale? })
  SDK->>API: POST /audio/speech (payload includes emotion fields)
  API-->>SDK: Audio response (may include emotion metadata)
  SDK-->>Client: Return audio data/stream
Loading
sequenceDiagram
  participant Client
  participant SDK as coze-js (WS)
  participant Server

  Client->>SDK: Open WS, request audio
  Server-->>SDK: OutputAudio { ..., emotion_config? }
  SDK-->>Client: Emit OutputAudio with emotion_config
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Possibly related PRs

Suggested reviewers

  • DingGao-Devin
  • jackshen310

Poem

I twitch my ears at tones anew,
Small hops of feeling threaded through.
Emotion notes and scales align,
Voices bloom — a brighter sign.
I nibble bytes and hum with glee. 🐇🎶

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • 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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

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.

3 participants