project-mirai / mirai-api-http

Mirai HTTP API (console) plugin
GNU Affero General Public License v3.0
1.66k stars 343 forks source link

发送语音需要先上传吗?可以直接用url吗?,然后获得voiceId 后再发送群消息,显示红色叹号! #515

Closed ltiaw closed 2 years ago

ltiaw commented 2 years ago

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} 但是群里的语音是红色叹号! 1113334

ryoii commented 2 years ago

可以直接url发

ltiaw commented 2 years ago

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} 群里发出来的语音红色叹号! 11223

我发url的是mp3链接,是有什么限制吗?

ryoii commented 2 years ago

看起来是这个URL响应了重定向,我测试一下

ryoii commented 2 years ago

破案了,来自 core 的文档

支持 AMR 和 SILK 格式. 若要支持 MP3 格式, 请参考 mirai-silk-converter