1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 19:17:38 +08:00

update voice

This commit is contained in:
Logiase 2020-08-09 13:01:46 +08:00
parent 3fd3197d5c
commit 8bcbb9b401
2 changed files with 33 additions and 1 deletions

View File

@ -429,8 +429,9 @@ func (c *QQClient) uploadPrivateImage(target int64, img []byte, count int) (*mes
return e, nil return e, nil
} }
func (c *QQClient) UploadGroupPtt(groupCode int64, voice []byte, voiceLength int32) (*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)
seq, pkt := c.buildGroupPttStorePacket(groupCode, h[:], int32(len(voice)), voiceLength) seq, pkt := c.buildGroupPttStorePacket(groupCode, h[:], int32(len(voice)), voiceLength)
r, err := c.sendAndWait(seq, pkt) r, err := c.sendAndWait(seq, pkt)
if err != nil { if err != nil {

31
utils/audio.go Normal file
View File

@ -0,0 +1,31 @@
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)
}