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 uses multipart/form-data for file uploads.
The text to convert to speech
Background music file (MP3, WAV, or other audio format)
Language code (e.g., “en”, “es”, “fr”)
Pause duration in milliseconds between text segments
Music volume adjustment in decibels. Negative values make music quieter (recommended: -20 to -30)
Fade in/out duration in milliseconds for the background music
Example Request
curl -X POST https://api.gistmag.co.uk/tts/with-music \
-F "text=This is a narration with background music." \
-F "music=@background.mp3" \
-F "language=en" \
-F "pause_duration=800" \
-F "music_volume=-20" \
-F "fade_duration=2000" \
-F "api_key=your_api_key_here" \
--output output_with_music.mp3
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
Example Usage
Python
import requests
with open("background.mp3", "rb") as f:
files = {"music": f}
data = {
"text": "This is a narration with background music.",
"language": "en",
"pause_duration": 800,
"music_volume": -20,
"fade_duration": 2000,
"api_key": "your_api_key_here"
}
response = requests.post(
"https://api.gistmag.co.uk/tts/with-music",
files=files,
data=data
)
with open("output_with_music.mp3", "wb") as f:
f.write(response.content)
Voice Cloning with Music
For voice cloning with background music, use the /tts/with-music/voice-clone endpoint.
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.