feat(tencent):add tencent cloud asr and tts#6316
Conversation
|
JunboLi seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
| def push_text(self, token: str) -> None: | ||
| if not token or self._input_ch.closed: | ||
| return | ||
|
|
||
| self._pushed_text += token | ||
|
|
||
| if self._metrics_task is None: | ||
| self._metrics_task = asyncio.create_task( | ||
| self._metrics_monitor_task(self._monitor_aiter), name="TTS._metrics_task" | ||
| ) | ||
|
|
||
| if not self._mtc_text: | ||
| self._num_segments += 1 | ||
|
|
||
| self._mtc_text += token | ||
| self._input_ch.send_nowait(token) | ||
| self._input_buffer.append(token) | ||
|
|
||
| def flush(self) -> None: | ||
| if self._input_ch.closed: | ||
| return | ||
|
|
||
| if self._mtc_text: | ||
| self._mtc_pending_texts.append(self._mtc_text) | ||
| self._mtc_text = "" | ||
|
|
||
| sentinel = self._FlushSentinel() | ||
| self._input_ch.send_nowait(sentinel) | ||
| self._input_buffer.append(sentinel) |
There was a problem hiding this comment.
π© TTS SynthesizeStream overrides push_text/flush to support multi-segment usage
The Tencent SynthesizeStream overrides both push_text (tts.py:303-319) and flush (tts.py:321-331) from the base class at livekit-agents/livekit/agents/tts/tts.py:635-673. The key difference is that the base class's push_text has a guard at livekit-agents/livekit/agents/tts/tts.py:648-654 that logs a deprecation warning and drops tokens when _num_segments >= 1 (i.e., a second segment is starting). The Tencent override removes this guard, unconditionally incrementing _num_segments for each new segment. This is intentional because the Tencent _run method (tts.py:333-370) explicitly handles multiple segments by creating a new WebSocket connection per flush via _synthesize_once, and the base class's _main_task validates that _num_segments == output_emitter.num_segments at livekit-agents/livekit/agents/tts/tts.py:500. The counts will match because each _flush_segment calls start_segment/end_segment. However, this pattern of overriding public API methods to bypass deprecation guards is unusual among the existing plugins β most other plugins don't override push_text/flush at all.
Was this helpful? React with π or π to provide feedback.
add tencent cloud asr and tts