-
Notifications
You must be signed in to change notification settings - Fork 51
feat: Update audio_speech.go add loudness_rate parameter #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
add parameter for loudness rate
WalkthroughAdds 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
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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Poem
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
|
There was a problem hiding this 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
orc.Data == nil
will panic onClose()
.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 forLoudnessRate
and consideromitempty
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.
📒 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.
tts speech add parameter for loudness rate
Summary by CodeRabbit