Overview#

The ABR SDK synthesizes speech from text on-device, with no network round-trip. You push UTF-8 text bytes and receive synthesized PCM (uncompressed audio) back through a callback as the model produces it.

The TTS API is provided by the ttsabr_lib module. The main class you interact with is TtsTts.

A TTS application is an abr_app_t created from a TTS package with abr_lib.app_create. Text goes into its input buffer and audio comes out of its output buffer; the session helper from the tarball’s examples/common directory wraps that in abr_session_push and abr_session_wait_for_completion.

How synthesis works#

TTS accepts raw UTF-8 text bytes and produces mono PCM audio. You push text in pieces and a callback fires each time the model produces new audio. Output begins arriving before the full text has been consumed: the model streams audio as it synthesizes, sentence by sentence.

synthesize.py#
from abr_sdk.tts import Tts

# Male voice
LIBRARY_PATH = "/path/to/nith-5m-live.en-m1-linux-x86_64/libnith_5m_live.so"

text = b"Hello, world."

chunks: list[bytes] = []

with Tts(LIBRARY_PATH) as tts:
    tts.push(text, on_pcm=chunks.append)
    tts.wait_for_completion()

pcm = b"".join(chunks)

The push()abr_session_push() call runs the synthesis event loop until all input has been accepted: it can block while the model’s input buffer is full, and the on_pcm callback fires during the call as PCM becomes available. The callback passed to the first push() of a session is used for the whole session; the on_pcm argument on later calls is ignored (passing the same callback each time, as the examples do, is harmless). An optional output_poll_timeout_ms argument keeps the call waiting for output until that many milliseconds after push() was called. wait_for_completion()abr_session_wait_for_completion() signals end-of-input, flushes the synthesis pipeline, and blocks until all audio has been delivered through the callback.

synthesize.c#
#include <stdlib.h>
#include <string.h>

#include "common/session.h"

// Male voice
#define LIBRARY_PATH \
    "/path/to/nith-5m-live.en-m1-linux-x86_64/libnith_5m_live.so"

static const char TEXT[] = "Hello, world.";

static uint8_t *pcm;
static size_t pcm_bytes;

/**
 * Appends the audio to `pcm`.
 */
static void on_pcm(void *user_data, const uint8_t *data, size_t n_bytes) {
    (void)user_data;
    uint8_t *grown = realloc(pcm, pcm_bytes + n_bytes);
    if (grown == NULL) {
        abort();
    }
    pcm = grown;
    memcpy(pcm + pcm_bytes, data, n_bytes);
    pcm_bytes += n_bytes;
}

int main(void) {
    abr_session_t session;
    if (abr_session_open(&session, LIBRARY_PATH, NULL, 0) != ABR_OK) {
        return 1;
    }
    abr_session_push(&session, (const uint8_t *)TEXT, strlen(TEXT), on_pcm,
                     NULL);
    abr_session_wait_for_completion(&session, on_pcm, NULL);
    abr_session_close(&session);

    // use pcm and pcm_bytes here

    free(pcm);
    return session.status == ABR_OK ? 0 : 1;
}

abr_session_push runs the synthesis event loop until all input has been accepted: it blocks while the model’s input buffer is full, and on_pcm fires during the call as PCM becomes available. abr_session_wait_for_completion pushes a flush marker to signal end-of-input and blocks until all audio has been delivered through the callback. Underneath, text goes in with abr_lib.buf_push and audio comes out with abr_lib.buf_pull, paced by an event set; examples/tts.c in the tarball shows that loop in full.

Output format#

The PCM bytes delivered to on_pcm are in the same format as the audio the ASR API consumes:

Property

Value

Encoding

Signed 16-bit integer (S16)

Byte order

Little-endian (LE)

Channels

Mono (1 channel)

Sample rate

16,000 Hz

Container

Raw bytes. No file headers

One second of output is 32,000 bytes (16,000 samples × 2 bytes per sample). Each on_pcm call may deliver any number of samples.

Text normalization#

The TTS model itself expects clean, speakable text: no numbers written as digits, no acronyms, no accented characters. The backend normalizes pushed text into that form automatically, one sentence at a time, so raw text can be pushed as-is.

tts.push("Dr. Smith owed $42 to the WHO.".encode("utf-8"))
# spoken as "doctor Smith owed forty two dollars to the W H O."
const char text[] = "Dr. Smith owed $42 to the WHO.";
abr_session_push(&session, (const uint8_t *)text, strlen(text), on_pcm, NULL);
// spoken as "doctor Smith owed forty two dollars to the W H O."

See Input format for what normalization does.

What you need to use TTS#

To run TTS you need three things:

  • The SDK Python package (pip install abr-sdk).

  • The SDK C binding, compiled into your program (see Installation).

  • An application package for your target platform. This archive contains the compiled model, the network weights, and supporting files. You download it from the ABR developer portal and extract it on the device. See Application packages.

  • UTF-8 text. Numbers, dates, and abbreviations are converted to spoken words by the backend automatically.

Next steps

  • New to the SDK? Start with TTS quickstart.

  • Input format: the normalization pipeline and SSML markup.

  • Voices: the available voices and how to select one.

  • Examples: full, runnable examples for file output, speaker playback, and more.