> ## Documentation Index
> Fetch the complete documentation index at: https://docs.elbic.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Quick Start

> Get started with the KugelAudio text-to-speech API: hear a first clip with one cURL command, claim your free credit, install an SDK, generate speech and stream audio.

## Hear your first clip

Three steps from an API key to German speech playing on your machine. You need
cURL and [FFmpeg](https://ffmpeg.org) (`brew install ffmpeg`,
`sudo apt install ffmpeg` or `winget install ffmpeg`).

<Steps>
  <Step title="Create an API key">
    [Sign up and create a key in the dashboard](/api-reference/authentication#getting-your-api-key).
    New accounts start with [free credit](#free-credit-to-start). Put the key in
    your shell:

    ```bash
    export KUGELAUDIO_API_KEY="your_api_key"
    ```
  </Step>
  <Step title="Generate a WAV file">
    This sends a German sentence to `kugel-3.5` with the public voice `979`
    (Sara Wagner). The API streams back raw PCM
    ([Audio formats](/api-reference/tts/audio-formats)), and FFmpeg writes it to
    `hello.wav`:

    ```bash
    curl -sS --fail -X POST https://api.elbic.com/v1/tts/generate \
      -H "Authorization: Bearer $KUGELAUDIO_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{"text": "Hallo! Das ist mein erster Satz mit KugelAudio.", "model_id": "kugel-3.5", "voice_id": 979, "language": "de"}' \
      | ffmpeg -y -loglevel error -f s16le -ar 24000 -ac 1 -i - hello.wav
    ```

    Run it in bash or zsh; on Windows, use Git Bash. If curl reports an HTTP
    status such as `401` (missing or wrong key), look it up in
    [Errors](/api-reference/errors).
  </Step>
  <Step title="Play it">
    ```bash
    afplay hello.wav   # macOS
    aplay hello.wav    # Linux
    start hello.wav    # Windows
    ```

    To generate from code instead, install an SDK below.
  </Step>
</Steps>

## Free credit to start

Every new account gets €5 of Text to Speech credit once: at least 70 minutes
of audio with any model, no credit card, and the credit does not expire. The
rates for each model are on the
[pricing page](/en/pricing).

## Prerequisites

Before you begin, make sure you have:

- An API key: [sign up and create one in the dashboard](/api-reference/authentication#getting-your-api-key).
- Python 3.10+, Node.js 18+, Java 17+, or cURL (plus [FFmpeg](https://ffmpeg.org) to play the raw audio cURL returns)

## Installation

<Tabs>
  <Tab title="Python">
    Install the Python SDK using pip or uv:

    ```bash
    pip install kugelaudio
    ```

    Or with uv (recommended):

    ```bash
    uv add kugelaudio
    ```
  </Tab>
  <Tab title="TypeScript/JavaScript">
    Install the TypeScript/JavaScript SDK using your preferred package manager:

    ```bash
    npm install kugelaudio
    ```

    Or with yarn/pnpm:

    ```bash
    yarn add kugelaudio
    # or
    pnpm add kugelaudio
    ```
  </Tab>
  <Tab title="Java">
    Add the dependency to your `pom.xml` (requires Java 17+):

    ```xml
    <dependency>
      <groupId>com.kugelaudio</groupId>
      <artifactId>kugelaudio</artifactId>
      <version>3.0.0</version>
    </dependency>
    ```

    Or with Gradle:

    ```groovy
    implementation 'com.kugelaudio:kugelaudio:3.0.0'
    ```
  </Tab>
  <Tab title="cURL">
    cURL comes pre-installed on macOS, Linux, and Windows 10+. No installation needed.

    Set your API key as an environment variable:

    ```bash
    export KUGELAUDIO_API_KEY="your_api_key"
    ```
  </Tab>
</Tabs>

## Basic Usage

### Initialize the Client

<Tip>
  **Connect once at startup.** Call `connect()` once (JavaScript, Java) or use
  `await KugelAudio.create(...)` (async Python) so the first request does not
  pay the connection handshake. See [Latency](/latency#pre-connect-at-startup).
</Tip>

<Tabs>
  <Tab title="Python">
    ```python
    from kugelaudio import KugelAudio

    # Initialize for synchronous generate() / stream() calls
    client = KugelAudio(api_key="your_api_key")
    ```
  </Tab>
  <Tab title="JavaScript">
    ```typescript
    import { KugelAudio } from 'kugelaudio';

    // Initialize with your API key
    const client = new KugelAudio({ apiKey: 'your_api_key' });

    // Pre-connect at startup (handshake happens here)
    await client.connect();

    // Confirm connection is ready
    console.log(`Connected: ${client.isConnected()}`);

    // The first request no longer pays the handshake
    ```
  </Tab>
  <Tab title="Java">
    ```java
    import com.kugelaudio.sdk.KugelAudio;
    import com.kugelaudio.sdk.KugelAudioOptions;

    KugelAudio client = new KugelAudio(
        KugelAudioOptions.builder("your_api_key").build()
    );

    // Pre-connect at startup (handshake happens here)
    client.connect();

    // Confirm connection is ready
    System.out.println("Connected: " + client.isConnected());

    // The first request no longer pays the handshake
    ```
  </Tab>
  <Tab title="cURL">
    No client initialization needed. Pass the API key in the `Authorization`
    header; this request fails if the key is missing or invalid:

    ```bash
    curl --fail-with-body "https://api.elbic.com/v1/voices?limit=1" \
      -H "Authorization: Bearer $KUGELAUDIO_API_KEY"
    ```
  </Tab>
</Tabs>

### Generate Speech

<Tip>
  Examples below use `kugel-3.5`, the default model. To use the previous model, set the model ID to `kugel-3`. See [Models](/models) for details.
</Tip>

<Tabs>
  <Tab title="Python">
    ```python
    # Generate speech
    audio = client.tts.generate(
        text="Welcome to KugelAudio! This is high-quality text-to-speech.",
        model_id="kugel-3.5",
        voice_id=1071,
    )

    # Save to file
    audio.save("output.wav")

    # Or get the raw bytes
    wav_bytes = audio.to_wav_bytes()
    ```
  </Tab>
  <Tab title="JavaScript">
    ```typescript
    // Generate speech
    const audio = await client.tts.generate({
      text: 'Welcome to KugelAudio! This is high-quality text-to-speech.',
      modelId: 'kugel-3.5',
      voiceId: 1071,
    });

    // audio.audio is an ArrayBuffer with PCM16 data
    console.log(`Duration: ${audio.durationMs}ms`);
    ```
  </Tab>
  <Tab title="Java">
    ```java
    import com.kugelaudio.sdk.GenerateRequest;
    import com.kugelaudio.sdk.AudioResponse;

    AudioResponse audio = client.tts().generate(
        GenerateRequest.builder("Welcome to KugelAudio! This is high-quality text-to-speech.")
            .modelId("kugel-3.5")
            .voiceId(1071)
            .language("en")
            .build()
    );

    // Save to file
    audio.saveWav(java.nio.file.Path.of("output.wav"));
    ```
  </Tab>
  <Tab title="cURL">
    ```bash
    curl -X POST https://api.elbic.com/v1/tts/generate \
      -H "Authorization: Bearer $KUGELAUDIO_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "text": "Welcome to KugelAudio! This is high-quality text-to-speech.",
        "model_id": "kugel-3.5",
        "voice_id": 1071
      }' \
      --output output.pcm

    # Convert to WAV for playback
    ffmpeg -f s16le -ar 24000 -ac 1 -i output.pcm output.wav
    ```
  </Tab>
</Tabs>

### Stream Audio

For lower latency, stream audio chunks as they're generated:

<Tabs>
  <Tab title="Python">
    ```python
    # Synchronous streaming
    for chunk in client.tts.stream(
        text="Hello, this is streaming audio.",
        model_id="kugel-3.5",
        voice_id=1071,
    ):
        if hasattr(chunk, 'audio'):
            # Process audio chunk immediately
            print(f"Chunk {chunk.index}: {len(chunk.audio)} bytes")
            # play_audio(chunk.audio)
    ```

    For async applications:

    ```python
    import asyncio

    async def stream_audio():
        async for chunk in client.tts.stream_async(
            text="Async streaming example.",
            model_id="kugel-3.5",
            voice_id=1071,
        ):
            if hasattr(chunk, 'audio'):
                # Process chunk
                pass

    asyncio.run(stream_audio())
    ```
  </Tab>
  <Tab title="JavaScript">
    ```typescript
    await client.tts.stream(
      {
        text: 'Hello, this is streaming audio.',
        modelId: 'kugel-3.5',
        voiceId: 1071,
      },
      {
        onChunk: (chunk) => {
          console.log(`Chunk ${chunk.index}: ${chunk.samples} samples`);
          // Play or process the audio chunk
        },
        onFinal: (stats) => {
          console.log(`Total duration: ${stats.durationMs}ms`);
          console.log(`Generation time: ${stats.generationMs}ms`);
        },
      }
    );
    ```
  </Tab>
  <Tab title="Java">
    ```java
    import com.kugelaudio.sdk.StreamCallbacks;
    import com.kugelaudio.sdk.AudioChunk;

    client.tts().stream(
        GenerateRequest.builder("Hello, this is streaming audio.")
            .modelId("kugel-3.5")
            .voiceId(1071)
            .language("en")
            .build(),
        new StreamCallbacks() {
            @Override
            public void onChunk(AudioChunk chunk) {
                System.out.printf("Chunk %d: %d bytes%n",
                    chunk.getIndex(), chunk.getAudio().length);
                // playAudio(chunk.getAudio());
            }
        }
    );
    ```
  </Tab>
  <Tab title="cURL">
    The REST endpoint streams raw PCM bytes. Pipe them to `ffplay` for real-time playback:

    ```bash
    curl -X POST https://api.elbic.com/v1/tts/generate \
      -H "Authorization: Bearer $KUGELAUDIO_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "text": "Hello, this is streaming audio.",
        "model_id": "kugel-3.5",
        "voice_id": 1071
      }' \
      --no-buffer | ffplay -f s16le -ar 24000 -ac 1 -nodisp -autoexit -
    ```

    <Note>
      For advanced streaming (WebSocket-based, token-by-token from LLMs), use the
      [Python, JavaScript, or Java SDK](/streaming/overview) or the
      [raw WebSocket API](/api-reference/raw-api).
    </Note>
  </Tab>
</Tabs>

## Working with Voices

The examples above use voice `1071`. To pick another, list the voices your key
can use. The listing returns all voices, one page at a time; pass `language` to
get only the voices that speak it: `de` matches every German accent (`de-DE`,
`de-AT`), `de-AT` only Austrian German. See [Voices](/features/voices) for
pagination, voice details, and cloning.

<Tabs>
  <Tab title="Python">
    ```python
    german = client.voices.list(language="de", limit=100)
    for voice in german.voices:
        print(f"{voice.id}: {voice.name}")
    ```
  </Tab>
  <Tab title="JavaScript">
    ```typescript
    const german = await client.voices.list({ language: 'de', limit: 100 });
    for (const voice of german.voices) {
      console.log(`${voice.id}: ${voice.name}`);
    }
    ```
  </Tab>
  <Tab title="Java">
    ```java
    import com.kugelaudio.sdk.Voice;

    for (Voice voice : client.voices().list("de", null, 100, 0).getVoices()) {
        System.out.printf("%d: %s%n", voice.getId(), voice.getName());
    }
    ```
  </Tab>
  <Tab title="cURL">
    ```bash
    curl "https://api.elbic.com/v1/voices?limit=100" \
      -H "Authorization: Bearer $KUGELAUDIO_API_KEY"
    ```
  </Tab>
</Tabs>

<Tip>
  **Pick your voice deliberately.** Voices differ in baseline energy, age, and warmth. Listen to several with representative text before choosing one. Building an LLM-driven voice agent? See [Voice Agent Prompting](/guides/voice-prompting).
</Tip>

## Next Steps

<CardGroup cols={2}>
  <Card
    title="Generate Speech"
    icon="play"
    href="/features/generate"
  >
    All generation options and parameters
  </Card>
  <Card
    title="Streaming"
    icon="wave-pulse"
    href="/streaming/overview"
  >
    Real-time audio streaming techniques
  </Card>
  <Card
    title="Using Voices"
    icon="microphone"
    href="/features/voices"
  >
    Browse voices, paginate, and clone
  </Card>
  <Card
    title="Text Processing"
    icon="spell-check"
    href="/features/text-processing"
  >
    Normalization and spell tags
  </Card>
</CardGroup>

### Your SDK

<CardGroup cols={3}>
  <Card title="Python" icon="python" href="/sdks/quickstart?lang=python">
    Python SDK reference
  </Card>
  <Card title="TypeScript/JavaScript" icon="js" href="/sdks/quickstart?lang=typescript">
    TypeScript/JavaScript SDK reference
  </Card>
  <Card title="Java" icon="java" href="/sdks/quickstart?lang=java">
    Java SDK reference
  </Card>
</CardGroup>
