← Blog

·

How to transcribe customer voice messages and reply with AI on the WhatsApp Business API

Updated on November 4, 2026

To transcribe voice messages on the WhatsApp Business API, the flow has four steps: the webhook tells you an audio message arrived, your system swaps the media id for a temporary URL and downloads the file with your token, a speech-to-text model (such as OpenAI’s or Whisper running on your own server) turns the audio into text, and that text goes to your bot or AI, which replies through the API. Voice notes arrive as OGG with the Opus codec, can be up to 16 MB, and the media ID received in the webhook is valid for 7 days.

How the audio arrives in the webhook

When a customer sends a voice message, the messages webhook includes an audio object, as shown in the audio message reference:

{
  "from": "5511988887777",
  "id": "wamid.HBgLNTUxMTk4ODg4Nzc3NxUCABIYFjNFQjBDMEQ4",
  "timestamp": "1762250400",
  "type": "audio",
  "audio": {
    "mime_type": "audio/ogg; codecs=opus",
    "sha256": "wvqXMe6n7n1W0zphvLPoLj+s/NtKqmr3zZ7YzTP7xFI=",
    "id": "1908647269898587",
    "voice": true
  }
}
  • voice: true means it was recorded with WhatsApp’s voice recording button (a voice note).
  • id is the media ID you use to download the file.
  • Meta has also started including a url field for direct download, rolled out gradually since November 2025. Don’t rely on it: treat it as optional and fall back to the id.

Limits that matter

From the Cloud API media page:

ItemValue
Audio formatsAAC, AMR, MP3, M4A and OGG (Opus only, mono)
Maximum size16 MB
Download URL validity5 minutes
Validity of the media ID received in the webhook7 days

In short: download as soon as the webhook arrives and store the file yourself if you need it later. The full download walkthrough, with error handling, is in how to download media customers send.

Want to try it while you read? Create a Vectalk account and send your first message through the official API. Create free account →

Choosing a transcription model

You have two families of options:

  • Third-party API. OpenAI’s speech-to-text guide currently recommends the gpt-transcribe model and says whisper-1, gpt-4o-transcribe and gpt-4o-mini-transcribe are deprecated, with shutdown scheduled for February 26, 2027. The limit is 25 MB per file, above WhatsApp’s 16 MB. The API reference lists ogg among accepted formats (the guide doesn’t; if you get an error, convert to MP3 with ffmpeg).
  • A model on your own server. Open-source Whisper or faster-whisper run locally (they need ffmpeg). The audio never leaves your infrastructure, at the cost of CPU/GPU and maintenance.

Other cloud providers also offer speech-to-text APIs, such as Google Cloud Speech-to-Text. The code below isolates transcription in one function so you can switch models without touching the rest.

The Python code (FastAPI)

The example receives the webhook, returns 200 immediately and processes the audio in the background. If you don’t have the basic bot yet, start with WhatsApp bot with Python and FastAPI.

import os
import tempfile

import httpx
from fastapi import BackgroundTasks, FastAPI, Request
from openai import OpenAI

GRAPH = "https://graph.facebook.com/v26.0"
TOKEN = os.environ["WHATSAPP_TOKEN"]
PHONE_NUMBER_ID = os.environ["PHONE_NUMBER_ID"]
HEADERS = {"Authorization": f"Bearer {TOKEN}"}

app = FastAPI()
ai = OpenAI()  # reads OPENAI_API_KEY from the environment
processed = set()  # in production, use Redis or a database


@app.post("/webhook")
async def webhook(request: Request, tasks: BackgroundTasks):
    body = await request.json()
    for entry in body.get("entry", []):
        for change in entry.get("changes", []):
            for msg in change.get("value", {}).get("messages", []):
                if msg["type"] == "audio" and msg["id"] not in processed:
                    processed.add(msg["id"])
                    tasks.add_task(handle_audio, msg)
    return {"ok": True}  # answer fast; heavy work runs in the task


def download_audio(media_id: str) -> bytes:
    with httpx.Client(timeout=30) as http:
        meta = http.get(f"{GRAPH}/{media_id}", headers=HEADERS).json()
        file = http.get(meta["url"], headers=HEADERS)  # fails without the token
        file.raise_for_status()
        return file.content


def transcribe(audio: bytes) -> str:
    with tempfile.NamedTemporaryFile(suffix=".ogg") as tmp:
        tmp.write(audio)
        tmp.flush()
        with open(tmp.name, "rb") as f:
            r = ai.audio.transcriptions.create(model="gpt-transcribe", file=f)
    return r.text


def answer_with_ai(text: str) -> str:
    r = ai.responses.create(
        model=os.environ["OPENAI_MODEL"],
        instructions=(
            "You are Store X's assistant. Only answer about orders, "
            "delivery times and returns. If unsure, offer a human agent."
        ),
        input=text,
    )
    return r.output_text


def send_text(to: str, text: str, reply_to: str):
    httpx.post(
        f"{GRAPH}/{PHONE_NUMBER_ID}/messages",
        headers=HEADERS,
        json={
            "messaging_product": "whatsapp",
            "to": to,
            "type": "text",
            "context": {"message_id": reply_to},
            "text": {"body": text[:4096]},
        },
        timeout=30,
    )


def handle_audio(msg: dict):
    # mark as read and show "typing..." while processing
    httpx.post(
        f"{GRAPH}/{PHONE_NUMBER_ID}/messages",
        headers=HEADERS,
        json={
            "messaging_product": "whatsapp",
            "status": "read",
            "message_id": msg["id"],
            "typing_indicator": {"type": "text"},
        },
        timeout=30,
    )
    audio = download_audio(msg["audio"]["id"])
    text = transcribe(audio)
    reply = answer_with_ai(text)
    send_text(msg["from"], reply, msg["id"])

Notes on the code:

  • Answer the webhook quickly. Meta retries events that don’t get a 200, and transcription plus AI can take several seconds. That’s why processing runs in a task. In production, use a real queue, as explained in integration architecture with queues, retries and idempotency.
  • Deduplicate by wamid. Retries happen; without deduplication the customer gets two replies.
  • Typing indicator. The typing indicators page says it disappears when you reply or after 25 seconds, whichever comes first. Details in typing indicator and mark as read.
  • Quoted reply. context.message_id makes the reply quote the voice note, which helps when the customer sends several.
  • Language. To pin the language, OpenAI’s guide shows the languages field (for gpt-transcribe) sent through extra_body, for example extra_body={"languages": ["en"]}.

Variant with local Whisper

Just swap the transcribe function:

from faster_whisper import WhisperModel

model = WhisperModel("small", device="cpu", compute_type="int8")

def transcribe(audio: bytes) -> str:
    with tempfile.NamedTemporaryFile(suffix=".ogg") as tmp:
        tmp.write(audio)
        tmp.flush()
        segments, _ = model.transcribe(tmp.name, language="en")
        return " ".join(s.text.strip() for s in segments)

Best practices for a voice-message bot

  • Confirm what you understood. For orders, addresses or amounts, start the reply by repeating the key point (“Got it, you want to change the size on order 4521”). If the transcription was wrong, the customer corrects it right away.
  • Store the transcript with the conversation. The agent who takes over later reads the text instead of listening to the audio, and the history becomes searchable.
  • Handle long audio. A voice note several minutes long takes longer to transcribe and produces a big chunk of text for the AI. Set a duration or size limit and hand off to a human above it.
  • Log failures. If the download, transcription or AI fails, send a short message asking the customer to type instead, and log the error with the wamid for investigation.
  • Don’t transcribe what you don’t need. If the bot only handles one specific flow, ignore audio outside the active conversation or route it straight to the human queue.

Meta’s AI policy and the 24-hour window

Two rules limit what the bot can do:

  • AI policy. The platform terms prohibit AI providers from using the platform when AI is the main functionality offered (general-purpose assistants), and the AI providers page lists country exceptions, including Brazil since March 11, 2026. A bot that transcribes voice notes to serve your own business’s customers is a support use. What changed and what is still allowed is covered in Meta’s 2026 AI policy for the WhatsApp API.
  • Customer service window. A free-form text reply can only be sent within 24 hours of the customer’s last message. Since the customer’s voice note opens or renews the window, an immediate reply fits inside it. Since October 1, 2026, each number gets 1,000 free service messages per month; from the 1,001st on, each costs BRL 0.0350 for recipients in Brazil.

Always offer a path to a human agent when the transcription is poor or the topic is out of scope.

Privacy: voice is personal data

A person’s voice and what they say are personal data. In Brazil, they fall under the LGPD (General Data Protection Law, Law 13,709/2018); elsewhere, check your local data protection law. When you send the file to a transcription API, you share that data with a processor. Good practices: disclose it in your privacy policy, keep transcripts only as long as needed, don’t store the audio if you don’t need it, and prefer a local model for sensitive content (health, for example). More in LGPD and WhatsApp. This article is not legal advice.

How to do it with Vectalk

Vectalk is a proxy for the official WhatsApp API: the webhook you register on the instance receives the same payload as Meta’s. With an instance token (required for media), downloading is simpler, because there’s a route that returns the binary directly, without the temporary URL step:

VECTALK = "https://apis.vectalk.com.br/api"
HEADERS = {"Authorization": f"Bearer {os.environ['VECTALK_TOKEN']}"}

def download_audio(media_id: str) -> bytes:
    r = httpx.get(f"{VECTALK}/media/{media_id}/download", headers=HEADERS, timeout=30)
    r.raise_for_status()
    return r.content

Sending goes to POST https://apis.vectalk.com.br/api/messages with the same body, without the Phone Number ID in the URL, and mark-as-read uses the same route. The webhooks documentation asks for a 200 response within 20 seconds, one more reason to process audio in the background. Vectalk has no native AI in its dashboard: transcription and the bot run on your server. See media download in the docs or create your account.

Frequently asked questions

Does the WhatsApp API transcribe voice messages on its own?

No. Cloud API delivers the audio file; you handle transcription, with a speech-to-text API or a model running on your own server.

Why does the audio download return 401 or 404?

Without the Authorization header with your token, the download fails. If more than 5 minutes have passed, the URL has expired: query the media ID again to get a new one. After 7 days, the webhook’s media ID also expires.

Do I need to convert the OGG file before transcribing?

OpenAI’s API reference accepts ogg, and local Whisper reads OGG through ffmpeg. If your provider doesn’t, convert to MP3 or WAV with ffmpeg before sending.

Can I reply with audio instead of text?

Yes: generate audio with a text-to-speech service and send it as an audio media message within the 24-hour window. See how to send media with the WhatsApp API.

Does transcribing audio with AI break Meta’s policy?

Using AI to serve your own business’s customers is different from offering a general-purpose AI assistant, which is what the terms restrict. Keep the bot focused on your service, with a handoff to a human.


Official sources checked on November 4, 2026: Audio message webhook (Meta), Cloud API media (Meta), Text messages (Meta), Typing indicators (Meta), WhatsApp Business Platform terms, AI providers (Meta), OpenAI speech-to-text guide, OpenAI transcription reference, Whisper (OpenAI GitHub), faster-whisper (GitHub), Law 13,709/2018 (LGPD), Vectalk media download, Vectalk webhooks.

Put your business on the official WhatsApp

Create your account, connect your number to the official API (you can keep the app with coexistence) and start serving customers and sending messages.