Dub: translate and speak

quoted per request from $0.14USDC via x402POST /api/dub

Translate a text into a target language and speak the translation, in one paid call. Send POST /api/dub with the required fields text and targetLanguage and pay quoted per request from $0.14 over x402 or MPP (there is no free tier). It returns raw bytes, not JSON, with Content-Type audio/mpeg, audio/ogg, audio/aac, audio/flac, audio/wav or audio/pcm.

The translation runs on the /v1/chat/completions gateway tier and the speech on /api/tts (tier "standard", $0.140) or /api/tts-hd (tier "hd", $0.260); the price is the sum of the two. Answers the audio as raw bytes (mp3, opus, aac, flac, wav or pcm) with the translation, the detected source language and the models that served in the X-Dub-Translation header (base64 JSON); add json: 1 or format "json" for a JSON answer with the audio base64 in it. targetLanguage is a BCP-47 tag or an English name. The same ten standard voice names and named voices as the speech tiers. Text capped at 2000 chars, checked before any model call, and the cap applies to the translation. A failed step answers an error naming the step and is not charged. Model-backed.

Category: AI & computeTags: dub translate translation tts text-to-speech speech audio voiceAlso found as: translate-speak translate-and-speak dubbing

Try in playground →

Parameters

NameTypeRequiredDescription
textstringyesText to translate and speak (max 2000 chars; the cap also applies to the translation) Also accepted as content, str, string, input, body, data.
targetLanguagestringyesTarget language: a BCP-47 tag (es, pt-BR, zh-Hans, ja) or an English name (Spanish, Brazilian Portuguese)
sourceLanguagestringnoOptional source language, same forms; detected when omitted
voicestringnoVoice: alloy, ash, ballad, coral, echo, fable, nova, onyx, sage, shimmer (default: alloy), or a named voice (george, sarah, adam, alice, bella, bill, brian, callum, charlie, chris, daniel, eric, harry, jessica, laura, liam, lily, matilda, river, roger, will)
formatstringnoAudio format: mp3, opus, aac, flac, wav, pcm (default: mp3), or "json" for a JSON answer carrying the audio base64 as mp3
tierstringno"standard" (default, speech on /api/tts) or "hd" (speech on /api/tts-hd, priced at that tier's sum)
jsonbooleannotrue (or ?json=1) answers JSON with the audio base64 instead of raw bytes

Example request

curl -i -X POST https://agent402.tools/api/dub \
  -H "Content-Type: application/json" \
  -d '{"text":"Hello from Agent402! Every tool is paid per call.","targetLanguage":"es","voice":"nova","format":"mp3","json":true}'

Without payment this returns HTTP 402 Payment Required with the exact price for dub; any x402 v2 or MPP client pays it and retries.

Example response

A 200 carries raw bytes, not JSON, with Content-Type audio/mpeg, audio/ogg, audio/aac, audio/flac, audio/wav or audio/pcm: the file itself.

From an MCP client

catalog.call {
  "slug": "dub",
  "params": {
    "text": "Hello from Agent402! Every tool is paid per call.",
    "targetLanguage": "es",
    "voice": "nova",
    "format": "mp3",
    "json": true
  }
}

The hosted connector at https://agent402.tools/mcp needs a payment for dub; the stdio package pays it from a wallet or from an AGENT402_CREDITS_KEY issued earlier. Local install: npx -y agent402-mcp.

Errors and behavior

Paid call (JavaScript agent)

import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";

const client = new x402Client();
client.setSpendControls?.({ maxAmountPerPayment: "$0.26" }); // refuse any quote above this tool's price
registerExactEvmScheme(client, { signer: privateKeyToAccount(KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);

const res = await payFetch("https://agent402.tools/api/dub", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    "text": "Hello from Agent402! Every tool is paid per call.",
    "targetLanguage": "es",
    "voice": "nova",
    "format": "mp3",
    "json": true
  }),
});

Related tools

Text-to-speech

$0.12 · POST /api/tts

Convert text to speech with the eleven-v4-turbo model: returns audio (the base64-encoded file in the format asked.

Text-to-speech (HD)

$0.24 · POST /api/tts-hd

Convert text to speech with the eleven-v4 model, the most expressive speech tier (inline audio tags such as [whispering].

Text-to-speech (lite)

$0.005 · POST /api/tts-lite

Convert text to speech with Kokoro-82M, a fraction of the price of /api/tts.

Text-to-speech (OpenAI-compatible)

$0.06 · POST /v1/audio/speech

OpenAI-compatible text-to-speech over x402 - point any OpenAI SDK's audio.speech.create() at base_url.

Speech-to-text

$0.03 · POST /api/transcribe

Transcribe audio to text with the gpt-transcribe model.

Speech-to-text (Pro)

$0.10 · POST /api/transcribe-pro

Transcribe audio to text with the gpt-transcribe model - the same model as /api/transcribe with a longer cap.