Skip to main content

Installation

npm install @destined-ai/voice

Quick Start

import { SDK } from "@destined-ai/voice";

const client = new SDK({
  bearerToken: process.env.DESTINED_API_KEY,
});

// List speakers
const speakers = await client.speakers.listSpeakersV1SpeakersGet({
  gender: "Female",
  limit: 10,
});

// Generate speech
const audio = await client.ttsGeneration.synthesizeSpeechV1TtsSynthesizePost({
  speakerId: speakers[0].id,
  text: "Hello from Destined Voice!",
});

console.log(audio.audioUrl);

Available Namespaces

NamespaceDescription
client.healthAPI health checks
client.speakersBrowse and filter speakers
client.ttsGenerationGenerate TTS audio
client.jobsTrack batch job progress
client.sttTestingSTT provider testing
client.datasetsCSV dataset import
client.usersUser profile and usage
client.billingSubscription management

Configuration

import { SDK } from "@destined-ai/voice";

const client = new SDK({
  // Required: Your API key
  bearerToken: process.env.DESTINED_API_KEY,

  // Optional: Override base URL (default: https://api.destined.ai)
  serverURL: "https://api.destined.ai",

  // Optional: Custom fetch implementation
  httpClient: customFetch,
});

Error Handling

import { SDK } from "@destined-ai/voice";
import { SDKError } from "@destined-ai/voice/models/errors";

const client = new SDK({
  bearerToken: process.env.DESTINED_API_KEY,
});

try {
  const result = await client.ttsGeneration.synthesizeSpeechV1TtsSynthesizePost({
    speakerId: "invalid-id",
    text: "Hello",
  });
} catch (error) {
  if (error instanceof SDKError) {
    console.log("Status:", error.statusCode);
    console.log("Message:", error.message);
    console.log("Body:", error.body);
  }
}

TypeScript Types

All request/response types are exported:
import type {
  SpeakerResponse,
  SynthesizeRequest,
  JobStatus,
} from "@destined-ai/voice/models";

const request: SynthesizeRequest = {
  speakerId: "abc123",
  text: "Hello world",
};

Next.js Usage

// app/api/synthesize/route.ts
import { SDK } from "@destined-ai/voice";
import { NextResponse } from "next/server";

const client = new SDK({
  bearerToken: process.env.DESTINED_API_KEY!,
});

export async function POST(request: Request) {
  const { speakerId, text } = await request.json();

  const result = await client.ttsGeneration.synthesizeSpeechV1TtsSynthesizePost({
    speakerId,
    text,
  });

  return NextResponse.json(result);
}

React Hook Example

import { useState, useCallback } from "react";
import { SDK } from "@destined-ai/voice";

const client = new SDK({
  bearerToken: process.env.NEXT_PUBLIC_DESTINED_API_KEY!,
});

export function useSynthesis() {
  const [loading, setLoading] = useState(false);
  const [error, setError] = useState<Error | null>(null);

  const synthesize = useCallback(async (speakerId: string, text: string) => {
    setLoading(true);
    setError(null);

    try {
      const result = await client.ttsGeneration.synthesizeSpeechV1TtsSynthesizePost({
        speakerId,
        text,
      });
      return result;
    } catch (e) {
      setError(e as Error);
      throw e;
    } finally {
      setLoading(false);
    }
  }, []);

  return { synthesize, loading, error };
}