TTS quickstart#
This page walks you from a fresh install to synthesized audio. You will write a short program, run it, and understand what each part does.
Prerequisites#
You need:
Python 3.10+ and
piporuvThe ABR SDK:
pip install abr-sdk
The ABR SDK C binding, extracted from the tarball on the ABR developer portal, and a C99 compiler.
A TTS application package downloaded and extracted from the ABR developer portal. You should have a directory containing a
.soshared library file.An activated license for this device. See License activation.
If you have not downloaded an application package yet, follow Installation first.
Write the script#
Create a file called tts_quickstart.py:
import subprocess
from pathlib import Path
from abr_sdk.tts import Tts
# Female voice
LIBRARY_PATH = "/path/to/nith-5m-live.en-f1-linux-x86_64/libnith_5m_live.so"
text = b"Hello, world. Welcome to on-device text-to-speech."
chunks: list[bytes] = []
with Tts(LIBRARY_PATH) as tts:
tts.push(text, on_pcm=chunks.append)
tts.wait_for_completion()
Path("output.pcm").write_bytes(b"".join(chunks))
print("Wrote output.pcm")
subprocess.run(
["aplay", "-f", "S16_LE", "-r", "16000", "-c", "1", "output.pcm"], check=True
)
Replace LIBRARY_PATH with the path to the shared library inside your extracted application
package.
The tarball ships this program as examples/docs/tts_quickstart.c. It uses the
session helper from the tarball’s examples/common directory,
which opens the package and streams data through it:
#include <stdio.h>
#include <string.h>
#include "common/session.h"
// Female voice
#define LIBRARY_PATH \
"/path/to/nith-5m-live.en-f1-linux-x86_64/libnith_5m_live.so"
static const char TEXT[] = "Hello, world. Welcome to on-device text-to-speech.";
static void on_pcm(void *user_data, const uint8_t *data, size_t n_bytes) {
fwrite(data, 1, n_bytes, user_data);
}
int main(void) {
FILE *output = fopen("output.pcm", "wb");
if (output == NULL) {
return 1;
}
abr_session_t session;
if (abr_session_open(&session, LIBRARY_PATH, NULL, 0) != ABR_OK) {
fclose(output);
return 1;
}
abr_session_push(&session, (const uint8_t *)TEXT, strlen(TEXT), on_pcm,
output);
abr_session_wait_for_completion(&session, on_pcm, output);
abr_session_close(&session);
fclose(output);
printf("Wrote output.pcm\n");
return session.status == ABR_OK ? 0 : 1;
}
Replace LIBRARY_PATH with the path to the shared library inside your extracted application
package.
Run it#
python tts_quickstart.py
You should see Wrote output.pcm and hear the synthesized audio play automatically. To play back the
audio from the generated audio file, run:
aplay -f S16_LE -r 16000 -c 1 output.pcm # Linux
From the tarball’s top directory, compile the program with the binding and the helpers, run it, then play the file it wrote:
cc -std=c99 -Iabr_sdk -Iexamples abr_sdk/*.c examples/common/*.c examples/docs/tts_quickstart.c -o tts_quickstart
./tts_quickstart
aplay -f S16_LE -r 16000 -c 1 output.pcm # Linux
You should see Wrote output.pcm and hear the synthesized audio.
What just happened#
b"...": push()abr_session_push() takes UTF-8 bytes. The text can
contain digits, currency amounts, and abbreviations; the backend converts them to spoken words
before synthesis.
with Tts(LIBRARY_PATH) as tts:: The with block opens the application package and loads the
neural network on entry. On exit, whether normal or on exception, the SDK releases the loaded library
and all internal buffers.
tts.push(text, on_pcm=chunks.append): Feeds the text to the model. The call returns once all
of the text has been accepted by the pipeline, and the on_pcm callback can fire during the call
as the model produces PCM audio; here it appends each chunk to the chunks list.
tts.wait_for_completion(): Signals end-of-input, flushes the synthesis pipeline, and blocks
until all audio has been delivered through on_pcm.
b"".join(chunks): Concatenates the individual PCM chunks into one continuous byte string.
subprocess.run(["aplay", ...]): Plays back the saved file immediately using aplay. The
-f S16_LE -r 16000 -c 1 flags tell aplay to interpret the raw bytes as signed 16-bit
little-endian mono audio at 16 kHz, matching the format the TTS model produces.
static const char text[]: the input is UTF-8 text. It can contain digits, currency amounts,
and abbreviations; the backend converts them to spoken words before synthesis.
abr_session_open(&session, LIBRARY_PATH, NULL, 0): opens the application package with
abr_lib_open() and loads the neural network with abr_lib.app_create, reading the
weights from the directory that holds the library and the license from the directory abr-sdk activate wrote to.
abr_session_push(&session, text, strlen(text), on_pcm, output): feeds the text to the model
through abr_lib.buf_push. The call returns once all of the text has been accepted, and
on_pcm fires during the call as the model produces PCM audio; here it writes each run of bytes to
output.pcm with fwrite.
abr_session_wait_for_completion(&session, on_pcm, output): pushes a flush marker to signal
end-of-input and keeps pulling output with abr_lib.buf_pull until the marker comes out
the other side, so all audio has been delivered through on_pcm.
abr_session_close(&session): frees the application and unloads the library. Errors are
recorded in session.status as they happen, so the program checks once at the end.
aplay -f S16_LE -r 16000 -c 1 output.pcm: plays the file back as signed 16-bit little-endian
mono audio at 16 kHz, matching the format the TTS model produces.
The helper suits a desktop program. On an embedded target, write the loop it wraps yourself; see Without the session helper.
Next steps
Input format: how the backend normalizes numbers, acronyms, and abbreviations, and the SSML markup it supports.
Examples: ready-to-run examples for streaming to speakers, synthesizing multiple sentences, and reading from stdin.
Overview: how the streaming model works and the PCM output format in detail.