curl --request POST \
--url https://api.electronhub.ai/v1/audio/speech \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "tts-1",
"input": "Hello, world! This is a text-to-speech example.",
"voice": "alloy",
"response_format": "mp3",
"speed": 1,
"temperature": 1,
"top_p": 0.5,
"instructions": "<string>",
"speaker_transcript": "<string>",
"cfg_filter_top_k": 32,
"cfg_scale": 3,
"speech_rate": 0,
"pitch_adjustment": 0,
"emotional_style": "<string>"
}
'import requests
url = "https://api.electronhub.ai/v1/audio/speech"
payload = {
"model": "tts-1",
"input": "Hello, world! This is a text-to-speech example.",
"voice": "alloy",
"response_format": "mp3",
"speed": 1,
"temperature": 1,
"top_p": 0.5,
"instructions": "<string>",
"speaker_transcript": "<string>",
"cfg_filter_top_k": 32,
"cfg_scale": 3,
"speech_rate": 0,
"pitch_adjustment": 0,
"emotional_style": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'tts-1',
input: 'Hello, world! This is a text-to-speech example.',
voice: 'alloy',
response_format: 'mp3',
speed: 1,
temperature: 1,
top_p: 0.5,
instructions: '<string>',
speaker_transcript: '<string>',
cfg_filter_top_k: 32,
cfg_scale: 3,
speech_rate: 0,
pitch_adjustment: 0,
emotional_style: '<string>'
})
};
fetch('https://api.electronhub.ai/v1/audio/speech', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.electronhub.ai/v1/audio/speech",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'tts-1',
'input' => 'Hello, world! This is a text-to-speech example.',
'voice' => 'alloy',
'response_format' => 'mp3',
'speed' => 1,
'temperature' => 1,
'top_p' => 0.5,
'instructions' => '<string>',
'speaker_transcript' => '<string>',
'cfg_filter_top_k' => 32,
'cfg_scale' => 3,
'speech_rate' => 0,
'pitch_adjustment' => 0,
'emotional_style' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.electronhub.ai/v1/audio/speech"
payload := strings.NewReader("{\n \"model\": \"tts-1\",\n \"input\": \"Hello, world! This is a text-to-speech example.\",\n \"voice\": \"alloy\",\n \"response_format\": \"mp3\",\n \"speed\": 1,\n \"temperature\": 1,\n \"top_p\": 0.5,\n \"instructions\": \"<string>\",\n \"speaker_transcript\": \"<string>\",\n \"cfg_filter_top_k\": 32,\n \"cfg_scale\": 3,\n \"speech_rate\": 0,\n \"pitch_adjustment\": 0,\n \"emotional_style\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.electronhub.ai/v1/audio/speech")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"tts-1\",\n \"input\": \"Hello, world! This is a text-to-speech example.\",\n \"voice\": \"alloy\",\n \"response_format\": \"mp3\",\n \"speed\": 1,\n \"temperature\": 1,\n \"top_p\": 0.5,\n \"instructions\": \"<string>\",\n \"speaker_transcript\": \"<string>\",\n \"cfg_filter_top_k\": 32,\n \"cfg_scale\": 3,\n \"speech_rate\": 0,\n \"pitch_adjustment\": 0,\n \"emotional_style\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.electronhub.ai/v1/audio/speech")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"tts-1\",\n \"input\": \"Hello, world! This is a text-to-speech example.\",\n \"voice\": \"alloy\",\n \"response_format\": \"mp3\",\n \"speed\": 1,\n \"temperature\": 1,\n \"top_p\": 0.5,\n \"instructions\": \"<string>\",\n \"speaker_transcript\": \"<string>\",\n \"cfg_filter_top_k\": 32,\n \"cfg_scale\": 3,\n \"speech_rate\": 0,\n \"pitch_adjustment\": 0,\n \"emotional_style\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body"<string>"Text-to-Speech
Generate natural-sounding speech from text using AI voice models
curl --request POST \
--url https://api.electronhub.ai/v1/audio/speech \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "tts-1",
"input": "Hello, world! This is a text-to-speech example.",
"voice": "alloy",
"response_format": "mp3",
"speed": 1,
"temperature": 1,
"top_p": 0.5,
"instructions": "<string>",
"speaker_transcript": "<string>",
"cfg_filter_top_k": 32,
"cfg_scale": 3,
"speech_rate": 0,
"pitch_adjustment": 0,
"emotional_style": "<string>"
}
'import requests
url = "https://api.electronhub.ai/v1/audio/speech"
payload = {
"model": "tts-1",
"input": "Hello, world! This is a text-to-speech example.",
"voice": "alloy",
"response_format": "mp3",
"speed": 1,
"temperature": 1,
"top_p": 0.5,
"instructions": "<string>",
"speaker_transcript": "<string>",
"cfg_filter_top_k": 32,
"cfg_scale": 3,
"speech_rate": 0,
"pitch_adjustment": 0,
"emotional_style": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'tts-1',
input: 'Hello, world! This is a text-to-speech example.',
voice: 'alloy',
response_format: 'mp3',
speed: 1,
temperature: 1,
top_p: 0.5,
instructions: '<string>',
speaker_transcript: '<string>',
cfg_filter_top_k: 32,
cfg_scale: 3,
speech_rate: 0,
pitch_adjustment: 0,
emotional_style: '<string>'
})
};
fetch('https://api.electronhub.ai/v1/audio/speech', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.electronhub.ai/v1/audio/speech",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => 'tts-1',
'input' => 'Hello, world! This is a text-to-speech example.',
'voice' => 'alloy',
'response_format' => 'mp3',
'speed' => 1,
'temperature' => 1,
'top_p' => 0.5,
'instructions' => '<string>',
'speaker_transcript' => '<string>',
'cfg_filter_top_k' => 32,
'cfg_scale' => 3,
'speech_rate' => 0,
'pitch_adjustment' => 0,
'emotional_style' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.electronhub.ai/v1/audio/speech"
payload := strings.NewReader("{\n \"model\": \"tts-1\",\n \"input\": \"Hello, world! This is a text-to-speech example.\",\n \"voice\": \"alloy\",\n \"response_format\": \"mp3\",\n \"speed\": 1,\n \"temperature\": 1,\n \"top_p\": 0.5,\n \"instructions\": \"<string>\",\n \"speaker_transcript\": \"<string>\",\n \"cfg_filter_top_k\": 32,\n \"cfg_scale\": 3,\n \"speech_rate\": 0,\n \"pitch_adjustment\": 0,\n \"emotional_style\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.electronhub.ai/v1/audio/speech")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"tts-1\",\n \"input\": \"Hello, world! This is a text-to-speech example.\",\n \"voice\": \"alloy\",\n \"response_format\": \"mp3\",\n \"speed\": 1,\n \"temperature\": 1,\n \"top_p\": 0.5,\n \"instructions\": \"<string>\",\n \"speaker_transcript\": \"<string>\",\n \"cfg_filter_top_k\": 32,\n \"cfg_scale\": 3,\n \"speech_rate\": 0,\n \"pitch_adjustment\": 0,\n \"emotional_style\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.electronhub.ai/v1/audio/speech")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"tts-1\",\n \"input\": \"Hello, world! This is a text-to-speech example.\",\n \"voice\": \"alloy\",\n \"response_format\": \"mp3\",\n \"speed\": 1,\n \"temperature\": 1,\n \"top_p\": 0.5,\n \"instructions\": \"<string>\",\n \"speaker_transcript\": \"<string>\",\n \"cfg_filter_top_k\": 32,\n \"cfg_scale\": 3,\n \"speech_rate\": 0,\n \"pitch_adjustment\": 0,\n \"emotional_style\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body"<string>"Create Speech
POST /audio/speech
Convert text to natural-sounding speech audio.
Request Body
Text Input Parameters
Voice Parameters
Common Parameters
Advanced Parameters
Response
Returns an audio file in the specified format.Basic Example
const response = await fetch('https://api.electronhub.ai/v1/audio/speech', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'tts-1',
input: 'Hello! Welcome to Electron Hub text-to-speech.',
voice: 'alloy',
response_format: 'mp3'
})
});
const audioBuffer = await response.arrayBuffer();
const fs = require('fs');
fs.writeFileSync('speech.mp3', Buffer.from(audioBuffer));
import requests
response = requests.post(
'https://api.electronhub.ai/v1/audio/speech',
headers={
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
json={
'model': 'tts-1',
'input': 'Hello! Welcome to Electron Hub text-to-speech.',
'voice': 'alloy',
'response_format': 'mp3'
}
)
with open('speech.mp3', 'wb') as f:
f.write(response.content)
curl https://api.electronhub.ai/v1/audio/speech \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "tts-1",
"input": "Hello! Welcome to Electron Hub text-to-speech.",
"voice": "alloy",
"response_format": "mp3"
}' \
--output speech.mp3
Provider-Specific Examples
OpenAI Models (TTS-1, TTS-1 HD, GPT-4o Mini TTS)
{
"model": "tts-1",
"input": "Hello, world!",
"voice": "alloy",
"speed": 1.0
}
{
"model": "gpt-4o-mini-tts",
"input": "Welcome to our store!",
"voice": "nova",
"instructions": "Speak with enthusiasm and excitement, like a friendly shopkeeper"
}
ElevenLabs Models
{
"model": "elevenlabs",
"input": "Hello, this is ElevenLabs TTS.",
"voice": "Will (US male)"
}
requests.post(
'https://api.electronhub.ai/v1/audio/speech',
json={
'model': 'elevenlabs',
'input': 'Bonjour, je parle français!',
'voice': 'Guillaume (French male)'
}
)
Kokoro 82M Model
{
"model": "kokoro-82m",
"input": "Hello from Kokoro TTS!",
"voice": "af_alloy",
"speed": 1.2
}
requests.post(
'https://api.electronhub.ai/v1/audio/speech',
json={
'model': 'kokoro-82m',
'input': 'こんにちは、世界!',
'voice': 'jf_alpha'
}
)
NariLabs Dia Model (Advanced)
{
"model": "dia-1.6b",
"input": "Hello, this is a conversational speech example.",
"speaker_transcript": "Speaking in a calm, professional tone",
"cfg_scale": 3,
"cfg_filter_top_k": 25,
"temperature": 1.2,
"speed": 0.9
}
requests.post(
'https://api.electronhub.ai/v1/audio/speech',
json={
'model': 'dia-1.6b',
'input': 'Let me tell you a story...',
'speaker_transcript': 'Narrator voice with dramatic pauses',
'cfg_scale': 4,
'temperature': 1.3
}
)
MeloTTS Multilingual
{
"model": "melotts",
"input": "Bonjour, comment allez-vous?",
"voice": "fr"
}
# English
requests.post('/v1/audio/speech', json={'model': 'melotts', 'input': 'Hello world', 'voice': 'en'})
# Spanish
requests.post('/v1/audio/speech', json={'model': 'melotts', 'input': 'Hola mundo', 'voice': 'es'})
# Chinese
requests.post('/v1/audio/speech', json={'model': 'melotts', 'input': '你好世界', 'voice': 'zh'})
PlayAI Dialog Models
{
"model": "playai-tts",
"input": "This is a conversational AI speaking.",
"voice": "Celeste-PlayAI",
"temperature": 0.8
}
requests.post(
'https://api.electronhub.ai/v1/audio/speech',
json={
'model': 'playai-tts-arabic',
'input': 'مرحبا بكم في الذكاء الاصطناعي',
'voice': 'Nasser-PlayAI'
}
)
Microsoft TTS
{
"model": "microsoft-tts",
"input": "Hello, this is Microsoft Azure Text-to-Speech.",
"voice": "en-US-JennyNeural"
}
{
"model": "microsoft-tts",
"input": "Welcome to our exciting new product launch!",
"voice": "en-US-AriaNeural",
"speech_rate": 10,
"pitch_adjustment": 5,
"emotional_style": "cheerful"
}
requests.post(
'https://api.electronhub.ai/v1/audio/speech',
json={
'model': 'microsoft-tts',
'input': '你好,欢迎使用微软语音合成服务!',
'voice': 'zh-CN-XiaoxiaoNeural',
'speech_rate': -10,
'emotional_style': 'gentle'
}
)
requests.post(
'https://api.electronhub.ai/v1/audio/speech',
json={
'model': 'microsoft-tts',
'input': 'I am so sorry to hear about that.',
'voice': 'en-US-SaraNeural',
'emotional_style': 'sad',
'speech_rate': -20
}
)
Available Models
OpenAI Models
TTS-1 (tts-1)
- Optimized for real-time text-to-speech
- Cost-effective for most applications
- 11 available voices: alloy, ash, ballad, coral, echo, fable, onyx, nova, sage, shimmer, verse
tts-1-hd)
- High-quality text-to-speech
- Best audio quality with slower generation
- Same 11 voices as TTS-1
gpt-4o-mini-tts)
- Advanced TTS with instruction following
- Supports voice control via instructions
- Same 11 voices as TTS-1
Premium Models
ElevenLabs (elevenlabs)
- Ultra-realistic human-like voices
- 40+ multilingual voices
- Supports English, Spanish, French, German, Arabic, Chinese, Hindi, Polish
playai-tts)
- Specialized for conversational content
- 27 expressive voices
- Optimized for dialogue and storytelling
Specialized Models
Kokoro 82M (kokoro-82m)
- Lightweight but high-quality
- 80+ voices in multiple languages
- Open-source Apache-licensed model
microsoft-tts)
- Enterprise-grade quality
- 100+ neural voices
- Extensive language support
Voice Examples
OpenAI Voices
// Available voices for OpenAI models
const openaiVoices = [
'alloy', // Neutral, balanced
'echo', // Clear, professional
'fable', // Warm, storytelling
'onyx', // Deep, authoritative
'nova', // Bright, energetic
'shimmer' // Gentle, soothing
];
ElevenLabs Voices
// Sample of ElevenLabs voices by language
const elevenlabsVoices = {
english: ['Will (US male)', 'Jessica (US female)', 'George (UK male)', 'Lily (UK female)'],
spanish: ['Juan (Spanish male)', 'Gabriela (Spanish female)'],
french: ['Guillaume (French male)', 'Darine (French female)'],
german: ['Kurt (German male)', 'Leonie (German female)']
};
// Use with voice parameter and text input
{
"model": "elevenlabs",
"input": "Hello world",
"voice": "Will (US male)"
}
Microsoft TTS Voices
// Sample of Microsoft Azure Neural voices
const microsoftVoices = {
english: [
'en-US-JennyNeural', // Friendly female
'en-US-GuyNeural', // Casual male
'en-US-AriaNeural', // News anchor style
'en-US-DavisNeural', // Professional male
'en-GB-SoniaNeural', // British female
'en-AU-NatashaNeural' // Australian female
],
chinese: [
'zh-CN-XiaoxiaoNeural', // Standard female
'zh-CN-YunyangNeural', // Professional male
'zh-HK-HiuMaanNeural', // Hong Kong Cantonese
'zh-TW-HsiaoChenNeural' // Taiwan Mandarin
],
multilingual: [
'es-ES-ElviraNeural', // Spanish
'fr-FR-DeniseNeural', // French
'de-DE-KatjaNeural', // German
'ja-JP-NanamiNeural', // Japanese
'ko-KR-SunHiNeural' // Korean
]
};
// Use with text input and advanced controls
{
"model": "microsoft-tts",
"input": "Hello world",
"voice": "en-US-AriaNeural",
"emotional_style": "cheerful",
"speech_rate": 10
}
Model-Specific Parameters
| Provider | Special Parameters | Usage |
|---|---|---|
| GPT-4o Mini TTS | instructions | Natural language voice control |
| Dia 1.6B | speaker_transcript, cfg_scale, cfg_filter_top_k | Advanced voice conditioning |
| Microsoft TTS | speech_rate, pitch_adjustment, emotional_style | Voice modulation and emotions |
| MeloTTS | lang | Language selection (en, fr, es, etc.) |
| All Models | speed, temperature, top_p | Common generation controls |
Advanced Features
Speed Control
Adjust playback speed for different use cases:{
"model": "tts-1",
"input": "This text will be spoken faster.",
"voice": "alloy",
"speed": 1.5
}
Audio Formats
Choose the optimal format for your application:- MP3: Standard, widely compatible
- WAV: Uncompressed, highest quality
- OGG/Opus: Efficient compression
- FLAC: Lossless compression
- AAC: Good balance of quality and size
Instruction-Based Control (GPT-4o Mini TTS)
Control voice characteristics with natural language:{
"model": "gpt-4o-mini-tts",
"input": "Welcome to our store!",
"voice": "alloy",
"instructions": "Speak with enthusiasm and excitement, like a friendly shopkeeper"
}
Microsoft TTS Advanced Controls
Microsoft TTS offers fine-grained control over speech characteristics:Speech Rate Control
{
"model": "microsoft-tts",
"input": "This text will be spoken faster.",
"voice": "en-US-JennyNeural",
"speech_rate": 50
}
Pitch Adjustment
{
"model": "microsoft-tts",
"input": "This text has a higher pitch.",
"voice": "en-US-AriaNeural",
"pitch_adjustment": 25
}
Emotional Styles
Different voices support different emotional styles:{
"model": "microsoft-tts",
"input": "I'm so excited about this news!",
"voice": "en-US-AriaNeural",
"emotional_style": "cheerful",
"speech_rate": 10
}
cheerful- Happy and upbeatsad- Melancholic toneangry- Frustrated or upsetfearful- Nervous or scaredcalm- Relaxed and peacefulgentle- Soft and caringnewscast- Professional news anchorcustomerservice- Helpful and polite
Best Practices
Text Optimization
- Use clear punctuation for natural pauses
- Spell out numbers and abbreviations
- Use SSML tags for fine-grained control (model-dependent)
Voice Selection
- Customer Service: Professional voices (echo, George)
- Storytelling: Warm voices (fable, nova)
- Educational: Clear voices (alloy, shimmer)
- Gaming: Character voices (onyx, sage)
Performance Tips
- Cache generated audio when possible
- Use appropriate audio formats for your platform
- Consider real-time vs. high-quality models based on use case
Error Handling
Common error scenarios:try {
const response = await fetch('/v1/audio/speech', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'tts-1',
input: text,
voice: 'alloy'
})
});
if (!response.ok) {
const error = await response.json();
console.error('TTS Error:', error);
}
} catch (error) {
console.error('Network Error:', error);
}
Use Cases
- Voice Assistants: Natural conversation interfaces
- Audiobooks: Long-form content narration
- E-learning: Educational content delivery
- Accessibility: Screen reader alternatives
- Gaming: Character voice generation
- Customer Service: Automated phone systems
- Content Creation: Podcast and video narration
Authorizations
Enter your API key (starts with 'ek-')
Body
The TTS model to use for speech generation
"tts-1"
The text to convert to speech (OpenAI models)
1 - 4096"Hello, world! This is a text-to-speech example."
The voice to use for speech generation (OpenAI, Orpheus, PlayAI, ElevenLabs models)
"alloy"
The audio format for the generated speech
mp3, opus, aac, flac, wav, pcm The speed of the generated audio
0.25 <= x <= 4Temperature for randomness in speech generation
0 <= x <= 2Top-p value for nucleus sampling
0 <= x <= 1Additional instructions to control voice generation (GPT-4o Mini TTS)
Speaker transcript for Dia model
1000CFG filter top k value (Dia model)
15 <= x <= 50CFG scale value (Dia model)
1 <= x <= 5Speech rate adjustment for Microsoft TTS (-100 to 100)
-100 <= x <= 100Pitch adjustment for Microsoft TTS (-100 to 100)
-100 <= x <= 100Emotional style for Microsoft TTS (e.g., 'cheerful', 'sad', 'angry')
Response
Audio file
The response is of type file.
