How to generate a waveform for a voice message
We will talk about additional features of Send media-voice message endpoint: https://whapi.readme.io/reference/sendmessagevoice
When sending voice messages via WhatsApp, you can add a waveform parameter. This is a visual representation of the audio track - what you see as waves in the WhatsApp interface.
What is a waveform
waveform
is a base64-formatted string that represents an array of 64 bytes. Each byte is a number from 0 to 127 representing the audio volume at different points in time.
For example: AAAAFiQ0Ng0IKC0eDzIsJCglHSYZIhwmIQwoEAkMCC0eEB0yLA8VGxgbGh0dAxgIERciHyAjKicjIRwfKzU6AA==
How to send an audio file via WhatsApp API
You will need an endpoint: POST https://gate.whapi.cloud/messages/voice
This method is responsible for sending a voice message for chats. Make sure the audio file has the extension .ogg and the opus codec.
How to generate custom waveform
So, as we have already said, waveform is an array of 64 integers from 0 to 127 - these are essentially 64 amplitudes, which are visualized as vertical bands. You get a sort of graph or โequalizerโ where each bar is one of these values, and the height is limited to 127.
Knowing the desired โpatternโ (i.e. the general shape of this graph), it is possible to select an array of such 64 values that would reproduce it.
But we need to understand the limitations:
Horizontally we have only 64 pixels - that's sort of the โwidth of the screenโ.
Vertically, we have 127 pixels maximum per strip.
Each stripe is one vertical line, the height of which is given by a single number.
You can pick up such an array by hand or using AI-tools. Below we will give some examples.
Important: When testing, always preview the audio message in the WhatsApp mobile app โ the Web version may cache the waveform image if the same audio file is reused.
Symmetrical wavy pattern:
Here's its base64 string:
Wave (sine wave), a soft, smooth shape:
Here's its base64 string:
Peak in the center. Center maximum and uniform decrease towards the edges:
Here's its base64 string:
Here are more options that look interesting:
Staircase. Smooth step increase - visually like climbing:
Saw (triangular waves). Repetitive shape with linear rise and fall - imitates a โsawโ:
Pulses (uniform peaks). Single sharp peaks on a flat background - similar to a โpulseโ:
How to generate original waveform
To generate a custom visual waveform for your audio file, youโll need to take a few additional steps on your side.
First, convert the audio to mono (single channel). Then extract the amplitude values, normalized to the range of -1.0 to 1.0 โ this is your raw waveform data. Divide the entire array into 64 equal segments and calculate the average absolute amplitude for each segment.
Multiply each average by 127, round the result, and convert it to an integer. Once you have 64 integer values (each between 0 and 127), convert them into a byte array and encode the result in base64.
Need help? Contact support anytime.
Last updated
Was this helpful?