From 349115b948efbe782f425016306386814f730bb1 Mon Sep 17 00:00:00 2001 From: lanvent Date: Wed, 29 Mar 2023 17:05:32 +0800 Subject: [PATCH] fix: use mp3 file when mp3_to_wav failed --- channel/wechat/wechat_channel.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/channel/wechat/wechat_channel.py b/channel/wechat/wechat_channel.py index f3cbd16..9a7904d 100644 --- a/channel/wechat/wechat_channel.py +++ b/channel/wechat/wechat_channel.py @@ -273,7 +273,11 @@ class WechatChannel(Channel): msg.download(mp3_path) # mp3转wav wav_path = os.path.splitext(mp3_path)[0] + '.wav' - mp3_to_wav(mp3_path=mp3_path, wav_path=wav_path) + try: + mp3_to_wav(mp3_path=mp3_path, wav_path=wav_path) + except Exception as e: # 转换失败,直接使用mp3,对于某些api,mp3也可以识别 + logger.warning("[WX]mp3 to wav error, use mp3 path. " + str(e)) + wav_path = mp3_path # 语音识别 reply = super().build_voice_to_text(wav_path) # 删除临时文件