@inkibra/voice-sdk
v0.1.1
Published
Browser and server SDK for Inkibra Live Voice
Downloads
326
Readme
@inkibra/voice-sdk
The browser and server SDK for Inkibra Live Voice.
import LiveVoice from "@inkibra/voice-sdk";
const session = await LiveVoice.connect({
token,
prompt: "Help the user complete a concise inventory.",
conversation: {
starts: "assistant",
prompt: "Be concise and clarify uncertainty before moving on.",
},
tools: {
update_inventory: {
description: "Update an inventory item",
parameters: {
type: "object",
properties: { name: { type: "string" }, quantity: { type: "number" } },
required: ["name", "quantity"],
additionalProperties: false,
},
execute: async ({ name, quantity }) => updateInventory(String(name), Number(quantity)),
},
},
});
session.on("transcript.instantaneous", ({ text }) => console.log(text));
session.on("transcript.canonical", ({ turns }) => console.log(turns));
session.on("floor", ({ owner, assistantAudible }) => console.log(owner, assistantAudible));
session.on("assistant.energy", ({ current, predictions }) => {
animateAgent(current);
renderAssistantForecast(predictions);
});
session.on("phase", ({ phase, previousPhase }) => console.log(phase, previousPhase));
session.on("tool.call", ({ name, input }) => console.log(name, input));
session.on("error", console.error);
// Later:
session.stop();Create the short-lived browser token on your server. Never expose your Inkibra API key to the browser:
const response = await fetch("https://inkibra-voice.inkibra.workers.dev/v1/sessions", {
method: "POST",
headers: { authorization: `Bearer ${process.env.INKIBRA_API_KEY}`, "content-type": "application/json" },
body: JSON.stringify({ voice: "ara" }),
});
const { token } = await response.json();Server media
Telephone and calling-provider adapters use the server entry point. The adapter supplies PCM16LE mono audio at 24 kHz and maps Inkibra output commands to its provider playback queue.
import LiveVoice from "@inkibra/voice-sdk/server";
const session = await LiveVoice.connect({
apiKey: process.env.INKIBRA_API_KEY!,
audio: providerAudioTransport,
voice: "ara",
prompt: "Help callers schedule an appointment.",
conversation: { starts: "assistant" },
tools: {},
});
await session.closed;The Durable Object remains the sole owner of conversation state. The server audio transport owns only codec conversion and transient provider playback.
