Skip to main content
POST
/
v3
/
voices
/
speech
Generate Speech
curl --request POST \
  --url https://api.heygen.com/v3/voices/speech \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: <api-key>' \
  --data '
{
  "text": "<string>",
  "voice_id": "<string>",
  "input_type": "text",
  "speed": 1,
  "language": "<string>",
  "locale": "<string>"
}
'
import requests

url = "https://api.heygen.com/v3/voices/speech"

payload = {
"text": "<string>",
"voice_id": "<string>",
"input_type": "text",
"speed": 1,
"language": "<string>",
"locale": "<string>"
}
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
text: '<string>',
voice_id: '<string>',
input_type: 'text',
speed: 1,
language: '<string>',
locale: '<string>'
})
};

fetch('https://api.heygen.com/v3/voices/speech', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.heygen.com/v3/voices/speech",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'text' => '<string>',
'voice_id' => '<string>',
'input_type' => 'text',
'speed' => 1,
'language' => '<string>',
'locale' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://api.heygen.com/v3/voices/speech"

payload := strings.NewReader("{\n \"text\": \"<string>\",\n \"voice_id\": \"<string>\",\n \"input_type\": \"text\",\n \"speed\": 1,\n \"language\": \"<string>\",\n \"locale\": \"<string>\"\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("x-api-key", "<api-key>")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://api.heygen.com/v3/voices/speech")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"text\": \"<string>\",\n \"voice_id\": \"<string>\",\n \"input_type\": \"text\",\n \"speed\": 1,\n \"language\": \"<string>\",\n \"locale\": \"<string>\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.heygen.com/v3/voices/speech")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"text\": \"<string>\",\n \"voice_id\": \"<string>\",\n \"input_type\": \"text\",\n \"speed\": 1,\n \"language\": \"<string>\",\n \"locale\": \"<string>\"\n}"

response = http.request(request)
puts response.read_body
{
  "data": {
    "audio_url": "<string>",
    "duration": 123,
    "request_id": "req_abc123",
    "word_timestamps": [
      {
        "word": "<string>",
        "start": 123,
        "end": 123
      }
    ]
  }
}
{
"error": {
"code": "invalid_parameter",
"message": "'voice_id' is required.",
"param": "voice_id",
"doc_url": null
}
}
{
"error": {
"code": "authentication_failed",
"message": "Invalid or expired API key. Verify your x-api-key header.",
"param": null,
"doc_url": null
}
}
{
"error": {
"code": "rate_limit_exceeded",
"message": "Too many requests. Retry after the duration specified in the Retry-After header.",
"param": null,
"doc_url": null
}
}

Authorizations

x-api-key
string
header
required

HeyGen API key. Obtain from your HeyGen dashboard.

Body

application/json

Request body for text-to-speech generation.

text
string
required

Text to synthesize (1-5000 characters).

Required string length: 1 - 5000
voice_id
string
required

Voice ID to use. The voice must support the starfish engine. Filter compatible voices by passing engine=starfish to the voice listing endpoint.

input_type
string
default:text

Type of the input: 'text' for plain text, 'ssml' for SSML markup. Defaults to 'text'.

speed
number
default:1

Speed multiplier (0.5-2.0).

Required range: 0.5 <= x <= 2
language
string | null

Base language code (e.g. 'en', 'pt', 'zh'). Optional — auto-detected from text when omitted.

locale
string | null

BCP-47 locale tag (e.g. 'en-US', 'pt-BR'). When set, language is inferred from locale.

Response

Successful response

data
TextToSpeechResponseData · object

Response payload for text-to-speech generation.