Skip to main content

Installation

npm install 60db

Initialization

import { SixtyDBClient } from "60db";

// Simple initialization
const client = new SixtyDBClient("your-api-key");

Text-to-Speech

Basic TTS

const audio = await client.textToSpeech({
  text: 'Hello, world!',
  voice_id: 'default-voice',
  enhance: true,
  speed: 1.0,
  language:"en-us"
});

### Get all voices
const voices = await client.getVoices();

### Get all lanuages
const lanuages = await client.getLanguages();

### audio is an ArrayBuffer containing the audio data

Streaming TTS

await client.textToSpeechStream(
  {
    text: "This is a longer text that will be streamed",
    voice_id: "default-voice",
  },
  {
    onChunk: (chunk: Uint8Array) => {
      // Process audio chunk
      console.log("Received chunk:", chunk.length, "bytes");
    },
    onComplete: () => {
      console.log("Streaming complete");
    },
    onError: (error: string) => {
      console.error("Error:", error);
    },
  },
);

Speech-to-Text

Transcribe Audio

const file = document.querySelector('input[type="file"]').files[0];

const result = await client.speechToText(file, {
  language: "en",
});

console.log(result.text);

Get Supported Languages

const languages = await client.getLanguages();
console.log(languages);

Voice Management

List All Voices

const voices = await client.getVoices();
voices.forEach((voice) => {
  console.log(`${voice.name} (${voice.id})`);
});

Get Specific Voice

const voice = await client.getVoice("voice-id");
console.log(voice);

Create Custom Voice

const files = [file1, file2, file3]; // File objects

const newVoice = await client.createVoice({
  name: "My Custom Voice",
  files: files,
  description: "A custom voice for my brand",
});

console.log("Created voice:", newVoice.id);

Update Voice

await client.updateVoice("voice-id", {
  name: "Updated Voice Name",
  description: "Updated description",
});

Delete Voice

await client.deleteVoice("voice-id");

Authentication

Sign Up

const user = await client.signUp({
  email: "user@example.com",
  password: "secure-password",
  name: "John Doe",
});

Sign In

const session = await client.signIn({
  email: "user@example.com",
  password: "secure-password",
});

console.log("Token:", session.token);

Get Profile

const profile = await client.getProfile();
console.log(profile);

Update Profile

await client.updateProfile({
  name: "Jane Doe",
  company: "Acme Inc",
});

Workspace Management

List Workspaces

const workspaces = await client.getWorkspaces();

Create Workspace

const workspace = await client.createWorkspace({
  name: "My Workspace",
  description: "Team workspace",
});

Billing

Get Available Plans

const plans = await client.getPlans();
plans.forEach((plan) => {
  console.log(`${plan.name}: $${plan.price}/month`);
});

Get Current Plan

const currentPlan = await client.getCurrentPlan();
console.log("Current plan:", currentPlan.name);

Subscribe to Plan

await client.subscribe("plan-id");

Analytics

Get Usage Statistics

const usage = await client.getUsage();
console.log("Characters used:", usage.characters);
console.log("API calls:", usage.api_calls);

API Key Management

List API Keys

const apiKeys = await client.getApiKeys();

Create API Key

const newKey = await client.createApiKey("Production Key");
console.log("New API key:", newKey.key);

Delete API Key

await client.deleteApiKey("key-id");

Webhooks

List Webhooks

const webhooks = await client.getWebhooks();

Create Webhook

const webhook = await client.createWebhook({
  url: "https://example.com/webhook",
  events: ["tts.completed", "stt.completed"],
});

Delete Webhook

await client.deleteWebhook("webhook-id");

Error Handling

try {
  const audio = await client.textToSpeech({
    text: "Hello, world!",
    voice_id: "invalid-voice",
  });
} catch (error) {
  if (error.response) {
    // API error
    console.error("API Error:", error.response.status);
    console.error("Message:", error.response.data.message);
  } else {
    // Network or other error
    console.error("Error:", error.message);
  }
}

TypeScript Types

The SDK includes full TypeScript type definitions:
import { SixtyDBClient, SixtyDBConfig, TTSResponse } from "@60db-own/60db-js";