Generate Speech
Synthesize speech audio from text using a specified voice. The voice must support the starfish engine — use GET /v3/voices?engine=starfish to find compatible voices. Supports plain text and SSML. Speed range: 0.5–2.0x. Returns a URL to the generated audio file along with duration and optional word-level timestamps.
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": "https://files.heygen.ai/audio/tts_abc123.mp3",
"duration": 4.5,
"request_id": "req_abc123",
"word_timestamps": [
{
"word": "Hello",
"start": 0,
"end": 0.35
}
]
}
}{
"error": {
"code": "invalid_parameter",
"message": "'voice_id' is required.",
"param": "voice_id",
"doc_url": null
}
}{
"error": {
"code": "unauthorized",
"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
HeyGen API key. Obtain from your HeyGen dashboard.
Body
Request body for text-to-speech generation.
Text to synthesize (1-5000 characters). Break tags must express time in seconds (for example, ); millisecond values are not supported.
1 - 5000Voice ID to use. The voice must support the starfish engine. Filter compatible voices by passing engine=starfish to the voice listing endpoint.
Type of the input: 'text' for plain text, 'ssml' for SSML markup. Defaults to 'text'.
Speed multiplier (0.5-2.0).
0.5 <= x <= 2Base language code (e.g. 'en', 'pt', 'zh'). Optional — auto-detected from text when omitted.
BCP-47 locale tag (e.g. 'en-US', 'pt-BR'). When set, language is inferred from locale.
Response
Successful response
Response payload for text-to-speech generation.
Show child attributes
Show child attributes
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": "https://files.heygen.ai/audio/tts_abc123.mp3",
"duration": 4.5,
"request_id": "req_abc123",
"word_timestamps": [
{
"word": "Hello",
"start": 0,
"end": 0.35
}
]
}
}{
"error": {
"code": "invalid_parameter",
"message": "'voice_id' is required.",
"param": "voice_id",
"doc_url": null
}
}{
"error": {
"code": "unauthorized",
"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
}
}
