Переглянути джерело

微信公众号语音输入支持 (#808)

JS00000 3 роки тому
батько
коміт
88f4a45cae

+ 1 - 0
app.py

@@ -15,6 +15,7 @@ def sigterm_handler_wrap(_signo):
         conf().save_user_datas()
         if callable(old_handler): #  check old_handler
             return old_handler(_signo, _stack_frame)
+        sys.exit(0)
     signal.signal(_signo, func)
 
 def run():

+ 4 - 1
channel/wechatmp/README.md

@@ -45,8 +45,11 @@ sudo iptables-save > /etc/iptables/rules.v4
 ## 私有api_key
 公共api有访问频率限制(免费账号每分钟最多20次ChatGPT的API调用),这在服务多人的时候会遇到问题。因此这里多加了一个设置私有api_key的功能。目前通过godcmd插件的命令来设置私有api_key。
 
+## 语音输入
+利用微信自带的语音识别功能,提供语音输入能力。需要在公众号管理页面的“设置与开发”->“接口权限”页面开启“接收语音识别结果”。
+
 ## 测试范围
-目前在`RoboStyle`这个公众号上进行了测试(基于[wechatmp-stable分支](https://github.com/JS00000/chatgpt-on-wechat/tree/wechatmp-stable),而[master分支](https://github.com/zhayujie/chatgpt-on-wechat)含有最新功能,但是稳定性有待测试),感兴趣的可以关注并体验。开启了godcmd, Banwords, role, dungeon, finish这五个插件,其他的插件还没有测试。百度的接口暂未测试。语音对话没有测试。图片直接以链接形式回复(没有临时素材上传接口的权限)。
+目前在`RoboStyle`这个公众号上进行了测试(基于[wechatmp分支](https://github.com/JS00000/chatgpt-on-wechat/tree/wechatmp)),感兴趣的可以关注并体验。开启了godcmd, Banwords, role, dungeon, finish这五个插件,其他的插件还没有测试。百度的接口暂未测试。语音对话没有测试。图片直接以链接形式回复(没有临时素材上传接口的权限)。
 
 ## TODO
 * 服务号交互完善

+ 1 - 1
channel/wechatmp/ServiceAccount.py

@@ -21,7 +21,7 @@ class Query():
             webData = web.data()
             # logger.debug("[wechatmp] Receive request:\n" + webData.decode("utf-8"))
             wechatmp_msg = receive.parse_xml(webData)
-            if wechatmp_msg.msg_type == 'text':
+            if wechatmp_msg.msg_type == 'text' or wechatmp_msg.msg_type == 'voice':
                 from_user = wechatmp_msg.from_user_id
                 message = wechatmp_msg.content.decode("utf-8")
                 message_id = wechatmp_msg.msg_id

+ 1 - 1
channel/wechatmp/SubscribeAccount.py

@@ -22,7 +22,7 @@ class Query():
             webData = web.data()
             logger.debug("[wechatmp] Receive request:\n" + webData.decode("utf-8"))
             wechatmp_msg = receive.parse_xml(webData)
-            if wechatmp_msg.msg_type == 'text':
+            if wechatmp_msg.msg_type == 'text' or wechatmp_msg.msg_type == 'voice':
                 from_user = wechatmp_msg.from_user_id
                 to_user = wechatmp_msg.to_user_id
                 message = wechatmp_msg.content.decode("utf-8")