Skip to content

fix(asr): keep language, request_id and speaker_turns in ASRResponse - #165

Open
liujiahua123123 wants to merge 2 commits into
mainfrom
fix/asr-response-fields
Open

liujiahua123123 wants to merge 2 commits into
mainfrom
fix/asr-response-fields

Conversation

@liujiahua123123

@liujiahua123123 liujiahua123123 commented Oct 2, 2026 •

Copy link
Copy Markdown

Summary

ASRResponse declared only text, duration and segments, so pydantic's default extra="ignore" silently dropped fields that POST /v1/asr returns: language, language_code, request_id and speaker_turns (returned by transcribe-1-pro when timestamps are requested). Reading them raised AttributeError.

  • Add the four fields as optional (None when the API does not return them), with a new SpeakerTurn model (speaker, text, start, end), exported next to ASRSegment.
  • Fix the duration unit: it is seconds, not milliseconds (docstrings, the legacy fish_audio_sdk schema comment, and test fixtures). The generated docs page picks this up via the docs workflow.
  • README and the transcribe() docstring examples (published to the docs site) select transcribe-1-pro, the recommended model, via RequestOptions(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 of types/asr.py and resources/asr.py: 100%.
  • New tests parse a transcribe-1-pro-shaped response (with speaker_turns and request_id) and a transcribe-1-shaped one, for the sync and async clients. With the old model they fail (10 failures, AttributeError).
  • uv build and the import check pass; poe docs renders SpeakerTurn and the new fields.

Follow-up (not in this PR)

Request-side options for transcribe-1-pro (model selection without additional_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

  • New Features
    • Speech-to-text responses now include optional language, language code, request ID, and speaker-turn details with labels and timestamps.
    • Added an example showing how to request speaker turns and view transcript language information.
  • Documentation
    • Clarified that transcription duration and segment timestamps are measured in seconds.

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>
Copilot AI balanced review requested due to automatic review settings October 2, 2026 04:19
@coderabbitai

coderabbitai Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 1222bf84-b605-4aa7-8ff8-302fa5b6fc05

📥 Commits

Reviewing files that changed from the base of the PR and between 9fc082c and 8d2f6b5.

📒 Files selected for processing (2)
  • README.md
  • src/fishaudio/resources/asr.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/fishaudio/resources/asr.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The 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.

Changes

ASR Response

Layer / File(s) Summary
Response types and exports
src/fishaudio/types/asr.py, src/fishaudio/types/__init__.py, src/fish_audio_sdk/schemas.py
ASRResponse adds optional language, language-code, request-ID, and speaker-turn fields. The new SpeakerTurn type is publicly exported. Duration documentation uses seconds.
Transcription documentation and examples
src/fishaudio/resources/asr.py, README.md
Synchronous and asynchronous transcribe documentation describes response metadata and speaker turns. The README demonstrates selecting the Pro model and displaying the language code and speaker turns.
Response fixtures and tests
tests/unit/conftest.py, tests/unit/test_asr.py, tests/unit/test_types.py
Fixtures and tests use seconds and cover standard and Pro response fields, speaker turns, request options, and serialization.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 8d2f6

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 Review

Security architecture risk: 🔵 Low · up to 8d2f6

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
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The demonstrated change is bounded to SDK consumers receiving additional ASR response metadata and speaker text. Inspection identified no expansion of destinations, request authority, or client-side attacker reachability; production authorization and downstream application handling remain outside the inspected evidence.

Trust Boundaries and Controls

  • observed — Caller-supplied additional headers continue through the existing wrapper merge path, while endpoint-specific headers retain their existing precedence. This authority arrangement predates the PR; the new examples do not weaken it.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 85.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 7 files. (1 skipped: 1 …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately identifies the main change: preserving language, request_id, and speaker_turns in ASRResponse. It is concise and specific.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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.

@codecov

codecov Bot commented Oct 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
src/fishaudio/resources/asr.py 100.00% <ø> (ø)
src/fishaudio/types/__init__.py 100.00% <100.00%> (ø)
src/fishaudio/types/asr.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 Medium severity

Open (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>

This branch has not been deployed

No deployments
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.

2 participants