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

# Text-to-Speech

> Convert text to natural-sounding speech

## Overview

60db's Text-to-Speech (TTS) API converts written text into natural-sounding speech using advanced AI models. Our TTS engine supports multiple voices, languages, and customization options.

## Features

<CardGroup cols={2}>
  <Card title="Multiple Voices" icon="users">
    Choose from 50+ pre-built voices or create custom voices
  </Card>

  <Card title="Voice Customization" icon="sliders">
    Adjust speed, pitch, and other parameters
  </Card>

  <Card title="High Quality" icon="star">
    Crystal-clear audio with natural intonation
  </Card>

  <Card title="Multiple Formats" icon="file-audio">
    Support for MP3, WAV, OGG, and FLAC output formats
  </Card>
</CardGroup>

## Basic Usage

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={null}
    import { SixtyDBClient } from '60db';

    const client = new SixtyDBClient('your-api-key');

    const audio = await client.textToSpeech({
      text: 'Hello, world!',
      voice_id: 'default-voice',
      enhance: true,
      speed: 1.0
    });
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    from sixtydb import SixtyDBClient

    client = SixtyDBClient('your-api-key')

    audio = client.text_to_speech(
        text='Hello, world!',
        voice_id='default-voice',
        enhance=True,
        speed=1.0
    )

    with open('output.mp3', 'wb') as f:
        f.write(audio)
    ```
  </Tab>
</Tabs>

## Voice Parameters

### Speed

Control the speaking rate of the generated audio:

```javascript theme={null}
const audio = await client.textToSpeech({
  text: 'This will be spoken faster',
  speed: 1.5  // Range: 0.5 to 2.0
});
```

* `0.5`: Half speed (slow)
* `1.0`: Normal speed (default)
* `2.0`: Double speed (fast)

### Pitch

Adjust the pitch of the voice:

```javascript theme={null}
const audio = await client.textToSpeech({
  text: 'This will have a higher pitch',
  pitch: 1.3  // Range: 0.5 to 2.0
});
```

### Enhancement

Enable audio enhancement for better quality:

```javascript theme={null}
const audio = await client.textToSpeech({
  text: 'Enhanced audio quality',
  enhance: true  // Default: true
});
```

## Output Formats

Supported audio formats:

| Format | Quality   | File Size | Use Case              |
| ------ | --------- | --------- | --------------------- |
| MP3    | Good      | Small     | Web, mobile apps      |
| WAV    | Excellent | Large     | Professional audio    |
| OGG    | Good      | Small     | Web streaming         |
| FLAC   | Lossless  | Medium    | High-quality archival |

```javascript theme={null}
const audio = await client.textToSpeech({
  text: 'Hello, world!',
  output_format: 'wav'  // mp3, wav, ogg, flac
});
```

## Best Practices

<AccordionGroup>
  <Accordion title="Text Formatting">
    * Use proper punctuation for natural pauses
    * Break long texts into paragraphs
    * Use SSML tags for advanced control (coming soon)
  </Accordion>

  <Accordion title="Voice Selection">
    * Test multiple voices for your use case
    * Consider accent and gender for your audience
    * Use custom voices for brand consistency
  </Accordion>

  <Accordion title="Performance">
    * Cache frequently used audio
    * Batch requests when possible
    * Use appropriate audio format for your use case
  </Accordion>

  <Accordion title="Quality">
    * Enable enhancement for production use
    * Use WAV format for highest quality
    * Test with different speed settings
  </Accordion>
</AccordionGroup>

## Use Cases

### Voice Assistants

```javascript theme={null}
// Voice assistant
async function speakResponse(text) {
  const audio = await client.textToSpeech({
    text: text,
    voice_id: 'assistant-voice',
    enhance: true
  });

  playAudio(audio);
}
```

### Content Narration

```javascript theme={null}
// Generate audiobook chapter
const audio = await client.textToSpeech({
  text: chapterText,
  voice_id: 'narrator-voice',
  speed: 0.95,
  output_format: 'mp3'
});

saveToFile(`chapter-${chapterNum}.mp3`, audio);
```

### Accessibility

```javascript theme={null}
// Make web content accessible
async function readAloud(element) {
  const text = element.textContent;
  const audio = await client.textToSpeech({
    text,
    voice_id: 'clear-voice',
    enhance: true
  });
  
  playAudio(audio);
}
```

## API Reference

For detailed API documentation, see:

<Card title="Text to Speech" icon="microphone" href="/api-reference/tts/text-to-speech">
  Standard TTS endpoint
</Card>
