ttp-agent-sdk 2.3.1 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_headers +17 -0
- package/dist/agent-widget.js.map +1 -1
- package/dist/index.html +459 -20
- package/dist/script.js +1 -351
- package/dist/styles.css +1 -1
- package/package.json +2 -2
package/dist/index.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>TTP Agent SDK - Documentation</title>
|
|
7
|
-
<link rel="stylesheet" href="
|
|
7
|
+
<link rel="stylesheet" href="styles.css">
|
|
8
8
|
</head>
|
|
9
9
|
<body>
|
|
10
10
|
<!-- Mobile Header (only visible on mobile) -->
|
|
@@ -103,9 +103,13 @@
|
|
|
103
103
|
</a>
|
|
104
104
|
|
|
105
105
|
<a href="#react" class="quick-link-card">
|
|
106
|
-
<div class="quick-link-icon"
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
<div class="quick-link-icon" style="display: flex; gap: 8px; align-items: center;">
|
|
107
|
+
<span style="font-size: 2rem;">⚛️</span>
|
|
108
|
+
<span style="font-size: 2rem; color: #dd0031;">🅰️</span>
|
|
109
|
+
<span style="font-size: 1.5rem; font-weight: bold; background: #f7df1e; color: #000; padding: 4px 8px; border-radius: 4px; font-family: monospace;">JS</span>
|
|
110
|
+
</div>
|
|
111
|
+
<h3>Integrations</h3>
|
|
112
|
+
<p>React / Angular / Vanilla JS</p>
|
|
109
113
|
<span class="quick-link-arrow">→</span>
|
|
110
114
|
</a>
|
|
111
115
|
|
|
@@ -115,6 +119,13 @@
|
|
|
115
119
|
<p>Dynamic AI customization</p>
|
|
116
120
|
<span class="quick-link-arrow">→</span>
|
|
117
121
|
</a>
|
|
122
|
+
|
|
123
|
+
<a href="#text-to-speech" class="quick-link-card">
|
|
124
|
+
<div class="quick-link-icon">🔊</div>
|
|
125
|
+
<h3>Text To Speech</h3>
|
|
126
|
+
<p>REST API for voice synthesis</p>
|
|
127
|
+
<span class="quick-link-arrow">→</span>
|
|
128
|
+
</a>
|
|
118
129
|
</div>
|
|
119
130
|
</div>
|
|
120
131
|
|
|
@@ -127,7 +138,7 @@
|
|
|
127
138
|
<div>
|
|
128
139
|
<strong>Secure Authentication</strong>
|
|
129
140
|
<p>Backend-to-backend signed link authentication with one-time use tokens</p>
|
|
130
|
-
|
|
141
|
+
</div>
|
|
131
142
|
</div>
|
|
132
143
|
<div class="feature-compact-item">
|
|
133
144
|
<span class="feature-compact-icon">🎨</span>
|
|
@@ -463,12 +474,16 @@ app.post('/api/get-voice-session', async (req, res) => {
|
|
|
463
474
|
|
|
464
475
|
// Voice settings
|
|
465
476
|
voiceSpeed: 1.2,
|
|
466
|
-
|
|
477
|
+
voiceId: "nova", // Use voiceId (not selectedVoice)
|
|
467
478
|
|
|
468
479
|
// Behavior
|
|
469
480
|
firstMessage: "¡Hola! ¿Cómo puedo ayudarte hoy?",
|
|
470
481
|
disableInterruptions: false,
|
|
471
|
-
autoDetectLanguage: true
|
|
482
|
+
autoDetectLanguage: true,
|
|
483
|
+
|
|
484
|
+
// Tools (optional)
|
|
485
|
+
toolIds: [123, 456, 789], // Custom tool IDs
|
|
486
|
+
internalToolIds: ['calendar', 'email'] // Internal tool IDs
|
|
472
487
|
}
|
|
473
488
|
});</code></pre>
|
|
474
489
|
|
|
@@ -487,7 +502,6 @@ app.post('/api/get-voice-session', async (req, res) => {
|
|
|
487
502
|
<div class="settings-category">
|
|
488
503
|
<h3>🔊 Voice Settings</h3>
|
|
489
504
|
<ul>
|
|
490
|
-
<li><code>selectedVoice</code> - Voice preset name</li>
|
|
491
505
|
<li><code>voiceId</code> - Specific voice ID</li>
|
|
492
506
|
<li><code>voiceSpeed</code> - Speed multiplier (0.5-2)</li>
|
|
493
507
|
</ul>
|
|
@@ -504,7 +518,8 @@ app.post('/api/get-voice-session', async (req, res) => {
|
|
|
504
518
|
<div class="settings-category">
|
|
505
519
|
<h3>🛠️ Advanced</h3>
|
|
506
520
|
<ul>
|
|
507
|
-
<li><code>
|
|
521
|
+
<li><code>toolIds</code> - Array of custom tool IDs</li>
|
|
522
|
+
<li><code>internalToolIds</code> - Array of internal tool IDs</li>
|
|
508
523
|
<li><code>timezone</code> - User timezone</li>
|
|
509
524
|
</ul>
|
|
510
525
|
</div>
|
|
@@ -2333,12 +2348,6 @@ function App() {
|
|
|
2333
2348
|
</tr>
|
|
2334
2349
|
</thead>
|
|
2335
2350
|
<tbody>
|
|
2336
|
-
<tr>
|
|
2337
|
-
<td><code>selectedVoice</code></td>
|
|
2338
|
-
<td>string</td>
|
|
2339
|
-
<td>Voice names</td>
|
|
2340
|
-
<td>Voice preset name</td>
|
|
2341
|
-
</tr>
|
|
2342
2351
|
<tr>
|
|
2343
2352
|
<td><code>voiceId</code></td>
|
|
2344
2353
|
<td>string</td>
|
|
@@ -2404,10 +2413,16 @@ function App() {
|
|
|
2404
2413
|
</thead>
|
|
2405
2414
|
<tbody>
|
|
2406
2415
|
<tr>
|
|
2407
|
-
<td><code>
|
|
2416
|
+
<td><code>toolIds</code></td>
|
|
2417
|
+
<td>array</td>
|
|
2418
|
+
<td>Array of numbers</td>
|
|
2419
|
+
<td>Array of custom tool IDs to enable for this agent (e.g., [123, 456, 789])</td>
|
|
2420
|
+
</tr>
|
|
2421
|
+
<tr>
|
|
2422
|
+
<td><code>internalToolIds</code></td>
|
|
2408
2423
|
<td>array</td>
|
|
2409
|
-
<td>
|
|
2410
|
-
<td>Array of
|
|
2424
|
+
<td>Array of strings</td>
|
|
2425
|
+
<td>Array of internal tool IDs to enable for this agent (e.g., ['calendar', 'weather', 'email'])</td>
|
|
2411
2426
|
</tr>
|
|
2412
2427
|
<tr>
|
|
2413
2428
|
<td><code>timezone</code></td>
|
|
@@ -2420,7 +2435,431 @@ function App() {
|
|
|
2420
2435
|
</section>
|
|
2421
2436
|
</div>
|
|
2422
2437
|
|
|
2423
|
-
|
|
2438
|
+
\n <!-- Text-to-Speech API -->
|
|
2439
|
+
<section id="text-to-speech" class="doc-section">
|
|
2440
|
+
<h1>Text-to-Speech API</h1>
|
|
2441
|
+
<p class="badge-new">PUBLIC REST API</p>
|
|
2442
|
+
<p>Generate high-quality voice audio from text using our public REST API endpoint.</p>
|
|
2443
|
+
|
|
2444
|
+
<div class="info-box">
|
|
2445
|
+
<strong>🔒 Authentication:</strong> This endpoint requires API key authentication. Never expose your API key in frontend code - always call from your backend.
|
|
2446
|
+
</div>
|
|
2447
|
+
|
|
2448
|
+
<h2>Endpoint</h2>
|
|
2449
|
+
<pre><code>POST https://backend.talktopc.com/api/public/agents/tts/generate</code></pre>
|
|
2450
|
+
|
|
2451
|
+
<h2>Authentication</h2>
|
|
2452
|
+
<p>Include your API key in the Authorization header:</p>
|
|
2453
|
+
<pre><code>Authorization: Bearer YOUR_API_KEY</code></pre>
|
|
2454
|
+
|
|
2455
|
+
<h2>Request Parameters</h2>
|
|
2456
|
+
<table class="properties-table">
|
|
2457
|
+
<thead>
|
|
2458
|
+
<tr>
|
|
2459
|
+
<th>Parameter</th>
|
|
2460
|
+
<th>Type</th>
|
|
2461
|
+
<th>Required</th>
|
|
2462
|
+
<th>Description</th>
|
|
2463
|
+
</tr>
|
|
2464
|
+
</thead>
|
|
2465
|
+
<tbody>
|
|
2466
|
+
<tr>
|
|
2467
|
+
<td><code>text</code></td>
|
|
2468
|
+
<td>string</td>
|
|
2469
|
+
<td>Yes</td>
|
|
2470
|
+
<td>The text to convert to speech</td>
|
|
2471
|
+
</tr>
|
|
2472
|
+
<tr>
|
|
2473
|
+
<td><code>voiceId</code></td>
|
|
2474
|
+
<td>string</td>
|
|
2475
|
+
<td>No</td>
|
|
2476
|
+
<td>Voice identifier (default: agent's configured voice)</td>
|
|
2477
|
+
</tr>
|
|
2478
|
+
<tr>
|
|
2479
|
+
<td><code>voiceSpeed</code></td>
|
|
2480
|
+
<td>number</td>
|
|
2481
|
+
<td>No</td>
|
|
2482
|
+
<td>Voice speed multiplier: 0.5 - 2.0 (default: 1.0)</td>
|
|
2483
|
+
</tr>
|
|
2484
|
+
<tr>
|
|
2485
|
+
<td><code>language</code></td>
|
|
2486
|
+
<td>string</td>
|
|
2487
|
+
<td>No</td>
|
|
2488
|
+
<td>Language code (e.g., 'en', 'es', 'fr')</td>
|
|
2489
|
+
</tr>
|
|
2490
|
+
<tr>
|
|
2491
|
+
<td><code>agentId</code></td>
|
|
2492
|
+
<td>string</td>
|
|
2493
|
+
<td>No</td>
|
|
2494
|
+
<td>Agent ID to use voice settings from</td>
|
|
2495
|
+
</tr>
|
|
2496
|
+
</tbody>
|
|
2497
|
+
</table>
|
|
2498
|
+
|
|
2499
|
+
<h2>Example Requests</h2>
|
|
2500
|
+
|
|
2501
|
+
<style>
|
|
2502
|
+
.code-tabs {
|
|
2503
|
+
margin: 20px 0;
|
|
2504
|
+
}
|
|
2505
|
+
.code-tabs-header {
|
|
2506
|
+
display: flex;
|
|
2507
|
+
gap: 5px;
|
|
2508
|
+
border-bottom: 2px solid #e2e8f0;
|
|
2509
|
+
margin-bottom: 0;
|
|
2510
|
+
}
|
|
2511
|
+
.code-tab-button {
|
|
2512
|
+
padding: 10px 20px;
|
|
2513
|
+
background: #f8fafc;
|
|
2514
|
+
border: none;
|
|
2515
|
+
border-bottom: 3px solid transparent;
|
|
2516
|
+
cursor: pointer;
|
|
2517
|
+
font-weight: 500;
|
|
2518
|
+
color: #64748b;
|
|
2519
|
+
transition: all 0.2s;
|
|
2520
|
+
}
|
|
2521
|
+
.code-tab-button:hover {
|
|
2522
|
+
background: #e2e8f0;
|
|
2523
|
+
color: #334155;
|
|
2524
|
+
}
|
|
2525
|
+
.code-tab-button.active {
|
|
2526
|
+
background: white;
|
|
2527
|
+
color: #7c3aed;
|
|
2528
|
+
border-bottom-color: #7c3aed;
|
|
2529
|
+
}
|
|
2530
|
+
.code-tab-content {
|
|
2531
|
+
display: none;
|
|
2532
|
+
}
|
|
2533
|
+
.code-tab-content.active {
|
|
2534
|
+
display: block;
|
|
2535
|
+
}
|
|
2536
|
+
</style>
|
|
2537
|
+
|
|
2538
|
+
<div class="code-tabs">
|
|
2539
|
+
<div class="code-tabs-header">
|
|
2540
|
+
<button class="code-tab-button active" onclick="showTab(event, 'tab-curl')">cURL</button>
|
|
2541
|
+
<button class="code-tab-button" onclick="showTab(event, 'tab-nodejs')">Node.js</button>
|
|
2542
|
+
<button class="code-tab-button" onclick="showTab(event, 'tab-python')">Python</button>
|
|
2543
|
+
<button class="code-tab-button" onclick="showTab(event, 'tab-php')">PHP</button>
|
|
2544
|
+
<button class="code-tab-button" onclick="showTab(event, 'tab-java')">Java</button>
|
|
2545
|
+
</div>
|
|
2546
|
+
|
|
2547
|
+
<div id="tab-curl" class="code-tab-content active">
|
|
2548
|
+
<pre><code>curl -X POST https://backend.talktopc.com/api/public/agents/tts/generate \
|
|
2549
|
+
-H "Content-Type: application/json" \
|
|
2550
|
+
-H "Authorization: Bearer YOUR_API_KEY" \
|
|
2551
|
+
-d '{
|
|
2552
|
+
"text": "Hello! Welcome to our service.",
|
|
2553
|
+
"voiceId": "nova",
|
|
2554
|
+
"voiceSpeed": 1.2,
|
|
2555
|
+
"language": "en"
|
|
2556
|
+
}' \
|
|
2557
|
+
--output speech.mp3</code></pre>
|
|
2558
|
+
</div>
|
|
2559
|
+
|
|
2560
|
+
<div id="tab-nodejs" class="code-tab-content">
|
|
2561
|
+
<pre><code>const response = await fetch('https://backend.talktopc.com/api/public/agents/tts/generate', {
|
|
2562
|
+
method: 'POST',
|
|
2563
|
+
headers: {
|
|
2564
|
+
'Content-Type': 'application/json',
|
|
2565
|
+
'Authorization': `Bearer ${process.env.TTP_API_KEY}`
|
|
2566
|
+
},
|
|
2567
|
+
body: JSON.stringify({
|
|
2568
|
+
text: 'Hello! Welcome to our service.',
|
|
2569
|
+
voiceId: 'nova',
|
|
2570
|
+
voiceSpeed: 1.2,
|
|
2571
|
+
language: 'en'
|
|
2572
|
+
})
|
|
2573
|
+
});
|
|
2574
|
+
|
|
2575
|
+
// Response is audio file
|
|
2576
|
+
const audioBuffer = await response.arrayBuffer();
|
|
2577
|
+
const audioBlob = new Blob([audioBuffer], { type: 'audio/mpeg' });
|
|
2578
|
+
|
|
2579
|
+
// Play or save the audio
|
|
2580
|
+
const audioUrl = URL.createObjectURL(audioBlob);
|
|
2581
|
+
const audio = new Audio(audioUrl);
|
|
2582
|
+
audio.play();</code></pre>
|
|
2583
|
+
</div>
|
|
2584
|
+
|
|
2585
|
+
<div id="tab-python" class="code-tab-content">
|
|
2586
|
+
<pre><code>import requests
|
|
2587
|
+
import os
|
|
2588
|
+
|
|
2589
|
+
url = "https://backend.talktopc.com/api/public/agents/tts/generate"
|
|
2590
|
+
headers = {
|
|
2591
|
+
"Content-Type": "application/json",
|
|
2592
|
+
"Authorization": f"Bearer {os.environ['TTP_API_KEY']}"
|
|
2593
|
+
}
|
|
2594
|
+
data = {
|
|
2595
|
+
"text": "Hello! Welcome to our service.",
|
|
2596
|
+
"voiceId": "nova",
|
|
2597
|
+
"voiceSpeed": 1.2,
|
|
2598
|
+
"language": "en"
|
|
2599
|
+
}
|
|
2600
|
+
|
|
2601
|
+
response = requests.post(url, json=data, headers=headers)
|
|
2602
|
+
|
|
2603
|
+
if response.status_code == 200:
|
|
2604
|
+
# Save audio to file
|
|
2605
|
+
with open("speech.mp3", "wb") as f:
|
|
2606
|
+
f.write(response.content)
|
|
2607
|
+
print("Audio saved to speech.mp3")
|
|
2608
|
+
else:
|
|
2609
|
+
print(f"Error: {response.status_code}")</code></pre>
|
|
2610
|
+
</div>
|
|
2611
|
+
|
|
2612
|
+
<div id="tab-php" class="code-tab-content">
|
|
2613
|
+
<pre><code><?php
|
|
2614
|
+
$url = "https://backend.talktopc.com/api/public/agents/tts/generate";
|
|
2615
|
+
$apiKey = getenv('TTP_API_KEY');
|
|
2616
|
+
|
|
2617
|
+
$data = [
|
|
2618
|
+
'text' => 'Hello! Welcome to our service.',
|
|
2619
|
+
'voiceId' => 'nova',
|
|
2620
|
+
'voiceSpeed' => 1.2,
|
|
2621
|
+
'language' => 'en'
|
|
2622
|
+
];
|
|
2623
|
+
|
|
2624
|
+
$ch = curl_init($url);
|
|
2625
|
+
curl_setopt($ch, CURLOPT_POST, 1);
|
|
2626
|
+
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
|
|
2627
|
+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
2628
|
+
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
|
2629
|
+
'Content-Type: application/json',
|
|
2630
|
+
'Authorization: Bearer ' . $apiKey
|
|
2631
|
+
]);
|
|
2632
|
+
|
|
2633
|
+
$response = curl_exec($ch);
|
|
2634
|
+
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
2635
|
+
curl_close($ch);
|
|
2636
|
+
|
|
2637
|
+
if ($httpCode === 200) {
|
|
2638
|
+
file_put_contents('speech.mp3', $response);
|
|
2639
|
+
echo "Audio saved to speech.mp3";
|
|
2640
|
+
} else {
|
|
2641
|
+
echo "Error: HTTP $httpCode";
|
|
2642
|
+
}
|
|
2643
|
+
?></code></pre>
|
|
2644
|
+
</div>
|
|
2645
|
+
|
|
2646
|
+
<div id="tab-java" class="code-tab-content">
|
|
2647
|
+
<pre><code>import java.net.http.*;
|
|
2648
|
+
import java.net.URI;
|
|
2649
|
+
import java.nio.file.*;
|
|
2650
|
+
|
|
2651
|
+
public class TTSExample {
|
|
2652
|
+
public static void main(String[] args) throws Exception {
|
|
2653
|
+
String url = "https://backend.talktopc.com/api/public/agents/tts/generate";
|
|
2654
|
+
String apiKey = System.getenv("TTP_API_KEY");
|
|
2655
|
+
|
|
2656
|
+
String json = """
|
|
2657
|
+
{
|
|
2658
|
+
"text": "Hello! Welcome to our service.",
|
|
2659
|
+
"voiceId": "nova",
|
|
2660
|
+
"voiceSpeed": 1.2,
|
|
2661
|
+
"language": "en"
|
|
2662
|
+
}
|
|
2663
|
+
""";
|
|
2664
|
+
|
|
2665
|
+
HttpClient client = HttpClient.newHttpClient();
|
|
2666
|
+
HttpRequest request = HttpRequest.newBuilder()
|
|
2667
|
+
.uri(URI.create(url))
|
|
2668
|
+
.header("Content-Type", "application/json")
|
|
2669
|
+
.header("Authorization", "Bearer " + apiKey)
|
|
2670
|
+
.POST(HttpRequest.BodyPublishers.ofString(json))
|
|
2671
|
+
.build();
|
|
2672
|
+
|
|
2673
|
+
HttpResponse<byte[]> response = client.send(
|
|
2674
|
+
request,
|
|
2675
|
+
HttpResponse.BodyHandlers.ofByteArray()
|
|
2676
|
+
);
|
|
2677
|
+
|
|
2678
|
+
if (response.statusCode() == 200) {
|
|
2679
|
+
Files.write(Paths.get("speech.mp3"), response.body());
|
|
2680
|
+
System.out.println("Audio saved to speech.mp3");
|
|
2681
|
+
} else {
|
|
2682
|
+
System.out.println("Error: " + response.statusCode());
|
|
2683
|
+
}
|
|
2684
|
+
}
|
|
2685
|
+
}</code></pre>
|
|
2686
|
+
</div>
|
|
2687
|
+
</div>
|
|
2688
|
+
|
|
2689
|
+
<script>
|
|
2690
|
+
function showTab(event, tabId) {
|
|
2691
|
+
// Hide all tab contents
|
|
2692
|
+
const contents = document.querySelectorAll('.code-tab-content');
|
|
2693
|
+
contents.forEach(content => content.classList.remove('active'));
|
|
2694
|
+
|
|
2695
|
+
// Deactivate all tab buttons
|
|
2696
|
+
const buttons = document.querySelectorAll('.code-tab-button');
|
|
2697
|
+
buttons.forEach(button => button.classList.remove('active'));
|
|
2698
|
+
|
|
2699
|
+
// Show selected tab and activate button
|
|
2700
|
+
document.getElementById(tabId).classList.add('active');
|
|
2701
|
+
event.currentTarget.classList.add('active');
|
|
2702
|
+
}
|
|
2703
|
+
</script>
|
|
2704
|
+
|
|
2705
|
+
<h2>Response</h2>
|
|
2706
|
+
<p>The endpoint returns audio data directly with the following headers:</p>
|
|
2707
|
+
<table class="properties-table">
|
|
2708
|
+
<thead>
|
|
2709
|
+
<tr>
|
|
2710
|
+
<th>Header</th>
|
|
2711
|
+
<th>Value</th>
|
|
2712
|
+
<th>Description</th>
|
|
2713
|
+
</tr>
|
|
2714
|
+
</thead>
|
|
2715
|
+
<tbody>
|
|
2716
|
+
<tr>
|
|
2717
|
+
<td><code>Content-Type</code></td>
|
|
2718
|
+
<td>audio/mpeg</td>
|
|
2719
|
+
<td>Audio format (MP3)</td>
|
|
2720
|
+
</tr>
|
|
2721
|
+
<tr>
|
|
2722
|
+
<td><code>Content-Length</code></td>
|
|
2723
|
+
<td>number</td>
|
|
2724
|
+
<td>Size of audio file in bytes</td>
|
|
2725
|
+
</tr>
|
|
2726
|
+
</tbody>
|
|
2727
|
+
</table>
|
|
2728
|
+
|
|
2729
|
+
<h2>Voice Speed Examples</h2>
|
|
2730
|
+
<table class="properties-table">
|
|
2731
|
+
<thead>
|
|
2732
|
+
<tr>
|
|
2733
|
+
<th>Speed</th>
|
|
2734
|
+
<th>Effect</th>
|
|
2735
|
+
<th>Use Case</th>
|
|
2736
|
+
</tr>
|
|
2737
|
+
</thead>
|
|
2738
|
+
<tbody>
|
|
2739
|
+
<tr>
|
|
2740
|
+
<td><code>0.5</code></td>
|
|
2741
|
+
<td>50% slower (half speed)</td>
|
|
2742
|
+
<td>Educational content, accessibility</td>
|
|
2743
|
+
</tr>
|
|
2744
|
+
<tr>
|
|
2745
|
+
<td><code>0.75</code></td>
|
|
2746
|
+
<td>25% slower</td>
|
|
2747
|
+
<td>Clear pronunciation, language learning</td>
|
|
2748
|
+
</tr>
|
|
2749
|
+
<tr>
|
|
2750
|
+
<td><code>1.0</code></td>
|
|
2751
|
+
<td>Normal speed (default)</td>
|
|
2752
|
+
<td>Standard conversation</td>
|
|
2753
|
+
</tr>
|
|
2754
|
+
<tr>
|
|
2755
|
+
<td><code>1.2</code></td>
|
|
2756
|
+
<td>20% faster</td>
|
|
2757
|
+
<td>Quick updates, notifications</td>
|
|
2758
|
+
</tr>
|
|
2759
|
+
<tr>
|
|
2760
|
+
<td><code>1.5</code></td>
|
|
2761
|
+
<td>50% faster</td>
|
|
2762
|
+
<td>Rapid information delivery</td>
|
|
2763
|
+
</tr>
|
|
2764
|
+
<tr>
|
|
2765
|
+
<td><code>2.0</code></td>
|
|
2766
|
+
<td>2x speed (double speed)</td>
|
|
2767
|
+
<td>Maximum speed, time-saving</td>
|
|
2768
|
+
</tr>
|
|
2769
|
+
</tbody>
|
|
2770
|
+
</table>
|
|
2771
|
+
|
|
2772
|
+
<h2>Backend Implementation Example</h2>
|
|
2773
|
+
<pre><code>// Your backend endpoint
|
|
2774
|
+
app.post('/api/generate-speech', async (req, res) => {
|
|
2775
|
+
const { text, voiceSpeed = 1.0 } = req.body;
|
|
2776
|
+
|
|
2777
|
+
// Call TTP TTS API
|
|
2778
|
+
const ttpResponse = await fetch('https://backend.talktopc.com/api/public/agents/tts/generate', {
|
|
2779
|
+
method: 'POST',
|
|
2780
|
+
headers: {
|
|
2781
|
+
'Content-Type': 'application/json',
|
|
2782
|
+
'Authorization': `Bearer ${process.env.TTP_API_KEY}` // 🔒 Secret!
|
|
2783
|
+
},
|
|
2784
|
+
body: JSON.stringify({
|
|
2785
|
+
text: text,
|
|
2786
|
+
voiceSpeed: voiceSpeed,
|
|
2787
|
+
voiceId: 'nova',
|
|
2788
|
+
language: 'en'
|
|
2789
|
+
})
|
|
2790
|
+
});
|
|
2791
|
+
|
|
2792
|
+
if (!ttpResponse.ok) {
|
|
2793
|
+
return res.status(ttpResponse.status).json({
|
|
2794
|
+
error: 'TTS generation failed'
|
|
2795
|
+
});
|
|
2796
|
+
}
|
|
2797
|
+
|
|
2798
|
+
// Forward audio to client
|
|
2799
|
+
const audioBuffer = await ttpResponse.arrayBuffer();
|
|
2800
|
+
res.set('Content-Type', 'audio/mpeg');
|
|
2801
|
+
res.send(Buffer.from(audioBuffer));
|
|
2802
|
+
});</code></pre>
|
|
2803
|
+
|
|
2804
|
+
<h2>Error Responses</h2>
|
|
2805
|
+
<table class="properties-table">
|
|
2806
|
+
<thead>
|
|
2807
|
+
<tr>
|
|
2808
|
+
<th>Status Code</th>
|
|
2809
|
+
<th>Description</th>
|
|
2810
|
+
</tr>
|
|
2811
|
+
</thead>
|
|
2812
|
+
<tbody>
|
|
2813
|
+
<tr>
|
|
2814
|
+
<td><code>400</code></td>
|
|
2815
|
+
<td>Bad Request - Invalid parameters</td>
|
|
2816
|
+
</tr>
|
|
2817
|
+
<tr>
|
|
2818
|
+
<td><code>401</code></td>
|
|
2819
|
+
<td>Unauthorized - Invalid or missing API key</td>
|
|
2820
|
+
</tr>
|
|
2821
|
+
<tr>
|
|
2822
|
+
<td><code>429</code></td>
|
|
2823
|
+
<td>Too Many Requests - Rate limit exceeded</td>
|
|
2824
|
+
</tr>
|
|
2825
|
+
<tr>
|
|
2826
|
+
<td><code>500</code></td>
|
|
2827
|
+
<td>Internal Server Error - TTS generation failed</td>
|
|
2828
|
+
</tr>
|
|
2829
|
+
</tbody>
|
|
2830
|
+
</table>
|
|
2831
|
+
|
|
2832
|
+
<div class="warning-box">
|
|
2833
|
+
<strong>⚠️ Security Best Practices:</strong>
|
|
2834
|
+
<ul style="margin-top: 10px; margin-left: 20px;">
|
|
2835
|
+
<li>Never expose your API key in frontend JavaScript</li>
|
|
2836
|
+
<li>Always call this endpoint from your backend server</li>
|
|
2837
|
+
<li>Implement rate limiting on your backend</li>
|
|
2838
|
+
<li>Validate and sanitize text input to prevent abuse</li>
|
|
2839
|
+
</ul>
|
|
2840
|
+
</div>
|
|
2841
|
+
|
|
2842
|
+
<h2>Use Cases</h2>
|
|
2843
|
+
<div class="features">
|
|
2844
|
+
<div class="feature">
|
|
2845
|
+
<h4>📢 Announcements</h4>
|
|
2846
|
+
<p>Generate audio announcements for notifications</p>
|
|
2847
|
+
</div>
|
|
2848
|
+
<div class="feature">
|
|
2849
|
+
<h4>📚 Content Creation</h4>
|
|
2850
|
+
<p>Convert articles or books to audio format</p>
|
|
2851
|
+
</div>
|
|
2852
|
+
<div class="feature">
|
|
2853
|
+
<h4>♿ Accessibility</h4>
|
|
2854
|
+
<p>Provide audio alternatives for text content</p>
|
|
2855
|
+
</div>
|
|
2856
|
+
<div class="feature">
|
|
2857
|
+
<h4>🎓 E-Learning</h4>
|
|
2858
|
+
<p>Create voice-overs for educational materials</p>
|
|
2859
|
+
</div>
|
|
2860
|
+
</div>
|
|
2861
|
+
</section>
|
|
2862
|
+
\n <!-- Footer -->
|
|
2424
2863
|
<footer class="doc-footer">
|
|
2425
2864
|
<p>© 2024 TTP Agent SDK. Built with ❤️ for developers.</p>
|
|
2426
2865
|
<p>
|
|
@@ -2432,7 +2871,7 @@ function App() {
|
|
|
2432
2871
|
</main>
|
|
2433
2872
|
</div>
|
|
2434
2873
|
|
|
2435
|
-
<script src="
|
|
2874
|
+
<script src="script.js"></script>
|
|
2436
2875
|
</body>
|
|
2437
2876
|
</html>
|
|
2438
2877
|
|