Convert text to speech using a specified voice
curl --request POST \
--url https://api.musicgpt.com/api/public/v1/TextToSpeech \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"text": "Hello, this is a sample text to speech conversion.",
"sample_audio_url": "<YOUR_AUDIO_URL>",
"voice_id": "e1cb7380-e3db-433a-b186-a996d7545986",
"gender": "female",
"webhook_url": "https://example.com/my-webhook"
}
'import requests
url = "https://api.musicgpt.com/api/public/v1/TextToSpeech"
payload = {
"text": "Hello, this is a sample text to speech conversion.",
"sample_audio_url": "<YOUR_AUDIO_URL>",
"voice_id": "e1cb7380-e3db-433a-b186-a996d7545986",
"gender": "female",
"webhook_url": "https://example.com/my-webhook"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
text: 'Hello, this is a sample text to speech conversion.',
sample_audio_url: '<YOUR_AUDIO_URL>',
voice_id: 'e1cb7380-e3db-433a-b186-a996d7545986',
gender: 'female',
webhook_url: 'https://example.com/my-webhook'
})
};
fetch('https://api.musicgpt.com/api/public/v1/TextToSpeech', 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.musicgpt.com/api/public/v1/TextToSpeech",
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' => 'Hello, this is a sample text to speech conversion.',
'sample_audio_url' => '<YOUR_AUDIO_URL>',
'voice_id' => 'e1cb7380-e3db-433a-b186-a996d7545986',
'gender' => 'female',
'webhook_url' => 'https://example.com/my-webhook'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$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.musicgpt.com/api/public/v1/TextToSpeech"
payload := strings.NewReader("{\n \"text\": \"Hello, this is a sample text to speech conversion.\",\n \"sample_audio_url\": \"<YOUR_AUDIO_URL>\",\n \"voice_id\": \"e1cb7380-e3db-433a-b186-a996d7545986\",\n \"gender\": \"female\",\n \"webhook_url\": \"https://example.com/my-webhook\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<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.musicgpt.com/api/public/v1/TextToSpeech")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"text\": \"Hello, this is a sample text to speech conversion.\",\n \"sample_audio_url\": \"<YOUR_AUDIO_URL>\",\n \"voice_id\": \"e1cb7380-e3db-433a-b186-a996d7545986\",\n \"gender\": \"female\",\n \"webhook_url\": \"https://example.com/my-webhook\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.musicgpt.com/api/public/v1/TextToSpeech")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"text\": \"Hello, this is a sample text to speech conversion.\",\n \"sample_audio_url\": \"<YOUR_AUDIO_URL>\",\n \"voice_id\": \"e1cb7380-e3db-433a-b186-a996d7545986\",\n \"gender\": \"female\",\n \"webhook_url\": \"https://example.com/my-webhook\"\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"task_id": "0a65cbb6-2ab8-4949-9ee0-0e8c138ac2cf",
"conversion_id": "6542baa6-d61f-4d90-b832-ed929d9c0996",
"eta": 17,
"credit_estimate": 0.68,
"message": "",
"status": "IN_QUEUE"
}{
"success": false,
"message": "Insufficient credit balance"
}{
"success": false,
"message": "Missing required field: text"
}{
"success": false,
"message": "Internal Server Error"
}Features
Text To Speech
Synthesize speech from text with voice and gender customization, plus optional webhook callback.
Give priority to the sample audio first, then to the voice ID, and lastly to gender.
POST
/
v1
/
TextToSpeech
Convert text to speech using a specified voice
curl --request POST \
--url https://api.musicgpt.com/api/public/v1/TextToSpeech \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"text": "Hello, this is a sample text to speech conversion.",
"sample_audio_url": "<YOUR_AUDIO_URL>",
"voice_id": "e1cb7380-e3db-433a-b186-a996d7545986",
"gender": "female",
"webhook_url": "https://example.com/my-webhook"
}
'import requests
url = "https://api.musicgpt.com/api/public/v1/TextToSpeech"
payload = {
"text": "Hello, this is a sample text to speech conversion.",
"sample_audio_url": "<YOUR_AUDIO_URL>",
"voice_id": "e1cb7380-e3db-433a-b186-a996d7545986",
"gender": "female",
"webhook_url": "https://example.com/my-webhook"
}
headers = {
"Authorization": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
text: 'Hello, this is a sample text to speech conversion.',
sample_audio_url: '<YOUR_AUDIO_URL>',
voice_id: 'e1cb7380-e3db-433a-b186-a996d7545986',
gender: 'female',
webhook_url: 'https://example.com/my-webhook'
})
};
fetch('https://api.musicgpt.com/api/public/v1/TextToSpeech', 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.musicgpt.com/api/public/v1/TextToSpeech",
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' => 'Hello, this is a sample text to speech conversion.',
'sample_audio_url' => '<YOUR_AUDIO_URL>',
'voice_id' => 'e1cb7380-e3db-433a-b186-a996d7545986',
'gender' => 'female',
'webhook_url' => 'https://example.com/my-webhook'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <api-key>",
"Content-Type: application/json"
],
]);
$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.musicgpt.com/api/public/v1/TextToSpeech"
payload := strings.NewReader("{\n \"text\": \"Hello, this is a sample text to speech conversion.\",\n \"sample_audio_url\": \"<YOUR_AUDIO_URL>\",\n \"voice_id\": \"e1cb7380-e3db-433a-b186-a996d7545986\",\n \"gender\": \"female\",\n \"webhook_url\": \"https://example.com/my-webhook\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<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.musicgpt.com/api/public/v1/TextToSpeech")
.header("Authorization", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"text\": \"Hello, this is a sample text to speech conversion.\",\n \"sample_audio_url\": \"<YOUR_AUDIO_URL>\",\n \"voice_id\": \"e1cb7380-e3db-433a-b186-a996d7545986\",\n \"gender\": \"female\",\n \"webhook_url\": \"https://example.com/my-webhook\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.musicgpt.com/api/public/v1/TextToSpeech")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"text\": \"Hello, this is a sample text to speech conversion.\",\n \"sample_audio_url\": \"<YOUR_AUDIO_URL>\",\n \"voice_id\": \"e1cb7380-e3db-433a-b186-a996d7545986\",\n \"gender\": \"female\",\n \"webhook_url\": \"https://example.com/my-webhook\"\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"task_id": "0a65cbb6-2ab8-4949-9ee0-0e8c138ac2cf",
"conversion_id": "6542baa6-d61f-4d90-b832-ed929d9c0996",
"eta": 17,
"credit_estimate": 0.68,
"message": "",
"status": "IN_QUEUE"
}{
"success": false,
"message": "Insufficient credit balance"
}{
"success": false,
"message": "Missing required field: text"
}{
"success": false,
"message": "Internal Server Error"
}Convert any given text into realistic speech using your chosen voice and gender.
TextToSpeech enables you to instantly bring written content to life. Perfect for:
Use this endpoint to initiate a new text-to-speech audio generation.
- Creating dynamic audio narrations or voiceovers
- Choosing gender-specific voice stylings for different contexts
- Using webhooks for real-time integration with your workflows
Endpoint
POST /v1/TextToSpeech
Sample Output
Prompt: When I think of superheroes I think of super humans. I think of Superman, Wolverine and Wonder Woman. Usually they have a cape, or a mask to hide their face just in case. They have X-ray vision and super-human strength. Some can even breathe in outer space. They fly around a while, but always come back to keep our cities safe. They’re here to save humanity from itself. It’s a metaphor for how we look outside ourselves for help, and while the fantasies are fun, I choose to look for me and you. Download AudioTry it Yourself
Visit the TextToSpeech Endpoint Explorer to try your own text samples.Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
text | String | Yes | The text content to convert to speech |
voice_id | String | Optional | Voice ID of the artist. Visit Get Voices by Name to get voice_id. |
sample_audio_url | String | Optional | URL of Voice you want. |
gender | String | Yes | Gender of the voice (“male”, “female”) |
webhook_url | String | No | URL to receive a callback with generated audio |
content-type: application/json
Sample Request
Python
import requests
url = "https://api.musicgpt.com/api/public/v1/TextToSpeech"
headers = {
"Authorization": "<API_KEY>",
"Content-Type": "application/json"
}
payload = {
"text": "Welcome to MusicGPT! This is a sample text-to-speech generation.",
"sample_audio_url": "<YOUR_AUDIO_URL>",
"voice_id": "e1cb7380-e3db-433a-b186-a996d7545986",
"gender": "female",
"webhook_url": "https://example.com/my-webhook"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
Sample Response
Success (200 OK)
{
"success":true,
"task_id":"0a65cbb6-2ab8-4949-9ee0-0e8c138ac2cf",
"conversion_id":"6542baa6-d61f-4d90-b832-ed929d9c0996",
"eta":17,
"credit_estimate":0.68,
"message":"",
"status":"IN_QUEUE"
}
Webhook Response
Once audio is ready, your webhook will receive:{
"success": true,
"conversion_type": "Text To Speech",
"task_id": "037a9a09-3fc6-4a90-8748-d3406ff712eb",
"conversion_id": "f1970224-ab06-4aa6-a832-0f3fd23212b7",
"conversion_path": "https://cdn1.musicgpt.com/conversions/api/tts/195e5815-b871-4ea0-86a2-7f5eb1c696d2/195e5815-b871-4ea0-86a2-7f5eb1c696d2.mp3",
"message": "Conversion Completed",
"conversion_cost": "0.68",
"conversion_duration": 27.78
}
Error Codes
- 402 Payment Required: Not enough credits to process the request
- 422 Unprocessable Entity: Invalid or missing fields
- 500 Internal Server Error: Server-side failure during processing
Payload and Request Formation
Authorizations
Body
application/json
- Option 1
- Option 2
Text to convert to speech
Example:
"Hello, this is a sample text to speech conversion."
An audio URL containing a voice sample of the target speaker without music or overlapping voices. Recommended over voice_id for better output quality.
Example:
"<YOUR_AUDIO_URL>"
Voice model ID
Example:
"e1cb7380-e3db-433a-b186-a996d7545986"
Gender preference for the voice (e.g., "male", "female")
Example:
"female"
Callback URL for async processing
Example:
"https://example.com/my-webhook"