Music Gen Endpoint
Overview
Music gen helps to generate audio based on input parameters
Request
--request POST 'https://modelslab.com/api/v6/voice/music_gen' \
Make a POST
request to https://modelslab.com/api/v6/voice/music_gen endpoint and pass the required parameters as a request body.
Body Attributes
Parameter | Description | Values |
---|---|---|
key | Your API Key used for request authorization | string |
prompt | The input text for audio generation. | string |
init_audio | The conditioning melody for audio generation. | URL (can upload audio up to 30 seconds only) |
sampling_rate | The sampling rate of the generated audio. | integer, default: 32000, minimum: 10000 |
max_new_token | The maximum number of new tokens for audio generation. | integer, range: 256 to 1024 |
base64 | Whether the input sound clip is in base64 format. Should be true or false . Defaults to false . | TRUE or FALSE |
temp | Whether you want temporary links. Useful if your country blocks access to storage sites. | TRUE or FALSE |
webhook | Set a URL to receive a POST API call once the audio generation is complete. | URL |
track_id | This ID is returned in the response to the webhook API call. Used to identify the webhook request. | integral value |
Example
Body
Body
{
"key":"",
"prompt":"rock music from the 90s",
"init_audio":"https://pub-3626123a908346a7a8be8d9295f44e26.r2.dev/generations/2e4c9960-7425-4720-82a1-a373063bf635.wav",
"sampling_rate":10000,
"base64":false,
"temp": false,
"webhook": null,
"track_id": null
}
Request
- JS
- PHP
- NODE
- PYTHON
- JAVA
var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({
"key":"",
"prompt":"rock music from the 90s",
"init_audio":"https://pub-3626123a908346a7a8be8d9295f44e26.r2.dev/generations/2e4c9960-7425-4720-82a1-a373063bf635.wav",
"sampling_rate":10000,
"base64":false,
"temp": false,
"webhook": null,
"track_id": null
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://modelslab.com/api/v6/voice/music_gen", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
<?php
$payload = [
"key" => "",
"prompt" => "rock music from the 90s",
"init_audio" => "https://pub-3626123a908346a7a8be8d9295f44e26.r2.dev/generations/2e4c9960-7425-4720-82a1-a373063bf635.wav",
"sampling_rate" => 10000,
"base64" => false,
"temp" => false,
"webhook" => null,
"track_id" => null
];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://modelslab.com/api/v6/voice/music_gen',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => json_encode($payload),
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
var request = require('request');
var options = {
'method': 'POST',
'url': 'https://modelslab.com/api/v6/voice/music_gen',
'headers': {
'Content-Type': 'application/json'
},
body: JSON.stringify({
"key":"",
"prompt":"rock music from the 90s",
"init_audio":"https://pub-3626123a908346a7a8be8d9295f44e26.r2.dev/generations/2e4c9960-7425-4720-82a1-a373063bf635.wav",
"sampling_rate":10000,
"base64":true,
"temp": false,
"webhook": null,
"track_id": null
})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
import requests
import json
url = "https://modelslab.com/api/v6/voice/music_gen"
payload = json.dumps({
"key":"",
"prompt":"rock music from the 90s",
"init_audio":"https://pub-3626123a908346a7a8be8d9295f44e26.r2.dev/generations/2e4c9960-7425-4720-82a1-a373063bf635.wav",
"sampling_rate":10000,
"base64":False,
"temp": False,
"webhook": None,
"track_id":None
})
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n \"key\":\"\",\n \"prompt\":\"rock music from the 90s\",\n \"init_audio\":\"https://pub-3626123a908346a7a8be8d9295f44e26.r2.dev/generations/2e4c9960-7425-4720-82a1-a373063bf635.wav\",\n \"sampling_rate\":10000,\n \"base64\":true,\n \"temp\": false,\n \"webhook\":\"\",\n \"track_id\":\"\"\n}");
Request request = new Request.Builder()
.url("https://modelslab.com/api/v6/voice/music_gen")
.method("POST", body)
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
Response
{
{
"status": "success",
"generationTime": 7.8882811069488525,
"id": 310815,
"output": [
"https://pub-3626123a908346a7a8be8d9295f44e26.r2.dev/generations/30ea5aee-fba8-4b65-bf71-2fc2b6b197c0.wav"
],
"proxy_links": [
"https://cdn2.stablediffusionapi.com/generations/30ea5aee-fba8-4b65-bf71-2fc2b6b197c0.wav"
],
"meta": {
"base64": "no",
"conditioning_melody": null,
"filename": "30ea5aee-fba8-4b65-bf71-2fc2b6b197c0.wav",
"input_text": "rock music from the 90s",
"max_new_token": 256,
"sampling_rate": 10000,
"temp": "no"
}
}
}