mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 11:07:40 +08:00
update voice
This commit is contained in:
parent
3fd3197d5c
commit
8bcbb9b401
@ -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
31
utils/audio.go
Normal 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)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user