Realtime audio streaming using our REST API

Get started in 2 mins with our HTTP REST API, you can also use our Python SDK or Nodejs SDK streaming.

🚧

Model Version

For the lowest realtime latency, you must use Voice Engine PlayHT2.0-turbo when calling the HTTP API.

PlayHT2.0-turbo is the latest version of our Conversational Text to Voice model called Gargamel, and has improved quality and reliability especially with handling acronyms, emails, phone numbers, addresses, etc.

Get your Credentials

To use the HTTP API you will need an API Key and a User Id, you can easily generate those, check this guide for a how-to.

Let's Stream

Let's stream some sentences and get the audio buffer back. Swap out the placeholders with your credentials.

curl --request POST \
     --url https://api.play.ht/api/v2/tts/stream \
     --header 'AUTHORIZATION: <YOUR_PLAY_HT_API_KEY>' \
     --header 'X-USER-ID: <YOUR_PLAY_HT_USER_ID>' \
     --header 'accept: audio/mpeg' \
     --header 'content-type: application/json' \
     --data '
{
  "text": "Hey, this is Jennifer from Play. Please hold on a moment, let me just um pull up your details real quick.",
  "voice": "s3://voice-cloning-zero-shot/d9ff78ba-d016-47f6-b0ef-dd630f59414e/female-cs/manifest.json",
  "output_format": "mp3",
  "speed": 1,
  "sample_rate": 44100,
  "voice_engine": "PlayHT2.0-turbo"
}
'
import fs from "fs";
import fetch from "node-fetch";

const url = "https://api.play.ht/api/v2/tts/stream";
const options = {
  method: "POST",
  headers: {
    accept: "audio/mpeg",
    "content-type": "application/json",
    AUTHORIZATION: "<YOUR_PLAY_HT_API_KEY>",
    "X-USER-ID": "<YOUR_PLAY_HT_USER_ID>",
  },
  body: JSON.stringify({
    voice_engine: 'PlayHT2.0-turbo',
    text: "Hey, this is Jennifer from Play. Please hold on a moment, let me just um pull up your details real quick.",
    voice:
      "s3://voice-cloning-zero-shot/d9ff78ba-d016-47f6-b0ef-dd630f59414e/female-cs/manifest.json",
    output_format: "mp3",
    sample_rate: "44100",
    speed: 1,
  }),
};

const response = await fetch(url, options);
const readableStream = response.body;

// Pipe the readable stream to a writable stream, this can be a local file or any other writable stream
readableStream.pipe(fs.createWriteStream("./audio.mp3"));

The above example will return an audio buffer stream that you can use to save locally or stream over the network to a browser, app, or telephony system.

For more details on the HTTP Streaming API, check this guide.

That is all you need to get started with realtime streaming through our HTTP API. If you need support, reach out to us at [email protected] or join us on Discord.