-
-
Notifications
You must be signed in to change notification settings - Fork 672
feat: wechatpadpro 触发tts时 添加对mp3格式音频支持 #1830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
更新后的腾讯录音助手音频转换的类图classDiagram
class tencent_record_helper {
+async convert_to_pcm_wav(input_path: str, output_path: str) str
+async audio_to_tencent_silk_base64(audio_path: str) tuple[str, float]
-async wav_to_tencent_silk_base64(wav_path: str) str (removed)
}
tencent_record_helper : Uses pyffmpeg or ffmpeg for conversion
tencent_record_helper : Handles temp file cleanup
文件级别变更
可能相关的 issue
提示和命令与 Sourcery 互动
自定义您的体验访问您的 仪表板 以:
获取帮助Original review guide in EnglishReviewer's GuideAdds support for MP3 and other non-WAV audio formats in WeChatPadPro TTS by introducing on-the-fly conversion to PCM WAV (via pyffmpeg or ffmpeg), refactoring the Silk encoding helper, and updating the message event to use the generalized converter. Sequence diagram for sending TTS voice message with MP3/WAV support in WeChatPadProsequenceDiagram
participant WeChatPadProMessageEvent as WeChatPadProMessageEvent
participant Record as Record
participant TencentRecordHelper as tencent_record_helper
participant FFmpeg as FFmpeg/pyffmpeg
participant SilkEncoder as pysilk
WeChatPadProMessageEvent->>Record: convert_to_file_path()
WeChatPadProMessageEvent->>TencentRecordHelper: audio_to_tencent_silk_base64(record_path)
alt input is not WAV
TencentRecordHelper->>FFmpeg: convert_to_pcm_wav(input_path, temp_wav)
FFmpeg-->>TencentRecordHelper: temp_wav
end
TencentRecordHelper->>SilkEncoder: Encode WAV to Silk
SilkEncoder-->>TencentRecordHelper: silk_b64, duration
TencentRecordHelper-->>WeChatPadProMessageEvent: silk_b64, duration
WeChatPadProMessageEvent->>WeChatServer: Send voice message (silk_b64)
Class diagram for updated Tencent record helper audio conversionclassDiagram
class tencent_record_helper {
+async convert_to_pcm_wav(input_path: str, output_path: str) str
+async audio_to_tencent_silk_base64(audio_path: str) tuple[str, float]
-async wav_to_tencent_silk_base64(wav_path: str) str (removed)
}
tencent_record_helper : Uses pyffmpeg or ffmpeg for conversion
tencent_record_helper : Handles temp file cleanup
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嘿 @zhx8702 - 我已经查看了你的更改 - 这里有一些反馈:
- 避免删除
audio_to_tencent_silk_base64
中的原始audio_path
——只删除你创建的文件(临时 WAV 或 SILK),以防止意外的数据丢失。 - 当 pyffmpeg 导入和 ffmpeg 子进程转换都失败时,添加显式的错误处理或清晰的异常,以便调用者获得有意义的失败消息。
AI 代理的提示
请解决此代码审查中的评论:
## 总体评论
- 避免删除 `audio_path` 中的原始 `audio_to_tencent_silk_base64`——只删除你创建的文件(临时 WAV 或 SILK),以防止意外的数据丢失。
- 当 pyffmpeg 导入和 ffmpeg 子进程转换都失败时,添加显式的错误处理或清晰的异常,以便调用者获得有意义的失败消息。
## 单独评论
### 评论 1
<location> `astrbot/core/utils/tencent_record_helper.py:98` </location>
<code_context>
+ stdout, stderr = await p.communicate()
+ logger.info(f"[FFmpeg] stdout: {stdout.decode().strip()}")
+ logger.debug(f"[FFmpeg] stderr: {stderr.decode().strip()}")
+ logger.info(f"[FFmpeg] return code: {p.returncode}")
+
+ if os.path.exists(output_path) and os.path.getsize(output_path) > 0:
</code_context>
<issue_to_address>
在非零 ffmpeg 退出代码上引发异常
在 ffmpeg 执行后检查 `p.returncode`,如果它非零,则引发错误,以便及时捕获失败的转换。
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
logger.info(f"[FFmpeg] stdout: {stdout.decode().strip()}")
logger.debug(f"[FFmpeg] stderr: {stderr.decode().strip()}")
logger.info(f"[FFmpeg] return code: {p.returncode}")
if os.path.exists(output_path) and os.path.getsize(output_path) > 0:
return output_path
else:
raise RuntimeError("生成的WAV文件不存在或为空")
=======
logger.info(f"[FFmpeg] stdout: {stdout.decode().strip()}")
logger.debug(f"[FFmpeg] stderr: {stderr.decode().strip()}")
logger.info(f"[FFmpeg] return code: {p.returncode}")
if p.returncode != 0:
raise RuntimeError(
f"FFmpeg 进程失败,返回码: {p.returncode}\n"
f"stderr: {stderr.decode().strip()}"
)
if os.path.exists(output_path) and os.path.getsize(output_path) > 0:
return output_path
else:
raise RuntimeError("生成的WAV文件不存在或为空")
>>>>>>> REPLACE
</suggested_fix>
帮助我更有用!请点击每个评论上的 👍 或 👎,我将使用反馈来改进你的评论。
Original comment in English
Hey @zhx8702 - I've reviewed your changes - here's some feedback:
- Avoid deleting the original
audio_path
inaudio_to_tencent_silk_base64
—only remove files you create (temp WAV or SILK) to prevent unexpected data loss. - Add explicit error handling or a clear exception when both the pyffmpeg import and the ffmpeg subprocess conversion fail, so callers get a meaningful failure message.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Avoid deleting the original `audio_path` in `audio_to_tencent_silk_base64`—only remove files you create (temp WAV or SILK) to prevent unexpected data loss.
- Add explicit error handling or a clear exception when both the pyffmpeg import and the ffmpeg subprocess conversion fail, so callers get a meaningful failure message.
## Individual Comments
### Comment 1
<location> `astrbot/core/utils/tencent_record_helper.py:98` </location>
<code_context>
+ stdout, stderr = await p.communicate()
+ logger.info(f"[FFmpeg] stdout: {stdout.decode().strip()}")
+ logger.debug(f"[FFmpeg] stderr: {stderr.decode().strip()}")
+ logger.info(f"[FFmpeg] return code: {p.returncode}")
+
+ if os.path.exists(output_path) and os.path.getsize(output_path) > 0:
</code_context>
<issue_to_address>
Raise on non-zero ffmpeg exit code
Check `p.returncode` after ffmpeg execution and raise an error if it is non-zero to catch failed conversions promptly.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
logger.info(f"[FFmpeg] stdout: {stdout.decode().strip()}")
logger.debug(f"[FFmpeg] stderr: {stderr.decode().strip()}")
logger.info(f"[FFmpeg] return code: {p.returncode}")
if os.path.exists(output_path) and os.path.getsize(output_path) > 0:
return output_path
else:
raise RuntimeError("生成的WAV文件不存在或为空")
=======
logger.info(f"[FFmpeg] stdout: {stdout.decode().strip()}")
logger.debug(f"[FFmpeg] stderr: {stderr.decode().strip()}")
logger.info(f"[FFmpeg] return code: {p.returncode}")
if p.returncode != 0:
raise RuntimeError(
f"FFmpeg 进程失败,返回码: {p.returncode}\n"
f"stderr: {stderr.decode().strip()}"
)
if os.path.exists(output_path) and os.path.getsize(output_path) > 0:
return output_path
else:
raise RuntimeError("生成的WAV文件不存在或为空")
>>>>>>> REPLACE
</suggested_fix>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
解决了 #1616
Motivation
多个tts服务商 提供的音频除了wav 还有mp3, wechatpadpro 添加发送语音的mp3适配
Modifications
如果文件不是wav 默认走mp3转wav逻辑
Check
requirements.txt
和pyproject.toml
文件相应位置。好的,这是将 pull request 总结翻译成中文的结果:
Sourcery 总结
添加即时音频格式检测和转换,以支持 WeChatPadPro 上 TTS 语音消息的 MP3(和其他格式),并更新消息事件以使用通用转换器
新功能:
增强功能:
wav_to_tencent_silk_base64
替换为audio_to_tencent_silk_base64
,并处理临时文件清理Original summary in English
好的,这是将 pull request 总结翻译成中文的结果:
Sourcery 总结
在 WeChatPadPro TTS 中启用 MP3 和其他音频格式支持,方法是在腾讯 Silk 编码之前将输入转换为 PCM WAV 格式。
新特性:
增强功能:
convert_to_pcm_wav
实用程序,该程序具有 pyffmpeg 和 ffmpeg CLI 后备方案。audio_to_tencent_silk_base64
替换wav_to_tencent_silk_base64
并处理临时文件清理。audio_to_tencent_silk_base64
发送语音消息。Original summary in English
Summary by Sourcery
Enable MP3 and other audio format support in WeChatPadPro TTS by converting inputs to PCM WAV before Tencent Silk encoding.
New Features:
Enhancements: