const ws = new WebSocket("wss://api.vachana.ai/api/v1/tts", {
headers: {
"Content-Type": "application/json",
"X-API-Key-ID": "<your-api-key>",
},
});
ws.on("open", () => {
const request = {
text: "नमस्ते, आप कैसे हैं?",
model: "vachana-vc-v1",
audio_config: {
sample_rate: 44100,
encoding: "linear_pcm",
},
speaker_embedding: {
embedding: "<your-embedding-string>",
shape: [1, 768],
dtype: "torch.bfloat16",
},
};
ws.send(JSON.stringify(request));
});
ws.on("message", (data) => {
// Handle audio chunks
console.log("Received audio chunk:", data);
});
ws.on("error", (error) => {
console.error("WebSocket error:", error);
});
ws.on("close", () => {
console.log("WebSocket connection closed");
});