--- description: 'TTS quickstart for the ABR SDK: install the package, download an application package, and synthesize your first speech in under five minutes.' --- # 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: ::::{lang-set} :::{lang} python - **Python 3.10+** and `pip` or `uv` - **The ABR SDK**: `pip install abr-sdk` ::: :::{lang} c - **The ABR SDK C binding**, extracted from the tarball on the [ABR developer portal](https://dev.appliedbrainresearch.com), and a C99 compiler. ::: :::: - **A TTS application package** downloaded and extracted from the [ABR developer portal](https://dev.appliedbrainresearch.com). You should have a directory containing a `.so` shared library file. - **An activated license** for this device. See {doc}`/sdk/getting-started/license-activation`. If you have not downloaded an application package yet, follow {doc}`/sdk/getting-started/installation` first. ## Write the script ::::::{lang-set} :::::{lang} python Create a file called `tts_quickstart.py`: ```{example} tts_quickstart.py ``` Replace `LIBRARY_PATH` with the path to the shared library inside your extracted application package. ::::: :::::{lang} c The tarball ships this program as `examples/docs/tts_quickstart.c`. It uses the {doc}`session helper ` from the tarball's `examples/common` directory, which opens the package and streams data through it: ```{example} tts_quickstart.c ``` Replace `LIBRARY_PATH` with the path to the shared library inside your extracted application package. ::::: :::::: ## Run it ::::{lang-set} :::{lang} python ```bash 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: ```bash aplay -f S16_LE -r 16000 -c 1 output.pcm # Linux ``` ::: :::{lang} c From the tarball's top directory, compile the program with the binding and the helpers, run it, then play the file it wrote: ```bash 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 ::::{lang-set} :::{lang} python **`b"..."`**: {api}`Tts.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. ::: :::{lang} c **`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 {c:func}`abr_lib_open` and loads the neural network with {c:member}`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 {c:member}`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 {c:member}`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](tts-without-session-helper). ::: :::: :::{admonition} Next steps :class: hint - {doc}`/sdk/tts/input-format`: how the backend normalizes numbers, acronyms, and abbreviations, and the SSML markup it supports. - {doc}`/sdk/tts/examples`: ready-to-run examples for streaming to speakers, synthesizing multiple sentences, and reading from stdin. - {doc}`/sdk/tts/overview`: how the streaming model works and the PCM output format in detail. :::