API Reference

Welcome to PlayHT

The PlayHT API provides a simple interface to our state-of-the-art AI TTS models. Follow this guide to get started.

1. Create authentication credentials

Generate a user ID and API key in the dashboard.

2. Install the SDK (optional)

npm install playht
pnpm install playht
yarn add playht
pip install pyht

3. Make your first request

import * as PlayHT from 'playht';
import fs from 'fs';

// Initialize client
PlayHT.init({
  userId: '<YOUR_USER_ID>',
  apiKey: '<YOUR_API_KEY>',
});

async function streamAudio(text) {
  const stream = await PlayHT.stream('Yooohoooo, big summer blowout!', { voiceEngine: 'PlayDialog' });
  stream.on('data', (chunk) => {
    // Do whatever you want with the stream, you could save it to a file, stream it in realtime to the browser or app, or to a telephony system
    fs.appendFileSync('output.mp3', chunk);
  });
  return stream;
}
curl --request POST \
     --url https://api.play.ht/api/v2/tts/stream \
     --header 'X-USER-ID: <YOUR_USER_ID>' \
     --header 'AUTHORIZATION: <YOUR_API_KEY>' \
     --header 'accept: audio/mpeg' \
     --header 'content-type: application/json' \
     --data '
{
  "text": "Hello from a realistic voice.",
  "voice_engine": "PlayDialog",
  "voice": "s3://voice-cloning-zero-shot/d9ff78ba-d016-47f6-b0ef-dd630f59414e/female-cs/manifest.json",
  "output_format": "mp3"
}
' --output result.mp3

4. Learn more

Input Streaming with LLMs

Our API supports Input streaming to make it seamless to integrate with LLMs like chatGPT, check this guide to see an example of how to use it.

Techniques to guarantee the lowest latency

Check this guide for some techniques to keep in mind when trying to achieve the lowest latency.

Audio streaming with Twilio

Follow this guide for integrating realtime audio streaming with Twilio for over the phone conversations.

Instant Voice Cloning

You can clone any voice instantly across languages with only 30 seconds of speech, try it easily in our API Playground, or through the API here.