Generate high-quality audio from text using our neural TTS models. This endpoint returns a complete MP3 file after processing your text.
Request
Here’s the simplest way to generate speech:
curl -X POST "https://api.neospeech.io/v1/audio/speech" \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"input": "Hello, welcome to NeoSpeech",
"voice": "lyra",
"model": "aurora-4"
}' \
--output speech.mp3
Parameters
Bearer token: Bearer sk-your-api-key
The text to convert to speech (max 5,000 characters)
Audio model: aurora-4 (premium), aurora-3.5 (high quality), turbo-3 (fast), or mini-2 (lightweight)
Adjust voice pitch from -50% to +50%. Default: +0%
Speech emotion: calm, excited, cheerful, or sad. Default: calm
Style intensity from 0.5 to 2.0. Default: 1.5
Language code like en-US, en-GB, fr-FR. Default: en-US
Response
Returns binary MP3 audio data with these headers:
Content-Type: audio/mpeg
X-Character-Count: 28
X-Model-Used: aurora-4
X-Voice-Used: Lyra
Common patterns
Save to file
const response = await fetch('https://api.neospeech.io/v1/audio/speech', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.NEOSPEECH_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
input: 'Your text here',
voice: 'lyra',
model: 'aurora-4'
})
});
const buffer = Buffer.from(await response.arrayBuffer());
fs.writeFileSync('output.mp3', buffer);
Add emotion
const response = await fetch('https://api.neospeech.io/v1/audio/speech', {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
input: 'This is exciting news!',
voice: 'kai',
model: 'aurora-4',
style: 'excited',
styleDegree: '1.8'
})
});
Handle errors
try {
const response = await fetch('https://api.neospeech.io/v1/audio/speech', {
method: 'POST',
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ input, voice, model })
});
if (!response.ok) {
const error = await response.json();
throw new Error(error.message);
}
return await response.blob();
} catch (error) {
console.error('Speech generation failed:', error.message);
throw error;
}