Convert text into natural-sounding speech using various TTS models from different providers. Supports multiple languages, voices, and customization options including speed control, voice instructions, and audio format selection.
POST
/
api
/
tts
Copy
curl --request POST \ --url https://nano-gpt.com/api/api/tts \ --header 'Content-Type: application/json' \ --header 'x-api-key: <api-key>' \ --data '{ "text": "Hello! This is a test of the text-to-speech API.", "model": "Kokoro-82m", "voice": "af_bella", "speed": 1, "response_format": "mp3", "instructions": "speak with enthusiasm", "stability": 0.5, "similarity_boost": 0.75, "style": 0}'
Convert text into natural-sounding speech using various TTS models. Supports multiple languages, voices, and customization options including speed control and voice instructions.
# Multi-speaker conversationdialogue = "[S1] Welcome to our podcast! [S2] Thanks for having me. [S1] Let's begin!"text_to_speech( text=dialogue, model="Dia-TTS", speed=1.1)# Single speaker with specific voicetext_to_speech( text="[S1] This is a single speaker narration.", model="Dia-TTS", voice="S2" # Use S2 voice for all text)
# Stable, consistent voicetext_to_speech( text="This is a professional announcement.", model="Elevenlabs-Turbo-V2.5", voice="Rachel", stability=0.9, similarity_boost=0.8, style=0)# Expressive, dynamic voice text_to_speech( text="This is so exciting!", model="Elevenlabs-Turbo-V2.5", voice="Rachel", stability=0.3, similarity_boost=0.7, style=0.8, speed=1.2)# Available voices: Rachel, Adam, Bella, Brian, etc.
# High-definition with voice instructionstext_to_speech( text="Welcome to customer service.", model="tts-1-hd", voice="nova", instructions="Speak warmly and professionally like a customer service representative", response_format="flac")# Ultra-low cost optiontext_to_speech( text="This is a cost-effective option.", model="gpt-4o-mini-tts", voice="alloy", instructions="Speak clearly and cheerfully", response_format="mp3")# Different format examplesformats = ["mp3", "wav", "opus", "flac", "aac"]for fmt in formats: text_to_speech( text=f"This is {fmt.upper()} format.", model="tts-1", voice="echo", response_format=fmt )
try: result = text_to_speech("Hello world!", model="Kokoro-82m") print("Success!")except Exception as e: if "400" in str(e): print("Bad request - check parameters") elif "401" in str(e): print("Unauthorized - check API key") elif "413" in str(e): print("Text too long for model") else: print(f"Error: {e}")