Skip to main content

OpenAI TTS Provider Guide

High-quality neural text-to-speech with six distinct voices and HD quality option


Overview​

NeuroLink integrates OpenAI's Text-to-Speech API, giving you access to six expressive neural voices across two model tiers. The standard model (tts-1) optimises for low latency, while the HD model (tts-1-hd) delivers higher audio fidelity for production use cases such as podcasts, voice assistants, and narration.

OpenAI TTS works with any NeuroLink text generation call — you can synthesise the raw prompt directly or synthesise the AI-generated response, controlled by the useAiResponse flag.

Key Facts​

PropertyValue
Provider IDopenai-tts
API endpointhttps://api.openai.com/v1/audio/speech
Modelstts-1 (standard), tts-1-hd (high quality)
Voicesalloy, echo, fable, onyx, nova, shimmer
Formatsmp3, wav, ogg (opus), opus
Max input4,096 characters per request
LanguagesFollows input text language automatically
StreamingNot supported (batch synthesis only)

Quick Start​

1. Get an API Key​

Sign up or log in at https://platform.openai.com and create a new secret key under API keys.

2. Configure Environment​

Add to your .env file:

# Required
OPENAI_API_KEY=sk-...

Default model (tts-1) and voice (alloy) are set in code; override per call via tts.model / tts.voice in the SDK or --tts-model / --tts-voice on the CLI. There is no OPENAI_TTS_MODEL / OPENAI_TTS_VOICE env var.

npm install @juspay/neurolink
# or
pnpm add @juspay/neurolink

4. Synthesise Your First Audio​

import { NeuroLink } from "@juspay/neurolink";
import { writeFileSync } from "fs";

const ai = new NeuroLink();

const result = await ai.generate({
provider: "openai",
input: { text: "Hello! Welcome to NeuroLink." },
tts: {
enabled: true,
provider: "openai-tts",
format: "mp3",
},
});

if (result.audio) {
writeFileSync("output.mp3", result.audio.buffer);
console.log(`Saved ${result.audio.size} bytes to output.mp3`);
}

Supported Models​

Model IDQualityLatencyUse Case
tts-1StandardLowerDefault; real-time apps, interactive voice UIs
tts-1-hdHDHigherPodcasts, narration, production audio assets

Select the HD model by passing quality: "hd" in TTS options — NeuroLink maps this automatically to tts-1-hd.


SDK Usage​

Direct Text Synthesis​

Synthesise the input text directly without calling an AI model:

import { NeuroLink } from "@juspay/neurolink";

const ai = new NeuroLink();

const result = await ai.generate({
input: { text: "NeuroLink makes AI development simple." },
tts: {
enabled: true,
provider: "openai-tts",
voice: "nova",
format: "mp3",
},
});

if (result.audio) {
console.log("Format:", result.audio.format);
console.log("Size:", result.audio.size, "bytes");
console.log("Latency:", result.audio.metadata?.latency, "ms");
}

AI Response Synthesis​

Generate a response with an AI model and then synthesise it:

const result = await ai.generate({
provider: "openai",
input: { text: "Greet the user in a warm and friendly tone." },
tts: {
enabled: true,
provider: "openai-tts",
useAiResponse: true, // Synthesise the AI-generated text, not the prompt
voice: "shimmer",
format: "mp3",
},
});

HD Quality Audio​

const result = await ai.generate({
input: { text: "This is high-definition audio narration." },
tts: {
enabled: true,
provider: "openai-tts",
quality: "hd", // Maps to tts-1-hd
voice: "onyx",
format: "wav",
},
});

Adjusting Playback Speed​

const result = await ai.generate({
input: { text: "Speaking at 80% normal speed." },
tts: {
enabled: true,
provider: "openai-tts",
voice: "alloy",
speed: 0.8, // Range: 0.25 to 4.0 (default: 1.0)
format: "mp3",
},
});

Save to File​

import { writeFileSync } from "fs";

const result = await ai.generate({
input: { text: "Saving audio to disk." },
tts: {
enabled: true,
provider: "openai-tts",
voice: "echo",
format: "mp3",
output: "./audio/output.mp3", // NeuroLink saves automatically if set
},
});

Per-Call Credential Override​

const result = await ai.generate({
input: { text: "Hello!" },
tts: {
enabled: true,
provider: "openai-tts",
},
credentials: {
openai: {
apiKey: "sk-user-specific-key",
},
},
});

CLI Usage​

Basic TTS​

# Synthesise text directly
neurolink generate "Hello, world!" --tts --tts-provider openai-tts

# Choose a voice
neurolink generate "Good morning!" --tts --tts-provider openai-tts --tts-voice nova

# Save to file
neurolink generate "Save this audio." \
--tts --tts-provider openai-tts \
--tts-voice shimmer \
--tts-output greeting.mp3

HD Quality​

neurolink generate "Professional narration." \
--tts --tts-provider openai-tts \
--tts-quality hd \
--tts-voice onyx \
--tts-output narration.mp3

Synthesise AI Response​

neurolink generate "Tell me a short story." \
--provider openai \
--tts --tts-provider openai-tts \
--tts-voice fable \
--tts-use-ai-response

Speed Adjustment​

neurolink generate "Slow and clear narration." \
--tts --tts-provider openai-tts \
--tts-voice alloy \
--tts-speed 0.75

Available Voices​

Voice IDGenderCharacterBest For
alloyNeutralBalanced, clear, versatileGeneral purpose, default
echoMaleCrisp, authoritativeAnnouncements, business content
fableNeutralWarm, expressive, storytellingNarration, audiobooks
onyxMaleDeep, confident, professionalVoiceovers, documentary
novaFemaleBright, friendly, conversationalVoice assistants, customer-facing
shimmerFemaleSoft, gentle, calmWellness apps, guided meditation

OpenAI voices are language-agnostic — they follow the language of the input text automatically, supporting English, Spanish, French, German, Japanese, and many more.


Audio Formats​

FormatExtensionUse CaseNotes
mp3.mp3Default; web, mobile, general storage24 kHz sample rate
wav.wavUncompressed; audio editors, processing24 kHz sample rate
ogg.oggBrowser streaming, web appsOpus codec at 48 kHz
opus.opusLow-bandwidth streamingOpus codec at 48 kHz

Configuration Reference​

Environment VariableRequiredDefaultDescription
OPENAI_API_KEYYes—OpenAI API key (starts with sk-)

Defaults for model (tts-1) and voice (alloy) are set in code; override per call via tts.model / tts.voice in the SDK or --tts-model / --tts-voice on the CLI. There are no OPENAI_TTS_MODEL / OPENAI_TTS_VOICE env vars.


Feature Support Matrix​

FeatureSupportedNotes
Text synthesisYes
AI response synthesisYesSet useAiResponse: true
HD qualityYesquality: "hd" maps to tts-1-hd
Speed controlYes0.25 – 4.0
Voice selectionYes6 neural voices
Multiple formatsYesmp3, wav, ogg, opus
Streaming TTSNoBatch synthesis only
Pitch / volume controlNoNot supported by OpenAI TTS API
Custom voicesNoOnly built-in voices supported

Troubleshooting​

"OpenAI TTS API key not configured"​

The OPENAI_API_KEY environment variable is missing or was not loaded.

# Check the variable is set
echo $OPENAI_API_KEY

# Set it for the current session
export OPENAI_API_KEY=sk-...

Create or rotate keys at https://platform.openai.com/api-keys.

"HTTP 429" — Rate limit exceeded​

You have hit OpenAI's TTS rate limits. Implement exponential backoff or reduce request concurrency. Rate limits are per-key and depend on your usage tier.

"HTTP 400" — Request too long​

The input text exceeds 4,096 characters. Split long content into smaller chunks and synthesise each separately.

function chunkText(text: string, maxLen = 4000): string[] {
const chunks: string[] = [];
for (let i = 0; i < text.length; i += maxLen) {
chunks.push(text.slice(i, i + maxLen));
}
return chunks;
}

"OpenAI TTS request timed out after 30 seconds"​

A network issue or overloaded API caused the request to time out. Retry the request — the error is marked retriable by NeuroLink's error system.

Audio sounds distorted at high speed​

Speeds above 2.0 can introduce artifacts. Use speed: 1.0 – 1.5 for natural-sounding output.


See Also​


Need Help? Join the GitHub Discussions or open an issue.