Text-to-Speech with Background Music
Text-to-Speech
Text-to-Speech with Background Music
Generate speech with background music
POST
Text-to-Speech with Background Music
Overview
Generate speech with background music. The music is automatically adjusted in volume, looped to match the speech length, and faded in/out for a professional sound.Request Body
This endpoint usesmultipart/form-data for file uploads.
string
required
The text to convert to speech
file
required
Background music file (MP3, WAV, or other audio format)
string
default:"en"
Language code (e.g., “en”, “es”, “fr”)
number
default:"800"
Pause duration in milliseconds between text segments
number
default:"-20"
Music volume adjustment in decibels. Negative values make music quieter (recommended: -20 to -30)
number
default:"2000"
Fade in/out duration in milliseconds for the background music
string
required
Your GistMag API key
Example Request
Response
The response is an MP3 audio file with speech overlaid on background music. Content-Type:audio/mpeg
Content-Disposition: attachment; filename=output_with_music.mp3
Credit Cost
1 credit per 1,000 characters (TTS) + 1 credit (background music), with a minimum of 2 credits total.Examples:
- 10 characters + music = 2 credits (1 TTS minimum + 1 music)
- 500 characters + music = 2 credits (1 TTS minimum + 1 music)
- 1,000 characters + music = 2 credits (1 TTS + 1 music)
- 2,500 characters + music = 4 credits (3 TTS + 1 music)
Example Usage
Python
Adding Music to Existing Audio
To add background music to an existing audio file (not generated by TTS), use the/tts/add-music endpoint.
The background music is automatically looped if it’s shorter than the speech, and trimmed if it’s longer. Volume is adjusted to ensure the speech remains clear and audible.