Skip to main content

Text to Audio Endpoint

Overview

Text to audio endpoint allows you to create an audio by passing in the text and a valid audio url or a pre created voice as voice_id. The result produces an audio with the same sound as the audio url or voice that was passed.

Request

--request POST 'https://modelslab.com/api/v6/voice/text_to_audio' \

Watch the Text to Audio API Demo video to see it in action Postman.

Make a POST request to https://modelslab.com/api/v6/voice/text_to_audio endpoint and pass the required parameters as a request body.

Body Attributes

ParameterDescription
keyYour API Key used for request authorization
promptText prompt with description of the audio you want to generate
init_audioA valid audio url you want it voice cloned
voice_idOptional, A valid id from the lists of voices
languageThe language of the voice. The supported languages includesenglish,arabic,spanish,german,czech,brazilian portuguese, chinese, dutch,french, hindi, hungarian,italian, japanese, korean,polish, russian, turkish. Default english
emotionOne of neutral, happy, sad, angry,dull. Defaults to neutral
speedFloating point value for speed of speaker. Defaults to 1.0
base64Whether the input sound clip is in base64 or not. Should be true or false. Defaults to false.
tempWhether you want temporary links or not. This is useful if your country blocks access to our storage sites. Should be true or false. Defaults
webhookSet an URL to get a POST API call once the image generation is complete.
track_idThis ID is returned in the response to the webhook API call. This will be used to identify the webhook request.

Note: You can either pass init_audio or voice_id. However, if both are passed at the same time the init_audio takes preference.

Example

Body

Body
{   
"key": "",
"prompt":"Narrative voices capable of pronouncing terminologies & acronyms in training and ai learning materials.",
"init_audio":"https://pub-f3505056e06f40d6990886c8e14102b2.r2.dev/audio/tom_hanks_1.wav",
"language":"english",
"webhook": null,
"track_id": null
}

Request

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");

var raw = JSON.stringify({
"key": "",
"prompt":"Narrative voices capable of pronouncing terminologies & acronyms in training and ai learning materials.",
"init_audio":"https://pub-f3505056e06f40d6990886c8e14102b2.r2.dev/audio/tom_hanks_1.wav",
"language":"english",
"webhook": null,
"track_id": null
});

var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};

fetch("https://modelslab.com/api/v6/voice/text_to_audio", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));

Response

{
"generationTime": 1.5732920169830322,
"links": [
"https://pub-3626123a908346a7a8be8d9295f44e26.r2.dev/generations/9ca99fa2-0f68-4800-b186-d83116cc5374.wav"
],
"meta": {
"base64": "no",
"emotion": "Happy",
"filename": "9ca99fa2-0f68-4800-b186-d83116cc5374.wav",
"input_text": "Narrative voices capable of pronouncing terminologies & acronyms in training and ai learning materials.",
"language": "english",
"speaker_wav": [
"tmp/0-9ca99fa2-0f68-4800-b186-d83116cc5374.wav"
],
"speed": 1.0,
"temp": "no"
},
"proxy_links": [],
"status": "success",
"warnings": []
}