Platform · Capacités
TTS
Implémenter la synthèse vocale — synthèse par lots et streaming temps réel optionnel.
Le mode par lots synthétise un buffer audio en une seule fois ; le mode temps réel diffuse des fragments de manière bidirectionnelle.
Définir la capacité
typescript
import { defineModels } from "@scrydon/sdk-authoring/extensions/define";
import type { TTSCapabilityConfig } from "@scrydon/sdk-authoring/extensions/capabilities/tts";
const ttsCapability: TTSCapabilityConfig = {
models: [
{ id: "tts-standard", name: "Standard TTS", voices: 6, benchmarks: [{ name: "MOS", score: 3.5, source: "Internal" }] },
{ id: "tts-hd", name: "HD TTS", voices: 6, benchmarks: [{ name: "MOS", score: 4.2, source: "Internal" }] },
],
defaultModel: "tts-standard",
// Batch mode — send text, get audio back
async synthesize(request) {
const response = await fetch("https://api.example.com/v1/synthesize", {
method: "POST",
headers: {
Authorization: `Bearer ${request.apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
text: request.text,
voice: request.voice,
model: request.model,
speed: request.speed,
}),
});
return {
audioBuffer: await response.arrayBuffer(),
format: "mp3",
mimeType: "audio/mpeg",
};
},
// Realtime streaming (optional)
realtime: {
protocol: "websocket",
async createSession(config) {
// The wire protocol is your vendor's; return a RealtimeSession.
const socket = new WebSocket("wss://api.example.com/v1/realtime-tts");
await new Promise((resolve, reject) => {
socket.addEventListener("open", resolve, { once: true });
socket.addEventListener("error", reject, { once: true });
});
socket.send(JSON.stringify({ type: "start", apiKey: config.apiKey, voice: config.voice, model: config.model }));
return {
sessionId: crypto.randomUUID(),
send: (chunk) => socket.send(chunk),
onMessage: (handler) =>
socket.addEventListener("message", (event) =>
handler({ type: "audio", data: event.data, timestamp: Date.now() })
),
close: async () => socket.close(),
};
},
features: { streamingInput: true, streamingOutput: true },
},
};
// One model family per runtime; list it under defineExtension()'s provides.models.
export const ttsModels = defineModels({
id: "my-service-tts",
name: "My Service Text-to-Speech",
family: "tts",
runtime: ttsCapability,
});Métadonnées du modèle
| Champ | Type | Obligatoire | Description |
|---|---|---|---|
id | string | oui | Identifiant unique du modèle (ex. "tts-hd") |
name | string | oui | Nom d'affichage dans l'interface |
voices | number | non | Nombre de préréglages de voix disponibles |
benchmarks | BenchmarkScore[] | non | Scores MOS — plus élevé est mieux |
Le benchmark TTS standard est le MOS (Mean Opinion Score, 1–5) — plus élevé est mieux. voices indique à l'interface combien de préréglages de voix afficher.