Text-to-Speech API

Convert Text to Natural Speech

Audio Generator. Generate natural-sounding audio in multiple languages and voices.

API Documentation

Everything you need to integrate our TTS API

GET
/api/voices
Retrieve all available voices and their configurations

Request Example

fetch('/api/voices')
  .then(res => res.json())
  .then(data => console.log(data))

Response Structure

{
  "responseCode": "200",
  "voiceGroups": [
    {
      "language": "English",
      "locale": "en-US",
      "accent": "American",
      "voices": [
        {
          "voiceId": "V0160199018703841W",
          "voiceName": "Natasha",
          "language": "English",
          "voiceStyles": ["Conversational", "Narration"],
          "gender": "Female"
        }
      ]
    }
  ]
}
POST
/api/generate-tts
Generate speech audio from text with specified voice and style

Request Body

text
requiredstring (max 500 characters)

The text to convert to speech

voiceId
requiredstring

The ID of the voice to use

style
optionalstring

Voice style (only for voices that support styles)

Request Example

fetch('/api/generate-tts', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    text: 'Hello, this is a test of the text-to-speech API.',
    voiceId: 'V0160199018703841W',
    style: 'Conversational'
  })
})
  .then(res => res.json())
  .then(data => console.log(data.mp3Url))

Success Response

{
  "success": true,
  "mp3Url": "/temp/audio-1234567890-abc123.mp3"
}

Error Response

{
  "success": false,
  "error": "Text exceeds maximum length of 500 characters"
}

Temporary Files

Generated MP3 files are automatically deleted after 20 minutes. Make sure to download or process them within this timeframe.

Complete Usage Example
Full workflow from fetching voices to generating audio
// Step 1: Fetch available voices
const voicesResponse = await fetch('/api/voices')
const { voiceGroups } = await voicesResponse.json()

// Step 2: Select a voice
const firstVoice = voiceGroups[0].voices[0]
console.log('Using voice:', firstVoice.voiceName)

// Step 3: Generate audio
const ttsResponse = await fetch('/api/generate-tts', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    text: 'Welcome to our text-to-speech API!',
    voiceId: firstVoice.voiceId,
    style: firstVoice.voiceStyles[0] // Use first style if available
  })
})

const { success, mp3Url, error } = await ttsResponse.json()

if (success) {
  // Step 4: Use the audio
  const audio = new Audio(mp3Url)
  audio.play()
} else {
  console.error('Error:', error)
}
Best Practices
  • 1
    Validate text length: Always ensure your text is under 500 characters before making a request
  • 2
    Check voice styles: Not all voices support styles. Check the voiceStyles array before including the style parameter
  • 3
    Handle errors gracefully: Always check the success field in the response and handle errors appropriately
  • 4
    Download promptly: MP3 files expire after 20 minutes, so process or download them immediately

Ready to get started?

Try our voice generator and create your first audio file