PlayHT TTS Streaming Text to Audio

fal-ai/playht-tts
Audio
Inference
Commercial use
Streaming

About

Text To Speech

1. Calling the API#

Install the client#

The client provides a convenient way to interact with the model API.

npm install --save @fal-ai/client

Setup your API Key#

Set FAL_KEY as an environment variable in your runtime.

export FAL_KEY="YOUR_API_KEY"

Submit a request#

The client API handles the API submit protocol. It will handle the request status updates and return the result when the request is completed.

import { fal } from "@fal-ai/client";

const result = await fal.subscribe("fal-ai/playht-tts", {
  input: {
    text: ["As she sat watching the world go by, something caught her eye. It wasn't so much its color or shape, but the way it was moving. She squinted to see if she could better understand what it was and where it was going, but it didn't help. As she continued to stare into the distance, she didn't understand why this uneasiness was building inside her body."]
  },
  logs: true,
  onQueueUpdate: (update) => {
    if (update.status === "IN_PROGRESS") {
      update.logs.map((log) => log.message).forEach(console.log);
    }
  },
});
console.log(result.data);
console.log(result.requestId);

2. Authentication#

The API uses an API Key for authentication. It is recommended you set the FAL_KEY environment variable in your runtime when possible.

API Key#

In case your app is running in an environment where you cannot set environment variables, you can set the API Key manually as a client configuration.
import { fal } from "@fal-ai/client";

fal.config({
  credentials: "YOUR_FAL_KEY"
});

3. Queue#

Submit a request#

The client API provides a convenient way to submit requests to the model.

import { fal } from "@fal-ai/client";

const { request_id } = await fal.queue.submit("fal-ai/playht-tts", {
  input: {
    text: ["As she sat watching the world go by, something caught her eye. It wasn't so much its color or shape, but the way it was moving. She squinted to see if she could better understand what it was and where it was going, but it didn't help. As she continued to stare into the distance, she didn't understand why this uneasiness was building inside her body."]
  },
  webhookUrl: "https://optional.webhook.url/for/results",
});

Fetch request status#

You can fetch the status of a request to check if it is completed or still in progress.

import { fal } from "@fal-ai/client";

const status = await fal.queue.status("fal-ai/playht-tts", {
  requestId: "764cabcf-b745-4b3e-ae38-1200304cf45b",
  logs: true,
});

Get the result#

Once the request is completed, you can fetch the result. See the Output Schema for the expected result format.

import { fal } from "@fal-ai/client";

const result = await fal.queue.result("fal-ai/playht-tts", {
  requestId: "764cabcf-b745-4b3e-ae38-1200304cf45b"
});
console.log(result.data);
console.log(result.requestId);

4. Files#

Some attributes in the API accept file URLs as input. Whenever that's the case you can pass your own URL or a Base64 data URI.

Data URI (base64)#

You can pass a Base64 data URI as a file input. The API will handle the file decoding for you. Keep in mind that for large files, this alternative although convenient can impact the request performance.

Hosted files (URL)#

You can also pass your own URLs as long as they are publicly accessible. Be aware that some hosts might block cross-site requests, rate-limit, or consider the request as a bot.

Uploading files#

We provide a convenient file storage that allows you to upload files and use them in your requests. You can upload files using the client API and use the returned URL in your requests.

import { fal } from "@fal-ai/client";

const file = new File(["Hello, World!"], "hello.txt", { type: "text/plain" });
const url = await fal.storage.upload(file);

Read more about file handling in our file upload guide.

5. Schema#

Input#

text string | list<string>* required

The text to be converted to speech.

voice string

The unique ID for a PlayHT or Cloned Voice. Default value: "s3://peregrine-voices/donna_parrot_saad/manifest.json"

seed integer

An integer number greater than or equal to 0. If equal to null or not provided, a random seed will be used. Useful to control the reproducibility of the generated audio. Assuming all other properties didn't change, a fixed seed should always generate the exact same audio file.

output_format OutputFormatEnum

The format of the audio file to be returned. Default value: "wav"

Possible enum values: raw, wav, mp3, ogg, flac, mulaw

quality QualityEnum

The quality of the generated audio file. Default value: "draft"

Possible enum values: draft, low, medium, high, premium

sample_rate integer

The sample rate of the audio file to be returned.

speed float

Control how fast the generated audio should be. A number greater than 0 and less than or equal to 5.0 Default value: 1

temperature float

Default value: 0.4

top_p float

Default value: 0.75

repetition_penalty float

A floating point number between 0, inclusive, and 10, inclusive. If equal to null or not provided, the model's default repetition_penalty will be used. The repetition_penalty parameter controls the penalty for repeated tokens. Higher values will penalize repeated tokens more heavily. Default value: 1.5

length_penalty float

Default value: 1.1

style_guidance float

Default value: 0.5

voice_guidance float
text_guidance float

Default value: 0.8

audio_source AudioSourceEnum

The audio source to be applied to the generated audio file.

Possible enum values: not_specified, libri_tts, hifi_tts, other_tts, audiobooks_ocotillo, audiobooks_whisper, audiobooks_unknown, podcasts_ocotillo, podcasts_whisper, podcasts_unknown, movies_ocotillo, movies_whisper, old_movies_ocotillo, old_movies_whisper, tv_show_ocotillo, tv_show_whisper, youtube_ocotillo, youtube_whisper, educational_ocotillo, educational_whisper, voice_actors_ocotillo, voice_actors_whisper, game_ocotillo, game_whisper, max_audio_sources

speaker_attributes SpeakerAttributesEnum

The speaker attributes to be applied to the generated audio file. Default value: "full_sentence"

Possible enum values: nil, british, american, irish, male, female, adult, youth, old, slow, neutral_speed, fast, low_pitch, neutral_pitch, high_pitch, smooth, round, gravelly, neutral_quality, thick, narrative, news, formal, two_speakers, full_sentence, max_speaker_attributes

speech_attributes SpeechAttributesEnum

The speech attributes to be applied to the generated audio file.

Possible enum values: female_angry, female_disgust, female_fear, female_happy, female_neutral, female_sad, female_surprise, male_angry, male_disgust, male_fear, male_happy, male_neutral, male_sad, male_surprise, nil, stuttering, conversation, oration, phone, interview, narration, talking_to_self, max_speech_attributes

language LanguageEnum

Possible enum values: english, mandarin, hindi, japanese, korean, arabic, spanish, french, italian, portuguese, german, dutch, swedish, czech, polish, russian, bulgarian, hebrew, greek, turkish, afrikaans, xhosa, tagalog, malay, indonesian, bengali, serbian, thai, urdu, croatian, hungarian, danish, amharic, albanian, catalan, ukrainian, galician, synthetic, other, max_languages

ar_chunk_size integer

Default value: 23

ar_first_chunk_size integer

Default value: 15

ar_chunk_overlap integer

Default value: 7

repetition_penalty_window integer

Default value: 70

recency_penalty_window integer

Default value: 20

msgpack boolean

If true, the response will be in msgpack format. Otherwise, it will be raw bytes.

request_id string
{
  "text": [
    "As she sat watching the world go by, something caught her eye. It wasn't so much its color or shape, but the way it was moving. She squinted to see if she could better understand what it was and where it was going, but it didn't help. As she continued to stare into the distance, she didn't understand why this uneasiness was building inside her body."
  ],
  "voice": "s3://voice-cloning-zero-shot/028a32d4-6a79-4ca3-a303-d6559843114b/chris/manifest.json",
  "seed": null,
  "output_format": "wav",
  "quality": "draft",
  "sample_rate": null,
  "speed": 1,
  "temperature": 0.4,
  "top_p": 0.75,
  "repetition_penalty": 1.5,
  "length_penalty": 1.1,
  "style_guidance": 0.5,
  "text_guidance": 0.8,
  "audio_source": null,
  "speaker_attributes": "full_sentence",
  "speech_attributes": null,
  "language": null,
  "ar_chunk_size": 23,
  "ar_first_chunk_size": 15,
  "ar_chunk_overlap": 7,
  "repetition_penalty_window": 70,
  "recency_penalty_window": 20,
  "request_id": null
}

Output#

audio AudioFile* required

The audio file.

{
  "audio": {
    "url": "",
    "content_type": "image/png",
    "file_name": "z9RV14K95DvU.png",
    "file_size": 4404019,
    "duration": null
  }
}

Other types#

AudioFile#

url string* required

The URL where the file can be downloaded from.

content_type string

The mime type of the file.

file_name string

The name of the file. It will be auto-generated if not provided.

file_size integer

The size of the file in bytes.

file_data string

File data

duration float

The duration of the audio file in seconds.

File#

url string* required

The URL where the file can be downloaded from.

content_type string

The mime type of the file.

file_name string

The name of the file. It will be auto-generated if not provided.

file_size integer

The size of the file in bytes.

file_data string

File data