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": "e0bb585f-b798-4bac-ac4e-de7fff38f9d7voice_12345",
"gender": "female",
"webhook_url": "https://example.com/my-webhook"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())curl --request POST \
--url https://api.musicgpt.com/api/public/v1/TextToSpeech \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"text": "<string>",
"sample_audio_url": "<string>",
"voice_id": "<string>",
"gender": "<string>",
"webhook_url": "<string>"
}
'const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
text: '<string>',
sample_audio_url: '<string>',
voice_id: '<string>',
gender: '<string>',
webhook_url: '<string>'
})
};
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' => '<string>',
'sample_audio_url' => '<string>',
'voice_id' => '<string>',
'gender' => '<string>',
'webhook_url' => '<string>'
]),
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\": \"<string>\",\n \"sample_audio_url\": \"<string>\",\n \"voice_id\": \"<string>\",\n \"gender\": \"<string>\",\n \"webhook_url\": \"<string>\"\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\": \"<string>\",\n \"sample_audio_url\": \"<string>\",\n \"voice_id\": \"<string>\",\n \"gender\": \"<string>\",\n \"webhook_url\": \"<string>\"\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\": \"<string>\",\n \"sample_audio_url\": \"<string>\",\n \"voice_id\": \"<string>\",\n \"gender\": \"<string>\",\n \"webhook_url\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"task_id": "72eed5b0-8652-4bb4-9a95-eb0ad4850f12",
"conversion_id": "648a6823-b2a4-47b3-801e-f452c567ae6f",
"eta": 19
}{
"success": false,
"error": "Insufficient credit balance"
}{
"success": false,
"error": "Missing required field: text"
}{
"success": false,
"error": "Internal Server Error"
}Conversion Endpoints
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
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": "e0bb585f-b798-4bac-ac4e-de7fff38f9d7voice_12345",
"gender": "female",
"webhook_url": "https://example.com/my-webhook"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())curl --request POST \
--url https://api.musicgpt.com/api/public/v1/TextToSpeech \
--header 'Authorization: <api-key>' \
--header 'Content-Type: application/json' \
--data '
{
"text": "<string>",
"sample_audio_url": "<string>",
"voice_id": "<string>",
"gender": "<string>",
"webhook_url": "<string>"
}
'const options = {
method: 'POST',
headers: {Authorization: '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
text: '<string>',
sample_audio_url: '<string>',
voice_id: '<string>',
gender: '<string>',
webhook_url: '<string>'
})
};
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' => '<string>',
'sample_audio_url' => '<string>',
'voice_id' => '<string>',
'gender' => '<string>',
'webhook_url' => '<string>'
]),
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\": \"<string>\",\n \"sample_audio_url\": \"<string>\",\n \"voice_id\": \"<string>\",\n \"gender\": \"<string>\",\n \"webhook_url\": \"<string>\"\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\": \"<string>\",\n \"sample_audio_url\": \"<string>\",\n \"voice_id\": \"<string>\",\n \"gender\": \"<string>\",\n \"webhook_url\": \"<string>\"\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\": \"<string>\",\n \"sample_audio_url\": \"<string>\",\n \"voice_id\": \"<string>\",\n \"gender\": \"<string>\",\n \"webhook_url\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"task_id": "72eed5b0-8652-4bb4-9a95-eb0ad4850f12",
"conversion_id": "648a6823-b2a4-47b3-801e-f452c567ae6f",
"eta": 19
}{
"success": false,
"error": "Insufficient credit balance"
}{
"success": false,
"error": "Missing required field: text"
}{
"success": false,
"error": "Internal Server Error"
}Authorizations
Body
application/json
- Option 1
- Option 2
Text to convert to speech
An audio URL containing a voice sample of the target speaker without music or overlapping voices. Recommended over voice_id for better output quality.
Voice model ID
Gender preference for the voice (e.g., "male", "female")
Callback URL for async processing
⌘I