Skip to content

Dub: translate and speak

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

AI-generated voice: tell listeners so.

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

Try in playground →

Details

Translate a text into a target language and speak the translation, in one paid call. 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 on x402, card and credits. Some calls are paid before they run; a failed one can be retried free with the same payment, or is refunded. Model-backed.

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. Up to 2000 characters.
targetLanguagestringyesTarget language: a BCP-47 tag (es, pt-BR, zh-Hans, ja) or an English name (Spanish, Brazilian Portuguese) The example sends es.
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) The example sends nova.
formatstringnoAudio format: mp3, opus, aac, flac, wav, pcm (default: mp3), or "json" for a JSON answer carrying the audio base64 as mp3 The example sends 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 The example sends true.

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}'

Watch a call get paid

RequestPOST /api/dub
402from $0.14 USDC
SignPAYMENT-SIGNATURE
Settleon 14 chains
Answer200 OK
ReceiptAgent402-ReceiptEd25519

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
  }
}

Hosted connector (https://agent402.tools/mcp): paid in the call. Stdio package (npx -y agent402-mcp@0.20.0): pays from a wallet or AGENT402_CREDITS_KEY.

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(process.env.AGENT_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
  }),
});

Get a wallet or run npx -y agent402-mcp@0.20.0 wallet new.

The quote (Python)

import base64, json, urllib.error, urllib.request

req = urllib.request.Request("https://agent402.tools/api/dub", method="POST", data="{\"text\":\"Hello from Agent402! Every tool is paid per call.\",\"targetLanguage\":\"es\",\"voice\":\"nova\",\"format\":\"mp3\",\"json\":true}".encode(), headers={"Content-Type": "application/json"})
try:
    urllib.request.urlopen(req)
except urllib.error.HTTPError as e:
    quote = json.loads(base64.b64decode(e.headers["PAYMENT-REQUIRED"]))
    print(e.code, [(a["network"], a["amount"]) for a in quote["accepts"]])  # the price, per chain, in base units

Related tools