Skip to content

TTS (Text-to-Speech) Resource

Note: This capability is now provided as an installable component. See the Components guide for how to install and use it.

Install: kdeps registry install tts

Usage: run: { component: { name: tts, with: { text: "...", voice: "alloy", apiKey: "..." } } }

The TTS component synthesizes speech from text using OpenAI TTS (online) or espeak (offline fallback). It produces an audio file accessible by downstream resources.

Component Inputs

InputTypeRequiredDefaultDescription
textstringyesText to synthesize
voicestringnoalloyVoice identifier: alloy, echo, fable, onyx, nova, shimmer (OpenAI voices)
apiKeystringnoOpenAI API key (required for online synthesis; omit to use local espeak)

Using the TTS Component

Online (OpenAI):

yaml
run:
  component:
    name: tts
    with:
      text: "Hello, welcome to KDeps!"
      voice: alloy
      apiKey: "sk-..."

Offline (espeak, no API key required):

yaml
run:
  component:
    name: tts
    with:
      text: "Hello, welcome to KDeps!"

Access the output audio file path via output('<callerActionId>').


Result Map

KeyTypeDescription
successbooltrue if synthesis succeeded.
outputFilestringAbsolute path to the generated audio file.

Expression Support

The text field supports KDeps expressions:

yaml
run:
  component:
    name: tts
    with:
      text: "Hello {{ get('name') }}, your score is {{ get('score') }} points."
      voice: nova
      apiKey: "{{ env('OPENAI_API_KEY') }}"

Example: Voice Assistant Response

yaml
# resources/respond.yaml
metadata:
  actionId: respond
run:
  chat:
    model: llama3
    prompt: "{{ input() }}"

# resources/speak.yaml
metadata:
  actionId: speak
  requires: [respond]
run:
  component:
    name: tts
    with:
      text: "{{ output('respond') }}"
      voice: alloy
      apiKey: "{{ env('OPENAI_API_KEY') }}"

# resources/reply.yaml
metadata:
  actionId: reply
  requires: [speak]
run:
  apiResponse:
    success: true
    response:
      audioPath: "{{ output('speak').outputFile }}"

Installation

The espeak CLI is required for offline synthesis:

bash
apt install espeak-ng    # Debian/Ubuntu
brew install espeak      # macOS

For online synthesis, an OpenAI API key is sufficient — no local install needed.

Released under the Apache 2.0 License.