Skip to content

feat: tts and output text and audio metrics#2122

Merged
wangyoucao577 merged 1 commit into
mainfrom
dev/tts_billing_metrics
Mar 31, 2026
Merged

feat: tts and output text and audio metrics#2122
wangyoucao577 merged 1 commit into
mainfrom
dev/tts_billing_metrics

Conversation

@YiminW

@YiminW YiminW commented Mar 29, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@github-actions

Copy link
Copy Markdown

PR Review: TTS Output Text and Audio Metrics

Good overall structure — the change follows the established pattern from cosy_tts_python and the three version bumps are correct.

Bug: rime_tts counts empty/whitespace text in character metrics

In rime_tts/extension.py, the new call is placed without an empty-text guard:

self.sent_tts = True
# Track character metrics  <- added here
self.metrics_add_output_characters(len(t.text))
await self.client.send_text(t)

Unlike the other two extensions, rime_tts.request_tts does not filter empty text before this point. The t.text.strip() == "" check later in the method is a downstream edge-case for a different code path and does not protect the metrics call.

Compare with:

  • google_tts_python: call is inside if t.text.strip() != "": (correct)
  • qwen3_tts_python: call is after if not t.text or not t.text.strip(): ... return (correct)

Fix: add a guard before the rime_tts call:

self.sent_tts = True
if t.text.strip():
    self.metrics_add_output_characters(len(t.text))
await self.client.send_text(t)

Minor: inconsistent None-safety for send_usage_metrics argument

google_tts_python passes a safe fallback:

await self.send_usage_metrics(self.current_request_id or "")

qwen3_tts_python and rime_tts both pass self.current_request_id directly. In qwen3_tts this is safe due to the early if self.current_request_id is None: return guard in _complete_request, but in _handle_tts_audio_end (rime_tts) the guard is only if self.request_start_ts is not None:, which does not formally guarantee current_request_id is non-None. If the base-class send_usage_metrics does not accept None, this could surface as a runtime error on unusual teardown paths.

Suggestion: use self.current_request_id or "" in both places for consistency with google_tts_python.


Missing test coverage for the new metrics

The existing test_metrics.py files in both google_tts_python and rime_tts only exercise TTFB. The new functionality — metrics_add_output_characters and send_usage_metrics (usage metrics emission at end-of-request) — is untested. qwen3_tts_python has no test directory at all.

Consider adding:

  1. An assertion that output_characters accumulates correctly across multiple text chunks per request.
  2. An assertion that a usage metric is emitted exactly once per completed request (and not for empty-text skips).
  3. A basic test suite for qwen3_tts_python mirroring the cosy/rime pattern.

Everything else looks good

  • Placement of metrics_add_recv_audio_chunks (immediately after accumulating bytes, before sending audio data) is consistent with the reference cosy_tts_python pattern in all three extensions.
  • send_usage_metrics is correctly placed before finish_request in all three completion paths.
  • Character metrics are correctly scoped to the non-empty text path in google_tts_python and qwen3_tts_python.
  • All three manifest.json version bumps are appropriate for the behaviour change.

@wangyoucao577
wangyoucao577 merged commit d8ae6c7 into main Mar 31, 2026
34 of 35 checks passed
@wangyoucao577
wangyoucao577 deleted the dev/tts_billing_metrics branch March 31, 2026 07:36
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