zhayujie / chatgpt-on-wechat

基于大模型搭建的聊天机器人,同时支持 微信公众号、企业微信应用、飞书、钉钉 等接入,可选择GPT3.5/GPT-4o/GPT4.0/ Claude/文心一言/讯飞星火/通义千问/ Gemini/GLM-4/Claude/Kimi/LinkAI,能处理文本、语音和图片,访问操作系统和互联网,支持基于自有知识库进行定制企业智能客服。
https://docs.link-ai.tech/cow
MIT License
29.49k stars 7.8k forks source link

微信公众号部署,无法使用语音识别 #1540

Open KunBuFenZi opened 9 months ago

KunBuFenZi commented 9 months ago

前置确认

⚠️ 搜索issues中是否已存在类似问题

操作系统类型?

Linux

运行的python版本是?

python 3.10

使用的chatgpt-on-wechat版本是?

Latest Release

运行的channel类型是?

wechatmp_service(公众号, 服务号)

复现步骤 🕹

公众号发送语音后 后台语音识别不出来(百度,azure,openai都试了)

问题描述 😯

微信公众号部署,无法使用语音识别。 尝试过添加amr的解码器,尝试过重新编译ffpeng,都不行。看过其他issue,pip安装过各语音识别需要的依赖,都不行

终端日志 📒


<此处粘贴终端日志>
```[INFO][2023-11-21 20:24:09][bridge.py:43] - create bot baidu for voice_to_text
[INFO][2023-11-21 20:24:09][baidu_voice.py:67] - 百度语音识别到了:['嗯。']
[INFO][2023-11-21 20:24:09][xunfei_spark_bot.py:55] - [XunFei] query=嗯。
[INFO][2023-11-21 20:24:09][xunfei_spark_bot.py:102] - [XunFei] start connect, prompt=[{'role': 'user', 'content': '你是谁'}, {'role': 'assistant', 'content': '您好,我是科大讯飞研发的认知智能大模型,我的名字叫讯飞星火认知大模型。我可以和人类进行自然交流,解答问题,高效完成各领域认知智能需求。'}, {'role': 'user', 'content': '嗯。'}]
[INFO][2023-11-21 20:24:10][xunfei_spark_bot.py:201] - [XunFei] Start websocket, session_id=oHwqy6u-fO7I4rVafwu9aPYk-NdI_170056944949
[INFO][2023-11-21 20:24:11][xunfei_spark_bot.py:88] - [XunFei-API] response=请问有什么问题或者需要帮助的地方吗?我会尽力为您提供准确和有用的信息。, time=1.1925382614135742s, usage={'text': {'question_tokens': 11, 'prompt_tokens': 62, 'completion_tokens': 17, 'total_tokens': 79}}
[INFO][2023-11-21 20:24:11][wechatmp_channel.py:153] - [wechatmp] Do send text to oHwqy6u-fO7I4rVafwu9aPYk-NdI: 请问有什么问题或者需要帮助的地方吗?我会尽力为您提供准确和有用的信息。
[INFO][2023-11-21 20:24:20][active_reply.py:44] - [wechatmp] 127.0.0.1:56048 Receive post query oHwqy6u-fO7I4rVafwu9aPYk-NdI 7303890210981412864: tmp/_EMT2_H0JvlKuIQuxql86D07t3lVJGrqBCcDm2yzKtZ8xZ2OAd3tTc_MaSL2CYjD.amr
127.0.0.1:56048 - - [21/Nov/2023 20:24:20] "HTTP/1.1 POST /wx" - 200 OK
[INFO][2023-11-21 20:24:20][baidu_voice.py:67] - 百度语音识别到了:['']
[ERROR][2023-11-21 20:24:20][wechatmp_channel.py:233] - [wechatmp] Fail to generate reply to user, msgId=7303890210981412864, exception=list index out of range
Traceback (most recent call last):
  File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/root/wechat/channel/chat_channel.py", line 156, in _handle
    reply = self._generate_reply(context)
  File "/root/wechat/channel/chat_channel.py", line 204, in _generate_reply
    reply = self._generate_reply(new_context)
  File "/root/wechat/channel/chat_channel.py", line 166, in _generate_reply
    e_context = PluginManager().emit_event(
  File "/root/wechat/plugins/plugin_manager.py", line 189, in emit_event
    instance.handlers[e_context.event](e_context, *args, **kwargs)
  File "/root/wechat/plugins/linkai/linkai.py", line 83, in on_handle_context
    mj_type = self.mj_bot.judge_mj_task_type(e_context)
  File "/root/wechat/plugins/linkai/midjourney.py", line 91, in judge_mj_task_type
    if cmd_list[0].lower() == f"{trigger_prefix}mj":
IndexError: list index out of range
[INFO][2023-11-21 20:25:10][active_reply.py:44] - [wechatmp] 127.0.0.1:39700 Receive post query oHwqy6u-fO7I4rVafwu9aPYk-NdI 7303890430024744960: tmp/_EMT2_H0JvlKuIQuxql86BOvT1hDgUUfKBVR7ivFjBQgQ2fdT3tyDWZl907Dxf2_.amr
127.0.0.1:39700 - - [21/Nov/2023 20:25:10] "HTTP/1.1 POST /wx" - 200 OK
[INFO][2023-11-21 20:25:11][baidu_voice.py:67] - 百度语音识别到了:['']
[ERROR][2023-11-21 20:25:11][wechatmp_channel.py:233] - [wechatmp] Fail to generate reply to user, msgId=7303890430024744960, exception=list index out of range
Traceback (most recent call last):
  File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/root/wechat/channel/chat_channel.py", line 156, in _handle
    reply = self._generate_reply(context)
  File "/root/wechat/channel/chat_channel.py", line 204, in _generate_reply
    reply = self._generate_reply(new_context)
  File "/root/wechat/channel/chat_channel.py", line 166, in _generate_reply
    e_context = PluginManager().emit_event(
  File "/root/wechat/plugins/plugin_manager.py", line 189, in emit_event
    instance.handlers[e_context.event](e_context, *args, **kwargs)
  File "/root/wechat/plugins/linkai/linkai.py", line 83, in on_handle_context
    mj_type = self.mj_bot.judge_mj_task_type(e_context)
  File "/root/wechat/plugins/linkai/midjourney.py", line 91, in judge_mj_task_type
    if cmd_list[0].lower() == f"{trigger_prefix}mj":
IndexError: list index out of range
KunBuFenZi commented 9 months ago

上面三次输入 我说的都是你好,第一次识别成“嗯”,后两次识别为空

cappiewu commented 9 months ago

网上查了一下,这个应该是公众号那边的问题,参考一下微信开放社区的相关帖子,例如: https://developers.weixin.qq.com/community/develop/doc/000428de67498835f3ef9d51851400 “开通语音识别后,用户每次发送语音给公众号时,微信会在推送的语音消息XML数据包中,增加一个Recognition字段”,而我打开公众号的语音识别后,Recognition每次返回都是None。 所以这个是微信公众号那边的问题。

你可以在 channel/wechatmp/wechatmp_message.py这个文件的19~20行,也就是: elif msg.type == "voice": if msg.recognition == None: 之间加入logger.info,变成: elif msg.type == "voice": logger.info(f"[wechatmp] voice msg, {msg}") if msg.recognition == None: 这样能打印整个msg,发送语音给公众号后可以看看公众号返回的信息。

我的返回信息: [INFO][2023-11-26 03:38:50][wechatmp_message.py:20] - [wechatmp] voice msg, VoiceMessage({'ToUserName': 'gh_054b25bbd8de', 'FromUserName': 'oXhbO6Se5zbjAzjdImTC-mVl1vqo', 'CreateTime': '1700969920', 'MsgType': 'voice', 'MediaId': 'aTclEq8PUpRjEKaopi6dl7Ky6uwDajnfq3PLFyw1uLup6u86kMj7EWkdWKkRTtsI', 'Format': 'amr', 'MsgId': '7305610177879736320', 'Recognition': None}) 可以看到'Recognition': None,是公众号那边没有进行语音识别。

sylanvans commented 8 months ago

我甚至没拿到我语音内容,这是一个问题吧。现在有处理方法吗

[INFO][2023-12-11 22:18:00][wechatmp_message.py:20] - [wechatmp] voice msg, VoiceMessage({'ToUserName': 'gh_216b701086e0', 'FromUserName': 'ovplI6rW3uMeS7_qAKr2cTorXDSQ', 'CreateTime': '1702304280', 'MsgType': 'voice', 'MediaId': 'omKpmQ86rcWB8SUkL9Lqg5D5nO3PDrdQXaPMv30KFl39-CaHqWLT8A9wV_2AUnbF', 'Format': 'amr', 'MsgId': '24371136331115260', 'Recognition': None}) [INFO][2023-12-11 22:18:00][passive_reply.py:97] - [wechatmp] Request 1 from ovplI6rW3uMeS7_qAKr2cTorXDSQ 24371136331115260 81.69.103.147:6732 tmp/omKpmQ86rcWB8SUkL9Lqg5D5nO3PDrdQXaPMv30KFl39-CaHqWLT8A9wV_2AUnbF.amr [INFO][2023-12-11 22:18:01][bridge.py:43] - create bot baidu for voice_to_text [INFO][2023-12-11 22:18:02][baidu_voice.py:67] - 百度语音识别到了:[''] [INFO][2023-12-11 22:18:02][bridge.py:43] - create bot linkai for chat [ERROR][2023-12-11 22:18:02][wechatmp_channel.py:233] - [wechatmp] Fail to generate reply to user, msgId=24371136331115260, exception=list index out of range Traceback (most recent call last): File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, *self.kwargs) File "/root/chatgpt-on-wechat/channel/chat_channel.py", line 168, in _handle reply = self._generate_reply(context) File "/root/chatgpt-on-wechat/channel/chat_channel.py", line 214, in _generate_reply reply = self._generate_reply(new_context) File "/root/chatgpt-on-wechat/channel/chat_channel.py", line 178, in _generate_reply e_context = PluginManager().emit_event( File "/root/chatgpt-on-wechat/plugins/plugin_manager.py", line 189, in emit_event instance.handlers[e_context.event](e_context, args, **kwargs) File "/root/chatgpt-on-wechat/plugins/role/role.py", line 111, in on_handle_context if clist[0] == f"{trigger_prefix}停止扮演": IndexError: list index out of range

tengzhaoyong commented 8 months ago

同上,求大佬解答

MasterKe2003 commented 7 months ago

同问

MasterKe2003 commented 6 months ago

https://github.com/zhayujie/chatgpt-on-wechat/pull/1686 亲测这个解决

uxfion commented 5 months ago

1686 亲测这个解决

请问大佬是如何解决的?方便告知一下解决步骤吗。我现在就是'Recognition': None这种情况,是使用百度语音转写可以支持吗?

我看到与个人微信接入不同的是微信公众号收到的音频是amr,个微接收到的是MP3,用whisper可以识别。而amr就出问题了,不知道改如何解决。

MasterKe2003 commented 5 months ago

1686 亲测这个解决

请问大佬是如何解决的?方便告知一下解决步骤吗。我现在就是'Recognition': None这种情况,是使用百度语音转写可以支持吗?

我看到与个人微信接入不同的是微信公众号收到的音频是amr,个微接收到的是MP3,用whisper可以识别。而amr就出问题了,不知道改如何解决。

按照那个提交把代码改了就行了

uxfion commented 5 months ago

按照那个提交把代码改了就行了

谢谢大佬!已经使用百度的语音api解决了在微信公众号上语音无法使用的问题