> ## Documentation Index
> Fetch the complete documentation index at: https://docs.60db.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# JavaScript/TypeScript SDK

> Complete guide to the 60db JavaScript/TypeScript SDK

## Installation

```bash theme={null}
npm install 60db
```

## Initialization

```typescript theme={null}
import { SixtyDBClient } from "60db";

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

## Text-to-Speech

### Basic TTS

```typescript theme={null}
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
```

## Speech-to-Text

### Transcribe Audio

```typescript theme={null}
const file = document.querySelector('input[type="file"]').files[0];

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

console.log(result.text);
```

### With Context Refinement

Supply a `context` string to enable server-side LLM polishing — proper nouns, filler removal, and punctuation are cleaned on the response text:

```typescript theme={null}
const result = await client.speechToText(file, {
  language: "hi",
  diarize: true,
  context:
    "Cricket coaching session. Players: Arjun Mehta, Ishaan Verma. Discussing batting technique.",
});
```

Omit `context` entirely to skip refinement. Note: this is the REST shape — the WebSocket streaming endpoint takes a `{general, text, terms}` object instead.

### Get Supported Languages

```typescript theme={null}
const languages = await client.getLanguages();
console.log(languages);
```

## Voice Management

### List All Voices

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

### Get Specific Voice

```typescript theme={null}
const voice = await client.getVoice("voice-id");
console.log(voice);
```

### Create Custom Voice

```typescript theme={null}
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

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

### Delete Voice

```typescript theme={null}
await client.deleteVoice("voice-id");
```

## Authentication

### Sign Up

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

### Sign In

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

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

### Get Profile

```typescript theme={null}
const profile = await client.getProfile();
console.log(profile);
```

### Update Profile

```typescript theme={null}
await client.updateProfile({
  name: "Jane Doe",
  company: "Acme Inc",
});
```

## Workspace Management

### List Workspaces

```typescript theme={null}
const workspaces = await client.getWorkspaces();
```

### Create Workspace

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

## Billing

### Get Available Plans

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

### Get Current Plan

```typescript theme={null}
const currentPlan = await client.getCurrentPlan();
console.log("Current plan:", currentPlan.name);
```

### Subscribe to Plan

```typescript theme={null}
await client.subscribe("plan-id");
```

## Analytics

### Get Usage Statistics

```typescript theme={null}
const usage = await client.getUsage();
console.log("Characters used:", usage.characters);
console.log("API calls:", usage.api_calls);
```

## API Key Management

### List API Keys

```typescript theme={null}
const apiKeys = await client.getApiKeys();
```

### Create API Key

```typescript theme={null}
const newKey = await client.createApiKey("Production Key");
console.log("New API key:", newKey.key);
```

### Delete API Key

```typescript theme={null}
await client.deleteApiKey("key-id");
```

## Webhooks

### List Webhooks

```typescript theme={null}
const webhooks = await client.getWebhooks();
```

### Create Webhook

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

### Delete Webhook

```typescript theme={null}
await client.deleteWebhook("webhook-id");
```

## Error Handling

```typescript theme={null}
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:

```typescript theme={null}
import { SixtyDBClient, SixtyDBConfig, TTSResponse } from "60db";
```
