This quickstart guide will help you programmatically convert text into audio using PlayAI’s models.

Check out our Playground for a quick way to try out our voices without writing any code.

Prerequisites

Converting Text to Speech

1

Set Up Your Environment

First, let’s set up your API credentials securely:

  echo 'export PLAYAI_KEY="your_api_key_here"' >> ~/.zshrc
  echo 'export PLAYAI_USER_ID="your_user_id_here"' >> ~/.zshrc
  source ~/.zshrc
2

Create Your First Audio

Run the following script to create your first audio.

curl -X POST 'https://api.play.ai/api/v1/tts/stream' \
  -H "Authorization: Bearer $PLAYAI_KEY" \
  -H "Content-Type: application/json" \
  -H "X-USER-ID: $PLAYAI_USER_ID" \
  -d '{
    "model": "PlayDialog",
    "text": "Hello! This is my first text-to-speech audio using PlayAI!",
    "voice": "s3://voice-cloning-zero-shot/baf1ef41-36b6-428c-9bdf-50ba54682bd8/original/manifest.json",
    "outputFormat": "wav"
  }' \
  --output hello.wav

Understanding the Code

Let’s break down the key components:

  1. Authentication: We use environment variables for secure credential management
  2. Request Headers: Include your API key and user ID for authentication
  3. Request Body:
    • model: Set to PlayDialog for our advanced TTS model
    • text: The text you want to convert to speech
    • voice: URL to the voice manifest (using a default voice for this example)
    • outputFormat: The audio format (wav or mp3)

Next Steps

  1. Try Different Voices: Explore our voice library
  2. Create Multi-speaker Dialogues: Learn how to create conversations
  3. Stream Audio: Check out our WebSocket API for real-time streaming

Troubleshooting

Common issues and solutions:

  1. Authentication Errors

    • Verify your API key and user ID are correct
    • Ensure the ‘Bearer ’ prefix is included in the Authorization header
  2. API Errors

    • Check the API endpoint URL is correct
    • Verify the model name is PlayDialog
    • Ensure your text input is valid
  3. File Saving Issues

    • Check write permissions in your working directory
    • Verify sufficient disk space

Need more help? Check out our troubleshooting guide or error messages.