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

# TTS quickstart

> Learn how to make your first Inworld TTS API request

Use the [TTS Playground](https://platform.inworld.ai/tts-playground) to try Inworld’s Text-to-Speech models, compare voices, adjust parameters, and preview instant voice clones. To build a real-time application, use the API for advanced features and integration options.

This quickstart shows how to make your first Text-to-Speech API request and generate high-quality, realistic speech from text.

These examples run locally or on your server. `INWORLD_API_KEY` contains the complete copied Base64 credential. Direct HTTP requests use Basic. Browser and mobile apps should use the [backend token flow](https://docs.inworld.ai/portal/ephemeral-tokens.md#connect-a-client-through-your-backend). For auth errors, see [recovery steps](https://docs.inworld.ai/portal/api-key-auth.md#recover-from-authentication-failures).

## Make your first streaming TTS API request
This quickstart walks through making your first streaming API request, which we recommend for realtime, low-latency applications.

For batch audio generation, pre-rendered content, and anywhere latency isn't critical, see [Make a non-streaming request](#make-a-non-streaming-request) below.

<Steps titleSize="h3">
    <Step title="Create an API key">
      Create an [Inworld account](https://platform.inworld.ai/signup).

      In [Inworld Portal](https://platform.inworld.ai/), open **Manage** > [**API Keys**](https://platform.inworld.ai/api-keys) and click **Generate new key**. Choose **Standard**, click **Generate**, then copy **Basic (Base64)** as-is; do not encode it again. Use a **Standard** key for direct TTS calls; Voice and Router write permissions are not needed for synthesis.

      <img src="https://static.inworld.ai/portal-doc/img/portal/api-keys-light.3959394b.png" alt="API Keys page with Basic (Base64), UI-masked credentials and a hidden email" className="dark:hidden" width="1216" height="247" />
      <img src="https://static.inworld.ai/portal-doc/img/portal/api-keys-dark.f13c2425.png" alt="API Keys page with Basic (Base64), UI-masked credentials and a hidden email" className="hidden dark:block" width="1216" height="247" />

      Set your API key as an environment variable.
      <CodeGroup>
        ```shell macOS and Linux
        export INWORLD_API_KEY='your-base64-api-key-here'
        ```
        ```shell Windows
        setx INWORLD_API_KEY "your-base64-api-key-here"
        ```
      </CodeGroup>
    </Step>
    <Step title="Install the SDK">
      Install the TTS SDK in the language of your choice.

        <CodeGroup>
            ```bash JavaScript
            npm install @inworld/tts
            ```
            ```bash Python
            pip install inworld-tts
            ```
        </CodeGroup>
    </Step>
    <Step title="Prepare your first streaming request">
      Create a new file called `inworld_stream_quickstart.py` or `inworld_stream_quickstart.js`, confirm `INWORLD_API_KEY` is set in your environment, and copy the code below into the file. This example uses the `WAV` encoding so you can write the streamed chunks directly into a single `.wav` file. The WAV header arrives on the first chunk. The rest are raw PCM samples.

       <CodeGroup>
        ```javascript JavaScript
        import { InworldTTS } from '@inworld/tts';
        import fs from 'fs';

        const tts = InworldTTS();
        const chunks = [];

        for await (const chunk of tts.stream({
            text: "What a wonderful day to be a text-to-speech model! I'm super excited to show you how streaming works.",
            voice: 'Ashley',
            encoding: 'WAV',
            sampleRate: 48000,
        })) {
            chunks.push(chunk);
            console.log(`Received ${chunk.length} bytes`);
        }

        fs.writeFileSync('output_stream.wav', Buffer.concat(chunks));
        console.log('Audio saved to output_stream.wav');
        ```
        ```python Python
        import asyncio
        from inworld_tts import InworldTTS

        async def main():
            tts = InworldTTS()
            chunks = []

            async for chunk in tts.stream(
                text="What a wonderful day to be a text-to-speech model! I'm super excited to show you how streaming works.",
                voice="Ashley",
                encoding="WAV",
                sample_rate=48000,
            ):
                chunks.append(chunk)
                print(f"Received {len(chunk)} bytes")

            with open("output_stream.wav", "wb") as f:
                f.write(b"".join(chunks))

            print("Audio saved to output_stream.wav")

        asyncio.run(main())
        ```
       </CodeGroup>

       <Note>
       This example uses `WAV`: the first chunk carries one WAV header, and the rest carry raw PCM samples. Concatenating them directly produces a valid `.wav` file. With `LINEAR16`, every chunk is a complete WAV file, so direct concatenation produces audible clicks at chunk boundaries. Strip the per-chunk RIFF headers yourself, or use `WAV` for direct `.wav` output. `PCM` is raw headerless sample data. Use it only if your client handles containerization or playback, such as by adding a WAV header or feeding the samples to an audio API. See [Generating Audio](https://docs.inworld.ai/tts/capabilities/generating-audio.md) for the full format reference.
       </Note>
    </Step>
    <Step title="Run the code">
        Run the code for Python or JavaScript. The console will print out as streamed bytes are written to the audio file.

        <CodeGroup>

            ```javascript JavaScript
            node inworld_stream_quickstart.js
            ```
            ```python Python
            python inworld_stream_quickstart.py
            ```

        </CodeGroup>

        You should see a saved file called `output_stream.wav`. You can play this file with any audio player.
    </Step>
</Steps>

## Make a non-streaming request

The synchronous endpoint is the simplest way to try Inworld TTS and works well for batch audio generation, pre-rendered content, and anywhere latency isn't critical. Assuming you've already set up your API key and installed the SDK:

<Steps titleSize="h3">
    <Step title="Prepare your first request">
      For Python or JavaScript, create a new file called `inworld_quickstart.py` or `inworld_quickstart.js`. Copy the corresponding code into the file.

       <CodeGroup>
        ```javascript JavaScript
        import { InworldTTS } from '@inworld/tts';
        import fs from 'fs';

        const tts = InworldTTS();

        const audio = await tts.generate({
            text: 'What a wonderful day to be a text-to-speech model!',
            voice: 'Ashley',
        });

        fs.writeFileSync('output.mp3', audio);
        console.log('Audio saved to output.mp3');
        ```

        ```python Python
        from inworld_tts import InworldTTS

        tts = InworldTTS()

        tts.generate(
            text="What a wonderful day to be a text-to-speech model!",
            voice="Ashley",
            output_file="output.mp3",
        )
        print("Audio saved to output.mp3")
        ```
       </CodeGroup>

    </Step>
    <Step title="Run the code">
        Run the code for Python or JavaScript, or enter the curl command into your terminal.

        <CodeGroup>

            ```bash JavaScript
            node inworld_quickstart.js
            ```
            ```bash Python
            python inworld_quickstart.py
            ```
        </CodeGroup>

        You should see a saved file called `output.mp3`. You can play this file with any audio player.
    </Step>
</Steps>


## Next Steps

Now that you've tried out the TTS API, you can explore more TTS capabilities.

<CardGroup cols={3}>
  <Card title="TTS overview" icon="waveform-lines" href="https://docs.inworld.ai/tts/tts.md">
    Understand the capabilities of Inworld's Realtime TTS models.
  </Card>

  <Card title="Voice Cloning" icon="microphone" href="https://docs.inworld.ai/tts/instant-voice-cloning.md">
    Create a personalized voice clone with as little as 3 seconds of audio.
  </Card>

  <Card title="Best Practices" icon="circle-check" href="https://docs.inworld.ai/tts/best-practices/overview.md">
    The checklist for expressive, fast, production-ready TTS.
  </Card>
</CardGroup>
