mirror of
https://github.com/mautrix/whatsapp.git
synced 2025-03-14 14:15:38 +00:00
msgconv/from-matrix: fix reading duration and converting waveform
Fixes #757
This commit is contained in:
parent
c2f719e1ae
commit
8d4964138c
1 changed files with 10 additions and 6 deletions
|
@ -502,25 +502,29 @@ func parseGeoURI(uri string) (lat, long float64, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func getAudioInfo(content *event.MessageEventContent) (output []byte, Duration uint32) {
|
||||
func getAudioInfo(content *event.MessageEventContent) (output []byte, duration uint32) {
|
||||
duration = uint32(content.Info.Duration / 1000)
|
||||
audioInfo := content.MSC1767Audio
|
||||
if audioInfo == nil {
|
||||
return nil, uint32(content.Info.Duration / 1000)
|
||||
return
|
||||
}
|
||||
if duration == 0 && audioInfo.Duration != 0 {
|
||||
duration = uint32(audioInfo.Duration / 1000)
|
||||
}
|
||||
waveform := audioInfo.Waveform
|
||||
if len(waveform) == 0 {
|
||||
return nil, uint32(audioInfo.Duration / 1000)
|
||||
return
|
||||
}
|
||||
|
||||
maxVal := slices.Max(waveform)
|
||||
output = make([]byte, len(waveform))
|
||||
if maxVal < 256 {
|
||||
if maxVal <= 256 {
|
||||
for i, part := range waveform {
|
||||
output[i] = byte(part)
|
||||
output[i] = byte(min(part, 255))
|
||||
}
|
||||
} else {
|
||||
for i, part := range waveform {
|
||||
output[i] = min(byte(part/4), 255)
|
||||
output[i] = byte(min(part/4, 255))
|
||||
}
|
||||
}
|
||||
return
|
||||
|
|
Loading…
Add table
Reference in a new issue