Skip to content

Conversation

137-rick
Copy link
Contributor

@137-rick 137-rick commented Sep 4, 2025

tts speech add parameter for loudness rate

Summary by CodeRabbit

  • New Features
    • Introduced an optional “loudness_rate” parameter for audio speech generation, allowing finer control over output loudness per request.
    • Backward compatible: existing behavior remains unchanged if the parameter is not provided.

Copy link

coderabbitai bot commented Sep 4, 2025

Walkthrough

Adds an optional loudness_rate parameter to the CreateAudioSpeechReq struct in coze’s audio_speech.go, enabling clients to include loudness settings in /v1/audio/speech requests. No other files or logic paths are modified.

Changes

Cohort / File(s) Summary of Changes
Audio Speech request struct
audio_speech.go
Added field LoudnessRate *int with JSON tag json:"loudness_rate" to CreateAudioSpeechReq. No other code changes.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Client
    participant SDK as coze-go SDK
    participant API as /v1/audio/speech

    Client->>SDK: Build CreateAudioSpeechReq<br/>(..., loudness_rate?)
    note over Client,SDK: loudness_rate is optional

    SDK->>API: POST request with JSON body<br/>{ ..., "loudness_rate": n? }
    API-->>SDK: Speech audio response
    SDK-->>Client: Return API response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

feature

Poem

I twitch my ears at decibels’ fate,
A hop, a bop—now set loudness_rate!
Whisper-soft or thunder’s cheer,
Tune the tone, bring voices near.
In fields of code I thump with glee—
One tiny flag, more melody. 🐇🎵

✨ 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 or @coderabbit 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.

@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 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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
audio_speech.go (1)

49-59: Nil-deref risk in WriteToFile when response or stream is nil.

Unrelated to this PR, but c == nil or c.Data == nil will panic on Close().

Apply this guard:

 func (c *CreateAudioSpeechResp) WriteToFile(path string) error {
+  if c == nil || c.Data == nil {
+    return errors.New("no audio data to write")
+  }
   file, err := os.Create(path)
   if err != nil {
     return err
   }
   defer file.Close()
   defer c.Data.Close()

And add the import:

// in the import block
"errors"
🧹 Nitpick comments (3)
audio_speech.go (3)

49-59: Offer an io.Writer-based helper to reduce API friction and enable streaming.

A WriteTo(w io.Writer) improves reuse and testability; WriteToFile can delegate to it.

Add:

func (c *CreateAudioSpeechResp) WriteTo(w io.Writer) error {
	if c == nil || c.Data == nil {
		return errors.New("no audio data to write")
	}
	defer c.Data.Close()
	_, err := io.Copy(w, c.Data)
	return err
}

Then simplify WriteToFile:

func (c *CreateAudioSpeechResp) WriteToFile(path string) error {
	file, err := os.Create(path)
	if err != nil {
		return err
	}
	defer file.Close()
	return c.WriteTo(file)
}

21-29: Document new request option in public docs/README and add a serialization test.

To avoid regressions, add a unit test asserting the JSON includes loudness_rate when set and omits or sends null when unset (matching current contract).

If helpful, I can draft the test and a short README snippet.


27-29: Document LoudnessRate field
Add a brief comment clarifying the expected range and units for LoudnessRate and consider omitempty if the backend omits nil values:

 type CreateAudioSpeechReq struct {
   Input          string       `json:"input"`
   VoiceID        string       `json:"voice_id"`
   ResponseFormat *AudioFormat `json:"response_format"`
   Speed          *float32     `json:"speed"`
   SampleRate     *int         `json:"sample_rate"`
-  LoudnessRate   *int         `json:"loudness_rate"`
+  // LoudnessRate controls output loudness; document accepted range (e.g. –60 to +6) and units (dB).
+  LoudnessRate   *int         `json:"loudness_rate,omitempty"`
 }

No other references to loudness_rate were found in the repo.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 2b32c3f and e4d88af.

📒 Files selected for processing (1)
  • audio_speech.go (1 hunks)
🔇 Additional comments (1)
audio_speech.go (1)

28-28: LGTM: field addition is consistent with existing request options.

Pointer type matches surrounding optional fields and JSON naming is consistent.

@chyroc chyroc added the feature label Sep 4, 2025
@chyroc chyroc changed the title Update audio_speech.go add loudness_rate parameter feat: Update audio_speech.go add loudness_rate parameter Sep 4, 2025
@chyroc chyroc merged commit d5e3dc1 into coze-dev:main Sep 4, 2025
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants