This reference is for people building a web page that reads its text aloud to a visitor. The page requests an audio clip from NomNomzBot and plays it in the visitor’s browser. For speech heard on your stream, use Text to speech instead.
The dashboard uses this service on its Privacy Policy and Terms of Service pages. Your own site can use it after the bot’s operator allows that site’s origin: its scheme, host and port. There is no dashboard switch for adding an allowed site, so self-hosting access is needed for that configuration.
Send a request
Send one request for each piece of text.
The route sits on the address of your bot.
The examples use bot.example.com.
Write the address of your own bot instead.
POST /api/v1/public/read-aloud
Host: bot.example.com
Origin: https://docs.nomnomz.bot
Content-Type: application/json
{ "text": "Welcome to the stream.", "locale": "en" }
| Field | What it holds |
|---|---|
text | The text to speak. 1 to 500 UTF-16 code units after trimming whitespace from both ends; some emoji count as two units. |
locale | The language of the page: en, nl, or a locale such as nl-NL or pt_BR. A request with no locale, or an empty one, gets a 400 answer. |
The request needs no sign-in.
A good answer is audio in the audio/mpeg format (MP3).
The example’s Origin must be one of the operator’s allowed origins.
Browser scripts let the browser supply this header; a command-line client must include it explicitly.
The answer is the audio itself, not a link. In a script, check the response before treating it as audio. Read a successful response as a blob, play it through an audio element, and release the temporary address when playback ends. Call this function from a visitor’s play control and show any error beside that control.
async function readSentence(text, locale) {
const response = await fetch("https://bot.example.com/api/v1/public/read-aloud", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ text, locale }),
});
if (!response.ok) {
throw new Error(`Read aloud failed (${response.status}).`);
}
const clip = URL.createObjectURL(await response.blob());
const audio = new Audio(clip);
const release = () => URL.revokeObjectURL(clip);
audio.addEventListener("ended", release, { once: true });
audio.addEventListener("error", release, { once: true });
try {
await audio.play();
} catch (error) {
release();
throw error;
}
return audio;
}
Choose POST or GET
Use POST from a script.
The route also answers a GET request with the same two fields as the query values text and locale.
A good answer to the GET form carries a cache header, so the browser and any cache in front of the bot keep the clip.
The header allows a browser to keep it for 7 days and a shared cache to keep it for 30 days.
The POST form carries no such header.
Use this service for public page text. GET places the text in the URL and explicitly permits shared caching of the audio; the origin check is not a privacy boundary.
Do not point an audio element at the GET address.
That request sends no Origin header, so the bot refuses it (see “Use it from another site”).
Pick one sentence at a time
The endpoint limits each request to 500 characters; it does not require the text to be a grammatical sentence. For a readable page, one sentence per request gives the visitor a useful unit for pause, repeat and navigation. Split the page into sentences and send one request for each sentence. Ask for the next sentence while the current one plays to reduce pauses. Network and synthesis delays can still leave a gap.
Keep each clip in the memory of the page until the reading stops, so a repeat is free. The dashboard reads headings, paragraphs, list items and table cells. It skips code blocks, menus, headers, footers and hidden text.
Which voice speaks
The route does not use the voice setting of any channel. It always picks the voice itself, from the language of the request.
| Language | Voice |
|---|---|
English (en, or a locale such as en-US) | The platform default voice. A channel follows it until the channel picks its own voice (see Text to speech). |
| Any other language | A Microsoft Edge voice for that language. A locale whose country code repeats the language code comes first, for example nl-NL for nl; otherwise the bot sorts matching voice identifiers alphabetically. |
| A language with no voice | The platform default voice. |
The choice comes from the locale and the bot’s current voice catalog or platform default, rather than a visitor’s channel voice. Changing that catalog or platform default can therefore change the voice used for later requests.
Answers and limits
| Answer | Meaning |
|---|---|
| 200 | Audio, in the audio/mpeg format. |
| 400 | The locale is missing, empty, or not a language or locale code. Or the text is missing, empty or longer than 500 characters. |
| 403 | The site that sent the request is not allowed. See the next section. |
| 429 | The visitor sent too many requests. The limit is 40 requests each minute for each IP address. |
| 503 | The voice cannot speak right now. The page should stop and tell the visitor. |
A 429 answer carries a Retry-After header with the number of seconds to wait.
The current CORS policy does not expose this header to JavaScript on another origin.
That page can detect status 429, but cannot read the delay with response.headers.get('Retry-After'); stop automatic requests and offer a later retry.
An empty clip counts as a failure and also answers 503.
A 400, 403 or 503 that the route itself sends carries the header Cache-Control: no-store, so no cache keeps a refusal.
One 400 is different.
A request that leaves out text or locale, or sends one of them empty or with only spaces, gets the 400 of the web framework instead.
This is the same for GET and POST.
That answer carries no no-store header.
The public read-aloud service admits at most 2 calls at the same moment per API process, shared by all visitors to that process. A request that finds both places busy waits up to 30 seconds for a slot, and then answers 503 if neither becomes available. This is a queue wait limit, not a total synthesis timeout. The slot is acquired before checking the TTS memory cache.
The bot keeps up to 200 successful clips in process memory. A later request with the same text, voice and speech adjustments can reuse a cached clip; simultaneous cache misses can still synthesize the same text more than once. The text to speech of the bot shares that memory. When it is full, the bot drops one clip to make room, and a restart clears all of them. The configured voice can also fall back to an Edge voice when synthesis fails, so the selected catalog voice is not an unconditional guarantee of the voice heard.
Use it from another site
The bot answers only a request whose Origin header names an allowed site.
A browser sends that header when a script calls the route with fetch from another site, and on every POST.
A plain audio element that points at the GET address sends none.
A request with no Origin header gets a 403 answer, so that audio element, a plain script and a curl call are refused by default.
The origin check is not caller authentication: a program outside the browser can supply the header itself.
The endpoint also applies its text, rate, and synthesis-concurrency limits.
The allowed sites are:
- The public address of the bot, from the
App:BaseUrlsetting. This is the address that you set asAPI_BASE_URL. - The sites in the
ReadAloud:Originssetting. Without that setting, these two are allowed:https://docs.nomnomz.botandhttps://docs-dev.nomnomz.bot.
Write each site exactly as the browser shows it, with the scheme, the host and the port.
A site in ReadAloud:Origins replaces the two default sites, so list them again if you still want them.
The route does not allow cookies or sign-in details from the other site, so the page gets the audio and nothing else.
Set the allowed sites
Only the person who runs the bot can change these two settings. The bot reads them when it starts.
- Copy
.env.exampleto.env, if you do not have one yet. Open.envin the project folder of the bot and setAPI_BASE_URLto the public address, for examplehttps://bot.example.com. The default ishttp://localhost:5080. The compose file passes it to the bot asApp:BaseUrl. - Open your compose file,
docker-compose.ymlordocker-compose.lite.yml. Add one line for each site at the end of the bot’senvironmentlist, as the next two steps show. The first site ends in__0, the next in__1, and so on. - In
docker-compose.yml, the list sits in thex-api-serviceblock at the top of the file, not underapi-blueorapi-green. Add the lines after the last item of that list, with four spaces of indent. Do not add a secondenvironmentkey toapi-blueorapi-green, because it would replace the whole shared list. - In
docker-compose.lite.yml, add the lines at the end ofenvironmentunder theapiservice, with six spaces of indent. - Start the bot again.
This is the form for docker-compose.yml:
- ReadAloud__Origins__0=https://docs.nomnomz.bot
- ReadAloud__Origins__1=https://www.example.com
This is the form for docker-compose.lite.yml:
- ReadAloud__Origins__0=https://docs.nomnomz.bot
- ReadAloud__Origins__1=https://www.example.com
The shipped compose files have no .env variable for ReadAloud:Origins, so the lines go into the compose file itself.
For the install steps, see Install with Docker.