Telegram Bot API: voice message audio spectrogram is missing. A bug?
Asked Answered
F

2

10

I'm developing a Telegram bot and I have a question about sendvoice API to send voice (audio) messages.

I push a OGG file converting from a MP3 source file, using ffmpeg for conversion, with the command:

$ ffmpeg -loglevel panic -i \
    /path/to/la_piattaforma_telegram_è_perfetta.mp3 \
    -c:a libopus -compression_level 10 -frame_duration 60 -vbr on -application voip \
    /path/to/la_piattaforma_telegram_è_perfetta.ogg -y

BTW, the MIME type appears correct:

$ file --mime-type -b \ 
/path/to/la_piattaforma_telegram_è_perfetta.ogg
audio/ogg

The audio file is correctly played as expected, but the (minor) problem I have is that Telegram client (desktop/android/any) doesn't show the "waveform" (audio spectogram, as that in the blue widget in the image below), instead the waveform is visualized as a single line.

Any idea about how to show the waveform graphic? There is any specific OPUS format required to allow nice visualization?

enter image description here

$ mediainfo /path/to/la_piattaforma_telegram_è_perfetta.ogg
General
Complete name                            : /path/to/la_piattaforma_telegram_è_perfetta.ogg
Format                                   : Ogg
File size                                : 5.37 KiB
Duration                                 : 2 s 79 ms
Overall bit rate                         : 21.2 kb/s

Audio
ID                                       : 1485113069 (0x588506ED)
Format                                   : Opus
Duration                                 : 2 s 79 ms
Channel(s)                               : 1 channel
Channel positions                        : Front: C
Sampling rate                            : 16.0 kHz
Compression mode                         : Lossy
Writing library                          : libopus unknown-fixed

The lack of the waveform visualization could be because the audio track is mono (1 channel)?

Farmann answered 4/6, 2019 at 17:2 Comment(2)
Hi, I have same question, were you able to solve this issue? Thanks,Susurrant
Nope :( I think that's because the audio track is mono. For me it's a TG API bug.Farmann
S
4

You need to consider a few things:

  1. Specify a filename for your file when sending to Telegram.
  2. Convert the MP3 file to a .opus file directly.
  3. Set the bitrate to somewhere b/w 32kb to 64kb, or else, some Telegram clients can't decode the spectrogram.

This should lead you to a command like this:

ffmpeg -i input_path.mp3 -c:a libopus -b:a 32k -vbr on -compression_level 10 -frame_duration 60 -application voip output_path.ogg

You can see the working example here in my repo:

Sacha answered 27/8, 2023 at 0:17 Comment(0)
F
2

I solved the issue. It was my fault/bug (mostly). I answer now to my self to share the solution I just found.

  • Telegram SendVoice API docs states audio file to be sent must be in an .OGG file encoded with OPUS,

  • so, as described in my question, I used ffmpeg to convert the original (source) file, that was an .MP3, to the .OGG required format.

  • Unfortunately, for a bug in my program I sent the MP3 original audio instead of the converted OGG :(

Weirdly, Telegram API accept the MP3 audio format WITHOUT errors, but in this case DOES NOT display the spectrogram (showing instead just a continuous line).

Now, by sending the correct .OGG file I get the expected spectrogram!

BTW, to be picky, there is still a MINOR bug on Telegram API, related to the specifications on the API endpoint documentation (sendVoice does accept ALSO .MP3 and not only .OGG files).

Farmann answered 20/8, 2020 at 15:27 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.