Skip to main content
The node-tts template illustrates how to convert text-to-speech using the TTS node.
Architecture
  • Backend: Inworld Agent Runtime
  • Frontend: N/A (CLI example)

Prerequisites

Run the Template

  1. Clone the templates repository:
  2. Install the Runtime SDK inside the cli directory.
  3. Set up your Base64 Runtime API key by copying the .env-sample file into a .env file in the cli folder and adding your API key.
    .env
  4. Try a different model or voice! You can specify the model using the --modelId parameter and a voice using the --voiceName parameter:

Understanding the Template

The main functionality of the template is contained in the run function, which demonstrates how to use the Inworld Agent Runtime to convert text-to-speech using the TTS node. Now let’s break down the template into more detail:

1) Node Initialization

We start by creating the TTS node.
When creating the TTS node, you can specify:
  • id: A unique identifier for the node
  • speakerId: The voice to use for synthesis (see available voices)
  • modelId: The TTS model to use for synthesis
  • sampleRate: Audio output sample rate
  • temperature: Controls randomness in synthesis
  • speakingRate: Controls the speed of speech (1.0 is the voice’s natural speed)

2) Graph initialization

Next, we create the graph using the GraphBuilder, adding the TTS node and setting it as both start and end node:
The GraphBuilder configuration includes:
  • id: A unique identifier for the graph
  • apiKey: Your Inworld API key for authentication
  • enableRemoteConfig: Whether to enable remote configuration (set to false for local execution)
In this example, we only have a single TTS node, setting it as the start and end node. In more complex applications, you could connect other nodes, like a LLM node, to the TTS node to create a processing pipeline.

3) Graph execution

Now we execute the graph with the text input directly:
The text input is passed directly to the graph, which will be processed by the TTS node.

4) Response handling

The audio generation results are handled using the processResponse method, which supports streaming audio responses:
The response handler processes:
  • TTSOutputStream: Streaming audio responses containing both text and audio data
  • chunk.text: The text being synthesized
  • chunk.audio.data: The audio data as Float32Array samples

5) Audio file creation

Then, we encode the audio data and save it as a WAV file: