mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-06-18 21:45:04 +08:00
update ptt codec.
This commit is contained in:
parent
16d4bb1f05
commit
2db3c6339d
@ -596,7 +596,7 @@ func (c *QQClient) buildImageUploadPacket(data, updKey []byte, commandId int32,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// PttStore.GroupPttUp
|
// PttStore.GroupPttUp
|
||||||
func (c *QQClient) buildGroupPttStorePacket(groupCode int64, md5 []byte, size, voiceLength int32) (uint16, []byte) {
|
func (c *QQClient) buildGroupPttStorePacket(groupCode int64, md5 []byte, size, codec, voiceLength int32) (uint16, []byte) {
|
||||||
seq := c.nextSeq()
|
seq := c.nextSeq()
|
||||||
req := &pb.D388ReqBody{
|
req := &pb.D388ReqBody{
|
||||||
NetType: 3,
|
NetType: 3,
|
||||||
@ -614,7 +614,7 @@ func (c *QQClient) buildGroupPttStorePacket(groupCode int64, md5 []byte, size, v
|
|||||||
InnerIp: 0,
|
InnerIp: 0,
|
||||||
BuildVer: "6.5.5.663",
|
BuildVer: "6.5.5.663",
|
||||||
VoiceLength: voiceLength,
|
VoiceLength: voiceLength,
|
||||||
Codec: 0,
|
Codec: codec,
|
||||||
VoiceType: 1,
|
VoiceType: 1,
|
||||||
BoolNewUpChan: true,
|
BoolNewUpChan: true,
|
||||||
},
|
},
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
@ -502,8 +503,13 @@ func (c *QQClient) uploadPrivateImage(target int64, img []byte, count int) (*mes
|
|||||||
|
|
||||||
func (c *QQClient) UploadGroupPtt(groupCode int64, voice []byte) (*message.GroupVoiceElement, error) {
|
func (c *QQClient) UploadGroupPtt(groupCode int64, voice []byte) (*message.GroupVoiceElement, error) {
|
||||||
h := md5.Sum(voice)
|
h := md5.Sum(voice)
|
||||||
voiceLength := utils.GetAmrDuration(voice)
|
codec := func() int32 {
|
||||||
seq, pkt := c.buildGroupPttStorePacket(groupCode, h[:], int32(len(voice)), voiceLength)
|
if bytes.HasPrefix(voice, []byte("#!AMR")) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return 1
|
||||||
|
}()
|
||||||
|
seq, pkt := c.buildGroupPttStorePacket(groupCode, h[:], int32(len(voice)), codec, int32(len(voice)))
|
||||||
r, err := c.sendAndWait(seq, pkt)
|
r, err := c.sendAndWait(seq, pkt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
package utils
|
|
||||||
|
|
||||||
// GetAmrDuration - return .amr file duration form bytesData
|
|
||||||
func GetAmrDuration(bytesData []byte) int32 {
|
|
||||||
duration := -1
|
|
||||||
packedSize := [16]int{12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0}
|
|
||||||
|
|
||||||
length := len(bytesData)
|
|
||||||
pos := 6
|
|
||||||
var datas []byte
|
|
||||||
frameCount := 0
|
|
||||||
packedPos := -1
|
|
||||||
|
|
||||||
for pos <= length {
|
|
||||||
datas = bytesData[pos : pos+1]
|
|
||||||
if len(datas) != 1 {
|
|
||||||
if length > 0 {
|
|
||||||
duration = (length - 6) / 650
|
|
||||||
} else {
|
|
||||||
duration = 0
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
packedPos = int((datas[0] >> 3) & 0x0F)
|
|
||||||
pos += packedSize[packedPos] + 1
|
|
||||||
frameCount++
|
|
||||||
}
|
|
||||||
|
|
||||||
duration += frameCount * 20
|
|
||||||
return int32(duration/1000 + 1)
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user