Closed ltiaw closed 2 years ago
可以直接url发
data = { "sessionKey": "gCfdXBAG", "target": 51022656, "messageChain": [ {'type': 'Voice', 'url': "http://music.163.com/song/media/outer/url?id=1893308058"} ]} r2 = requests.post("http://192.168.1.225:8080/sendGroupMessage", json=data) print("发送语音结果:", r2.text)
结果还是一样 发送语音结果: {"code":0,"msg":"success","messageId":2045} 群里发出来的语音红色叹号!
我发url的是mp3链接,是有什么限制吗?
看起来是这个URL响应了重定向,我测试一下
破案了,来自 core 的文档
支持 AMR 和 SILK 格式. 若要支持 MP3 格式, 请参考 mirai-silk-converter
m = MultipartEncoder( fields={"sessionKey": "gCfdXBAG", "type": "group", 'voice': ('filename', open('123dd.mp3', 'rb'))} )
r = requests.post('http://192.168.1.225:8080/uploadVoice', data=m, headers={'Content-Type': m.content_type}) print(r.text) a = json.loads(r.text) voiceId = a["voiceId"]
print("voiceId:", voiceId)
data = { "sessionKey": "gCfdXBAG", "target": 51022656, "messageChain": [ {'type': 'Voice', 'voiceId': voiceId} ]} r2 = requests.post("http://192.168.1.225:8080/sendGroupMessage", json=data) print("发送语音结果:", r2.text)
返回结果: {"voiceId":"B7EBCC77925BADE91332995F1C4ED042.amr"} 发送语音结果: {"code":0,"msg":"success","messageId":2044} 但是群里的语音是红色叹号!