fix(asr): keep language, request_id and speaker_turns in ASRResponse - #165
liujiahua123123 wants to merge 2 commits into
Conversation
ASRResponse declared only text, duration and segments, so pydantic's default extra="ignore" silently dropped the language, language_code, request_id and speaker_turns fields that /v1/asr returns. Add them as optional fields (None when the API does not return them) with a new SpeakerTurn model, exported next to ASRSegment. Also correct the duration unit to seconds in the docstrings and the legacy fish_audio_sdk schema comment, and use seconds in the ASR test fixtures. The change is backward compatible: no existing field or request parameter changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe ASR response model adds optional language metadata, a request ID, and speaker-turn data. Documentation and examples describe these fields and use seconds for durations and timestamps. Tests cover standard and Pro responses. ChangesASR Response
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to The PR adds optional ASR metadata and documents timings in seconds. No actionable issue is established for merge; the current API’s timing units remain unconfirmed by the available contract evidence. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The response additions are narrow and do not change request authority or transport. Timing is now documented in seconds, but compatibility with the current service response remains unconfirmed. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The structured speaker-turn field conflicts with the documented production API contract, which exposes only inline speaker markers.
Review effort: Balanced
Findings: 1
What changed in this PR
Extends ASR response models with additional metadata and corrects documented timing units.
Changes:
- Adds language, request ID, and speaker-turn response fields.
- Documents durations as seconds.
- Adds sync/async parsing tests and usage examples.
| File | Description |
|---|---|
README.md |
Adds language and speaker-turn examples. |
src/fish_audio_sdk/schemas.py |
Corrects legacy duration units. |
src/fishaudio/resources/asr.py |
Updates response documentation. |
src/fishaudio/types/__init__.py |
Exports SpeakerTurn. |
src/fishaudio/types/asr.py |
Extends ASR response models. |
tests/unit/conftest.py |
Adds response fixtures. |
tests/unit/test_asr.py |
Tests client response parsing. |
tests/unit/test_types.py |
Tests new ASR models and fields. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| language: Optional[str] = None | ||
| language_code: Optional[str] = None | ||
| request_id: Optional[str] = None | ||
| speaker_turns: Optional[list[SpeakerTurn]] = None |
…mples
transcribe-1-pro is the recommended speech-to-text model, and the API serves
a request without the model header on transcribe-1. The README and the
transcribe() docstring examples (published to the docs site) now select it
with RequestOptions(additional_headers={"model": "transcribe-1-pro"}), and
the README shows speaker turns in the same example.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Summary
ASRResponsedeclared onlytext,durationandsegments, so pydantic's defaultextra="ignore"silently dropped fields thatPOST /v1/asrreturns:language,language_code,request_idandspeaker_turns(returned bytranscribe-1-prowhen timestamps are requested). Reading them raisedAttributeError.Nonewhen the API does not return them), with a newSpeakerTurnmodel (speaker,text,start,end), exported next toASRSegment.durationunit: it is seconds, not milliseconds (docstrings, the legacyfish_audio_sdkschema comment, and test fixtures). The generated docs page picks this up via the docs workflow.transcribe()docstring examples (published to the docs site) selecttranscribe-1-pro, the recommended model, viaRequestOptions(additional_headers={"model": "transcribe-1-pro"}); the README example also reads speaker turns.Backward compatible: no existing field or request parameter changes; old responses still parse.
Tests
uv run poe check(ruff check, ruff format --check, ty check): clean on Python 3.12 and 3.9.uv run poe test: 165 passed on Python 3.9, 3.10, 3.11, 3.12, 3.13 and 3.14 (main: 157). Coverage oftypes/asr.pyandresources/asr.py: 100%.transcribe-1-pro-shaped response (withspeaker_turnsandrequest_id) and atranscribe-1-shaped one, for the sync and async clients. With the old model they fail (10 failures,AttributeError).uv buildand the import check pass;poe docsrendersSpeakerTurnand the new fields.Follow-up (not in this PR)
Request-side options for
transcribe-1-pro(model selection withoutadditional_headers,tag_audio_events,diarize, speaker-count hints) could be added as optional keyword arguments in a separate change.🤖 Generated with Claude Code
Summary by CodeRabbit