feat(tts):增加tts(阿里云)提供商CosyVoice TTS(API),Qwen TTS Realtime(API)的支持,增加过滤 TTS 文本中的内容功能#7651
feat(tts):增加tts(阿里云)提供商CosyVoice TTS(API),Qwen TTS Realtime(API)的支持,增加过滤 TTS 文本中的内容功能#7651yuxwd wants to merge 7 commits intoAstrBotDevs:masterfrom
Conversation
Add two new TTS providers using Alibaba Cloud DashScope SDK: - Qwen TTS Realtime: WebSocket streaming TTS with low latency, supports qwen3-tts-flash-realtime and qwen3-tts-instruct-flash-realtime models - CosyVoice TTS: Non-streaming TTS with multiple voice options, supports cosyvoice-v3.5/v3/v2 models Includes config templates, provider manager integration, and i18n translations (zh-CN, en-US, ru-RU). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request introduces a TTS text filtering mechanism to strip markers like brackets and asterisks from text before synthesis, and adds support for Qwen TTS Realtime and CosyVoice TTS providers. The review feedback points out several critical issues: a logic error in the Qwen streaming implementation that causes audio duplication, a blocking call in an asynchronous function that could impact responsiveness, and incorrect usage of the DashScope SDK in the CosyVoice provider. Additionally, the FilteredQueue implementation requires a call to the base class constructor to ensure all inherited methods function correctly.
| if accumulated_text: | ||
| await loop.run_in_executor( | ||
| None, | ||
| qwen_tts.append_text, | ||
| accumulated_text, | ||
| ) |
| callback.complete_event.set() | ||
|
|
||
| await loop.run_in_executor(None, _connect_and_send) | ||
| finished = callback.wait_for_finished(timeout=self.timeout) |
There was a problem hiding this comment.
callback.wait_for_finished(timeout=self.timeout) 是一个阻塞同步调用(内部使用 threading.Event.wait),在异步函数中直接调用会阻塞 asyncio 事件循环,导致机器人响应变慢。建议使用 loop.run_in_executor 将其放入线程池执行。
| finished = callback.wait_for_finished(timeout=self.timeout) | |
| finished = await loop.run_in_executor(None, callback.wait_for_finished, self.timeout) |
| audio_bytes = await loop.run_in_executor( | ||
| None, | ||
| synthesizer.call, | ||
| text, | ||
| self.timeout_ms, | ||
| ) |
There was a problem hiding this comment.
| self, | ||
| real_queue: asyncio.Queue[T | None], | ||
| custom_rules: list[str] | None = None, | ||
| ) -> None: | ||
| self._real_queue = real_queue | ||
| self._custom_rules = custom_rules | ||
|
|
There was a problem hiding this comment.
FilteredQueue 继承自 asyncio.Queue 但未调用 super().__init__()。虽然该类目前通过代理模式重写了主要方法,但未初始化的基类会导致 get_nowait、put_nowait 等未被重写的方法在调用时因缺少内部状态(如 _getters, _putters)而失败。建议显式调用 super().__init__() 以确保对象状态完整。
def __init__(\n self,\n real_queue: asyncio.Queue[T | None],\n custom_rules: list[str] | None = None,\n ) -> None:\n super().__init__(maxsize=real_queue.maxsize)\n self._real_queue = real_queue\n self._custom_rules = custom_rulesfaf411f to
0068960
Compare



Modifications / 改动点
tts提供商添加
项目原生tts阿里云提供商tts支持不全面,改动添加了CosyVoice TTS(API),Qwen TTS Realtime(API)的支持
过滤 TTS 文本中的内容
bot发送tts优化,增加了,过滤 TTS 文本中的内容的功能,可以让tts不读()的内容,支持正则过滤
代码测试
进行了macos系统和linux(Alibaba Cloud Linux 3.2104 LTS 64位)测试无问题




Screenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
[✅ ] 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
[✅ ] 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
[ ✅ ] 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。[ ✅ ] 😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。