Skip to content

feat: tencent tts add metrics#2124

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

feat: tencent tts add metrics#2124
wangyoucao577 merged 1 commit into
mainfrom
dev/tts_billing_metrics

Conversation

@YiminW

@YiminW YiminW commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@github-actions

Copy link
Copy Markdown

PR Review: feat: tencent tts add metrics

This PR adds metrics tracking to tencent_tts_python, consistent with the pattern already used in other TTS extensions (bytedance_tts_duplex, google_tts_python, cosy_tts_python). The changes are small and focused.

What looks good

  • The three metric call sites are correctly placed: character count inside the t.text.strip() != "" guard, audio chunks inside the len(audio_data) > 0 guard, and send_usage_metrics before finish_request so the request ID is still valid.
  • Version bump to 0.4.5 is appropriate for a feature addition.
  • Missing newline at end of manifest.json is fixed.

Issue: potential null request ID passed to send_usage_metrics

The added line in _handle_tts_audio_end:

await self.send_usage_metrics(self.current_request_id)

self.current_request_id can be None here if _handle_tts_audio_end is called after a previous invocation already cleared it. The method sets self.current_request_id = None at the end but never resets request_start_ts, so the if self.request_start_ts is not None: guard does not protect against a double-call scenario. The sibling extension google_tts_python handles this defensively (line 232):

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

Recommend applying the same pattern here.

Minor: character count includes whitespace

metrics_add_output_characters(len(t.text)) counts all characters including leading/trailing whitespace, even though only t.text.strip() is checked for emptiness before sending. Very minor, but worth noting for metric accuracy.

No test coverage

No tests are added for the new metric calls. Given the straightforward pattern being followed this is acceptable, but tests for the metrics paths would improve confidence.

Summary

The change is correct and follows established conventions in the codebase. The only concrete fix worth addressing before merging is using self.current_request_id or "" in the send_usage_metrics call to stay consistent with google_tts_python and avoid passing None in edge cases.

@YiminW
YiminW force-pushed the dev/tts_billing_metrics branch from 5c770e6 to 578ed0b Compare March 31, 2026 10:48
@github-actions

Copy link
Copy Markdown

PR Review - Overall LGTM with minor observations. This PR adds output character and audio chunk metrics to the Tencent TTS extension, following the same pattern established in PR 2122 for google_tts_python, qwen3_tts_python, and rime_tts. The implementation correctly mirrors the established pattern: metrics_add_output_characters inside the text strip guard, metrics_add_recv_audio_chunks at the audio data receive point, and send_usage_metrics called before finish_request in _handle_tts_audio_end. Minor observations: (1) Character count includes whitespace - the guard ensures t.text.strip() is non-empty but metrics_add_output_characters(len(t.text)) still counts leading/trailing whitespace. Consistent with google_tts_python so fine as-is, but worth noting if exact character billing matters. (2) Metrics are inside the 'if self.request_start_ts is not None' block - correct and pre-existing behavior, but means metrics will not emit if _handle_tts_audio_end is called before a request starts. Not introduced by this PR. The missing newline fix in manifest.json is a nice cleanup and the version bump to 0.4.5 is appropriate. Clean, focused change that brings Tencent TTS to parity with other TTS extensions. No blocking issues.

@wangyoucao577
wangyoucao577 merged commit 6dca78a into main Mar 31, 2026
34 checks passed
@wangyoucao577
wangyoucao577 deleted the dev/tts_billing_metrics branch March 31, 2026 11:15
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