talk.dev Voice AI SDK Examples
Competitive Positioning Against ElevenLabs
talk.dev delivers the same functionality as ElevenLabs with superior performance and developer experience:
| Feature | ElevenLabs | talk.dev | Advantage |
|---|---|---|---|
| Synthesis Speed | 200ms+ | <150ms | 25% faster |
| Voice Cloning | 5-15 minutes | 2-5 minutes | 50% faster |
| Pricing | $0.004/1K chars | $0.002/1K chars | 50% cheaper |
| Languages | 20+ | 25+ | More languages |
| Real-time | Limited | Full WebSocket | Better streaming |
| API Design | Complex | RESTful | Simpler integration |
JavaScript/TypeScript SDK
Installation
npm install @talk/ai-sdk
# or
yarn add @talk/ai-sdkBasic Text-to-Speech
import { TalkAI } from "@talk/ai-sdk";
const client = new TalkAI("your-api-key");
async function basicSynthesis() {
const audio = await client.synthesize({
text: "Hello world, this is talk.dev voice AI!",
voice: "sarah-professional",
format: "mp3",
});
console.log(`Audio URL: ${audio.audio_url}`);
console.log(`Duration: ${audio.duration}s`);
console.log(`Processing time: ${audio.processing_time}ms`);
}Advanced Synthesis with Emotion Control
async function emotionalSynthesis() {
const audio = await client.synthesize({
text: "I'm so excited to help you build amazing voice applications!",
voice: "alex-conversational",
emotion: "enthusiastic",
speed: 1.1,
pitch: 0.05,
format: "wav",
quality: "ultra",
});
return audio;
}Voice Cloning Workflow
async function cloneVoiceWorkflow() {
// Step 1: Upload audio sample for cloning
const cloneJob = await client.voices.clone({
name: "CEO Voice",
description: "Professional male voice for corporate content",
audioFile: audioFile, // File object or Buffer
consentVerified: true,
});
console.log(`Clone ID: ${cloneJob.clone_id}`);
console.log(`Status: ${cloneJob.status}`);
// Step 2: Wait for completion (with progress tracking)
const voice = await client.voices.waitForClone(cloneJob.clone_id, {
onProgress: (progress) => console.log(`Progress: ${progress}%`),
timeout: 300000, // 5 minutes
});
console.log(`Voice cloned successfully: ${voice.voice_id}`);
// Step 3: Use the cloned voice
const customAudio = await client.synthesize({
text: "This is my cloned voice speaking",
voice: voice.voice_id,
format: "mp3",
});
return customAudio;
}Real-time Streaming Synthesis
async function streamingSynthesis() {
const stream = client.createStream({
voice: "sarah-professional",
format: "webm",
quality: "high",
onAudioChunk: (chunk) => {
// Play audio chunk immediately
playAudioChunk(chunk);
},
onComplete: () => {
console.log("Streaming synthesis complete");
},
onError: (error) => {
console.error("Streaming error:", error);
},
});
// Send text to be synthesized in real-time
await stream.addText("Hello there! ");
await stream.addText("This text is being synthesized ");
await stream.addText("as I speak it to you.");
// Finish the stream
await stream.end();
}Batch Processing Multiple Texts
async function batchSynthesis() {
const texts = [
"Welcome to our company podcast.",
"Today we're discussing AI innovation.",
"Thank you for listening!",
];
const audioPromises = texts.map((text, index) =>
client.synthesize({
text,
voice: "sarah-professional",
format: "mp3",
})
);
const audios = await Promise.all(audioPromises);
audios.forEach((audio, index) => {
console.log(`Audio ${index + 1}: ${audio.audio_url}`);
});
return audios;
}Usage Tracking and Analytics
async function checkUsage() {
const usage = await client.usage.get({
start_date: "2024-01-01",
end_date: "2024-01-31",
granularity: "day",
});
console.log(`Total characters: ${usage.total_usage.characters_synthesized}`);
console.log(`Total cost: $${usage.total_usage.cost_usd}`);
// Voice usage breakdown
usage.voice_usage.forEach((voice) => {
console.log(`${voice.voice_name}: ${voice.total_characters} characters`);
});
return usage;
}Python SDK
Installation
pip install talkaiBasic Usage
from talkai import TalkAI
client = TalkAI(api_key="your-api-key")
# Basic synthesis
audio = client.synthesize(
text="Hello world, this is talk.dev voice AI!",
voice="sarah-professional",
format="mp3"
)
print(f"Audio URL: {audio.audio_url}")
print(f"Duration: {audio.duration}s")Voice Cloning in Python
import asyncio
from talkai import TalkAI
async def clone_voice_example():
client = TalkAI(api_key="your-api-key")
# Upload audio file for cloning
with open("sample_voice.wav", "rb") as audio_file:
clone_job = await client.voices.clone(
name="Custom Voice",
audio_file=audio_file,
consent_verified=True
)
# Wait for completion
voice = await client.voices.wait_for_clone(
clone_job.clone_id,
timeout=300 # 5 minutes
)
# Use cloned voice
audio = await client.synthesize(
text="This is my cloned voice speaking",
voice=voice.voice_id
)
return audio
# Run async function
audio = asyncio.run(clone_voice_example())Real-time Streaming in Python
import asyncio
from talkai import TalkAI
async def streaming_example():
client = TalkAI(api_key="your-api-key")
async def audio_handler(chunk):
# Handle each audio chunk
print(f"Received audio chunk: {len(chunk)} bytes")
# Play audio chunk here
stream = await client.create_stream(
voice="alex-conversational",
format="wav",
on_audio_chunk=audio_handler
)
# Send text for real-time synthesis
await stream.add_text("Hello there! ")
await stream.add_text("This is streaming synthesis.")
await stream.end()
asyncio.run(streaming_example())Go SDK
Installation
go get github.com/talkdev/go-sdkBasic Usage
package main
import (
"context"
"fmt"
"log"
"github.com/talkdev/go-sdk/talkai"
)
func main() {
client := talkai.New("your-api-key")
ctx := context.Background()
// Basic synthesis
audio, err := client.Synthesize(ctx, &talkai.SynthesisRequest{
Text: "Hello world, this is talk.dev voice AI!",
Voice: "sarah-professional",
Format: "mp3",
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Audio URL: %s\n", audio.AudioURL)
fmt.Printf("Duration: %.2fs\n", audio.Duration)
}Voice Cloning in Go
func cloneVoiceExample() error {
client := talkai.New("your-api-key")
ctx := context.Background()
// Open audio file
audioFile, err := os.Open("sample_voice.wav")
if err != nil {
return err
}
defer audioFile.Close()
// Start cloning
cloneJob, err := client.Voices.Clone(ctx, &talkai.VoiceCloneRequest{
Name: "Custom Voice",
AudioFile: audioFile,
ConsentVerified: true,
})
if err != nil {
return err
}
// Wait for completion
voice, err := client.Voices.WaitForClone(ctx, cloneJob.CloneID, 5*time.Minute)
if err != nil {
return err
}
// Use cloned voice
audio, err := client.Synthesize(ctx, &talkai.SynthesisRequest{
Text: "This is my cloned voice speaking",
Voice: voice.VoiceID,
})
if err != nil {
return err
}
fmt.Printf("Custom audio: %s\n", audio.AudioURL)
return nil
}Ruby SDK
Installation
gem install talkaiBasic Usage
require 'talkai'
client = TalkAI::Client.new(api_key: 'your-api-key')
# Basic synthesis
audio = client.synthesize(
text: "Hello world, this is talk.dev voice AI!",
voice: "sarah-professional",
format: "mp3"
)
puts "Audio URL: #{audio.audio_url}"
puts "Duration: #{audio.duration}s"Voice Cloning in Ruby
# Clone voice from audio file
audio_file = File.open("sample_voice.wav", "rb")
clone_job = client.voices.clone(
name: "Custom Voice",
audio_file: audio_file,
consent_verified: true
)
# Wait for completion
voice = client.voices.wait_for_clone(clone_job.clone_id, timeout: 300)
# Use cloned voice
audio = client.synthesize(
text: "This is my cloned voice speaking",
voice: voice.voice_id
)
puts "Custom audio: #{audio.audio_url}"Use Case Examples
Content Creation (Competing with ElevenLabs' Core Market)
// Podcast narration
async function createPodcastNarration() {
const script = `
Welcome to TechTalk, the podcast where we explore
the latest innovations in artificial intelligence.
Today we're discussing the future of voice synthesis.
`;
const audio = await client.synthesize({
text: script,
voice: "david-podcast", // Professional male voice
emotion: "engaging",
speed: 0.95, // Slightly slower for clarity
format: "wav",
quality: "ultra",
});
return audio;
}
// Audiobook generation
async function generateAudiobook(chapters: string[]) {
const audioPromises = chapters.map((chapter) =>
client.synthesize({
text: chapter,
voice: "emma-storytelling",
emotion: "narrative",
format: "mp3",
quality: "high",
})
);
const audioChapters = await Promise.all(audioPromises);
return audioChapters;
}Gaming and Interactive Media
// Character voice generation
async function generateCharacterVoices() {
const characters = [
{ name: "Hero", voice: "brave-knight", dialogue: "For honor and glory!" },
{
name: "Wizard",
voice: "wise-mage",
dialogue: "Magic flows through all things",
},
{
name: "Merchant",
voice: "friendly-trader",
dialogue: "Welcome to my shop!",
},
];
const characterAudios = await Promise.all(
characters.map((char) =>
client.synthesize({
text: char.dialogue,
voice: char.voice,
emotion: "character-appropriate",
format: "ogg", // Optimized for games
})
)
);
return characterAudios;
}E-learning and Accessibility
// Course narration with multiple languages
async function createMultilingualCourse(content: string) {
const languages = [
{ code: "en-US", voice: "sarah-educator" },
{ code: "es-ES", voice: "maria-profesora" },
{ code: "fr-FR", voice: "claire-instructeur" },
];
const translations = await Promise.all(
languages.map(async (lang) => {
// Assume translation service
const translatedContent = await translateText(content, lang.code);
return client.synthesize({
text: translatedContent,
voice: lang.voice,
emotion: "educational",
speed: 0.9, // Slower for learning
format: "mp3",
});
})
);
return translations;
}Live Applications
// Real-time chat synthesis
async function liveChat() {
const stream = client.createStream({
voice: "assistant-friendly",
format: "webm",
onAudioChunk: (chunk) => {
// Play immediately for real-time chat
audioContext.playChunk(chunk);
},
});
// Simulate chat messages being synthesized in real-time
chatSocket.on("message", async (message) => {
await stream.addText(message.text + " ");
});
return stream;
}Migration from ElevenLabs
API Compatibility Layer
// ElevenLabs compatibility wrapper
class ElevenLabsCompatibility {
private client: TalkAI;
constructor(apiKey: string) {
this.client = new TalkAI(apiKey);
}
// ElevenLabs-style text-to-speech
async textToSpeech(text: string, voiceId: string, voiceSettings?: any) {
return this.client.synthesize({
text,
voice: this.mapVoiceId(voiceId),
speed: voiceSettings?.stability || 1.0,
emotion: voiceSettings?.clarity_boost ? "clear" : "neutral",
format: "mp3",
});
}
// ElevenLabs-style voice cloning
async cloneVoice(name: string, files: File[]) {
return this.client.voices.clone({
name,
audioFile: files[0], // Use first file
consentVerified: true,
});
}
private mapVoiceId(elevenLabsId: string): string {
// Map ElevenLabs voice IDs to talk.dev equivalents
const voiceMap: Record<string, string> = {
"21m00Tcm4TlvDq8ikWAM": "sarah-professional",
AZnzlk1XvdvUeBnXmlld: "alex-conversational",
// Add more mappings as needed
};
return voiceMap[elevenLabsId] || "sarah-professional";
}
}
// Easy migration
const talkdev = new ElevenLabsCompatibility("your-talk-dev-api-key");Performance Comparisons
Latency Benchmarks
// Benchmark against ElevenLabs
async function performanceBenchmark() {
const testText = "This is a performance benchmark test.";
console.time("talk.dev synthesis");
const talkdevAudio = await client.synthesize({
text: testText,
voice: "sarah-professional",
});
console.timeEnd("talk.dev synthesis");
// Expected: ~140ms
console.log(`talk.dev processing time: ${talkdevAudio.processing_time}ms`);
// ElevenLabs typically takes 200ms+ for similar requests
return {
provider: "talk.dev",
latency: talkdevAudio.processing_time,
advantage: "25%+ faster",
};
}Cost Comparison
async function costComparison() {
const monthlyUsage = await client.usage.get({
start_date: "2024-01-01",
end_date: "2024-01-31",
});
const talkdevCost = monthlyUsage.total_usage.cost_usd;
const elevenLabsEquivalentCost =
(monthlyUsage.total_usage.characters_synthesized * 0.004) / 1000;
const savings = elevenLabsEquivalentCost - talkdevCost;
const savingsPercent = (savings / elevenLabsEquivalentCost) * 100;
console.log(`talk.dev cost: $${talkdevCost.toFixed(2)}`);
console.log(`ElevenLabs equivalent: $${elevenLabsEquivalentCost.toFixed(2)}`);
console.log(
`Savings: $${savings.toFixed(2)} (${savingsPercent.toFixed(1)}%)`
);
return {
talkdevCost,
elevenLabsCost: elevenLabsEquivalentCost,
savings,
savingsPercent,
};
}This comprehensive SDK documentation positions talk.dev as a superior alternative to ElevenLabs across all major programming languages and use cases, with clear performance advantages and migration paths.