tulir / whatsmeow

Go library for the WhatsApp web multidevice API
https://go.mau.fi/whatsmeow
Mozilla Public License 2.0
2.06k stars 383 forks source link

Audio cannot be played on mobile #517

Open Ngebab opened 8 months ago

Ngebab commented 8 months ago

Hello so I tried sending an audio using bytes. It works but only for whatsapp web and whatsapp desktop, when I tried to play it on my phone it would make no audio

this is my code (Im using wasock which is whatsmeow with added feature)

audioUploaded, err := msg.Client.Upload(context.Background(), body, waSocket.MediaAudio)
                if err != nil {
                    msg.ReplyError("Error While Uploading Media to WhatsApp Server")
                    return
                }
                content := &waProto.Message{

                    AudioMessage: &waProto.AudioMessage{
                        ContextInfo:   msg.NewContext(true),
                        Url:           proto.String(audioUploaded.URL),
                        Ptt:           proto.Bool(true),
                        DirectPath:    proto.String(audioUploaded.DirectPath),
                        Mimetype:      proto.String("audio/ogg; codecs=opus"),
                        FileLength:    proto.Uint64(audioUploaded.FileLength),
                        FileSha256:    audioUploaded.FileSHA256,
                        FileEncSha256: audioUploaded.FileEncSHA256,
                        MediaKey:      audioUploaded.MediaKey,
                    },
                }
                msg.Reply(content)
hoehermann commented 5 months ago

The official phone app is very picky about the audio format. Setting the mime-type and hoping for the best is not enough. It must absolutely be an ogg container with the opus compression at 16 kHz and exactly one channel. I recommend using ffmpeg: ffmpeg -i yourinput -ac 1 -ar 16000 -c:a libopus voicemessage.ogg. I had users trying to send an MP3 or AAC file. This cannot be expected to work (even if other clients can support more formats due to auto-detection).
Reports from iOS users indicate, that values for the waveform diagram must be supplied for the message to be regarded as a "ptt" voice message.