Skip to content

Conversation

@Soulter
Copy link
Member

@Soulter Soulter commented Sep 28, 2025

fixes #2844


Motivation / 动机

Modifications / 改动点

修正配置点映射

Verification Steps / 验证步骤

Screenshots or Test Results / 运行截图或测试结果

Compatibility & Breaking Changes / 兼容性与破坏性变更

  • 这是一个破坏性变更 (Breaking Change)。/ This is a breaking change.
  • 这不是一个破坏性变更。/ This is NOT a breaking change.

Checklist / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。/ If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。/ My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。/ 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.txt and pyproject.toml.
  • 😮 我的更改没有引入恶意代码。/ My changes do not introduce malicious code.
## Sourcery 总结

通过修正配置映射、增强切换命令以及在处理管道中添加提供者检查和警告日志,修复了 TTS 双输出功能。

Bug 修复:
- 修正 `dual_output``provider_tts_settings.dual_output` 的配置键映射
- 在未配置提供者时阻止 TTS 处理,并修正 `tts` 命令逻辑以遵循全局 TTS 启用状态

改进:
- 更新默认 STT/TTS 配置描述和提示,以提供更清晰的用户指导
-`preprocess``result_decorate` 阶段添加警告日志,以应对语音提供者缺失的情况
Original summary in English

Summary by Sourcery

Fix the TTS dual-output feature by correcting config mappings, enhancing the toggle command, and adding provider checks with warning logs in the processing pipeline.

Bug Fixes:

  • Correct the config key mapping for dual_output to provider_tts_settings.dual_output
  • Prevent TTS processing when no provider is configured and fix the tts command logic to respect global TTS enable status

Enhancements:

  • Update default STT/TTS config descriptions and hints for clearer user guidance
  • Add warning logs in preprocess and result_decorate stages when voice providers are missing

@auto-assign auto-assign bot requested review from Larch-C and anka-afk September 28, 2025 02:45
@Soulter Soulter changed the title fix: 修复"开启 TTS 时同时输出语音和文字内容" fix: 修复"开启 TTS 时同时输出语音和文字内容"功能不可用的问题 Sep 28, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

您好 - 我已审阅了您的更改,它们看起来很棒!

AI 代理提示
请解决此代码审查中的评论:

## 单独评论

### 评论 1
<location> `astrbot/core/pipeline/result_decorate/stage.py:188-192` </location>
<code_context>
-                and tts_provider
                 and SessionServiceManager.should_process_tts_request(event)
             ):
+                if not tts_provider:
+                    logger.warning(
+                        f"会话 {event.unified_msg_origin} 未配置文本转语音模型。"
+                    )
+                    return
                 new_chain = []
                 for comp in result.chain:
</code_context>

<issue_to_address>
**建议:** 考虑向用户提示 TTS 提供商配置错误。

除了仅记录警告外,当 TTS 因缺少配置而不可用时,请考虑在会话中通知用户。

建议的实现:

```python
                if not tts_provider:
                    logger.warning(
                        f"会话 {event.unified_msg_origin} 未配置文本转语音模型。"
                    )
                    # 向用户会话发送系统消息,提示TTS未配置
                    SessionServiceManager.send_system_message(
                        event,
                        "当前会话未配置文本转语音模型,无法进行语音合成。"
                    )
                    return

```

- 如果 `SessionServiceManager.send_system_message` 不存在,您将需要实现或使用适当的方法向会话中的用户发送系统消息。
- 调整消息发送函数和参数以符合您的代码库中用户/系统通知的约定。
</issue_to_address>

### 评论 2
<location> `astrbot/core/pipeline/preprocess_stage/stage.py:49-51` </location>
<code_context>
             ctx = self.plugin_manager.context
             stt_provider = ctx.get_using_stt_provider(event.unified_msg_origin)
             if not stt_provider:
+                logger.warning(
+                    f"会话 {event.unified_msg_origin} 未配置语音转文本模型。"
+                )
                 return
             message_chain = event.get_messages()
</code_context>

<issue_to_address>
**建议:** 考虑针对缺失的 STT 提供商提供面向用户的反馈。

目前,只记录了一个警告。请在会话中添加面向用户的反馈,以阐明其请求未被处理的原因。

建议的实现:

```python
            if not stt_provider:
                logger.warning(
                    f"会话 {event.unified_msg_origin} 未配置语音转文本模型。"
                )
                # 用户可见的反馈
                event.reply("当前会话未配置语音转文本模型,无法处理您的语音请求。")
                return

```

如果您的事件对象没有 `reply` 方法,请将 `event.reply(...)` 替换为适当的方法以向用户/会话发送消息。根据您应用程序的语气和风格调整反馈消息。
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Original comment in English

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `astrbot/core/pipeline/result_decorate/stage.py:188-192` </location>
<code_context>
-                and tts_provider
                 and SessionServiceManager.should_process_tts_request(event)
             ):
+                if not tts_provider:
+                    logger.warning(
+                        f"会话 {event.unified_msg_origin} 未配置文本转语音模型。"
+                    )
+                    return
                 new_chain = []
                 for comp in result.chain:
</code_context>

<issue_to_address>
**suggestion:** Consider surfacing TTS provider misconfiguration to the user.

Instead of only logging a warning, consider notifying the user in-session when TTS is unavailable due to missing configuration.

Suggested implementation:

```python
                if not tts_provider:
                    logger.warning(
                        f"会话 {event.unified_msg_origin} 未配置文本转语音模型。"
                    )
                    # 向用户会话发送系统消息,提示TTS未配置
                    SessionServiceManager.send_system_message(
                        event,
                        "当前会话未配置文本转语音模型,无法进行语音合成。"
                    )
                    return

```

- If `SessionServiceManager.send_system_message` does not exist, you will need to implement or use the appropriate method to send a system message to the user in-session.
- Adjust the message sending function and parameters to match your codebase's conventions for user/system notifications.
</issue_to_address>

### Comment 2
<location> `astrbot/core/pipeline/preprocess_stage/stage.py:49-51` </location>
<code_context>
             ctx = self.plugin_manager.context
             stt_provider = ctx.get_using_stt_provider(event.unified_msg_origin)
             if not stt_provider:
+                logger.warning(
+                    f"会话 {event.unified_msg_origin} 未配置语音转文本模型。"
+                )
                 return
             message_chain = event.get_messages()
</code_context>

<issue_to_address>
**suggestion:** Consider user-facing feedback for missing STT provider.

Currently, only a warning is logged. Please add user-facing feedback in the session to clarify why their request was not processed.

Suggested implementation:

```python
            if not stt_provider:
                logger.warning(
                    f"会话 {event.unified_msg_origin} 未配置语音转文本模型。"
                )
                # 用户可见的反馈
                event.reply("当前会话未配置语音转文本模型,无法处理您的语音请求。")
                return

```

If your event object does not have a `reply` method, replace `event.reply(...)` with the appropriate method to send a message to the user/session. Adjust the feedback message as needed for your application's tone and style.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Soulter Soulter merged commit 50f74f5 into master Sep 28, 2025
5 checks passed
@Soulter Soulter deleted the fix/2844 branch October 18, 2025 01:54
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.

[Bug]开启 TTS 时同时输出语音和文字内容无效

2 participants