# Audio

> Text-to-speech and transcription (Whisper) endpoints for generating audio from text and converting audio files to text.

- Canonical: https://tchavi.com/en/docs/audio

---


Tchavi supports two audio endpoints: text-to-speech (TTS) for generating audio from text, and transcription (Whisper) for converting audio files to text.

## Text-to-Speech

<Endpoint method="POST" path="/v1/audio/speech" />

Converts text to spoken audio. Returns raw audio bytes.

| Parameter         | Type   | Required | Description                                                                     |
| ----------------- | ------ | -------- | ------------------------------------------------------------------------------- |
| `model`           | string | Yes      | "tts-1" (faster) or "tts-1-hd" (higher quality)                                 |
| `input`           | string | Yes      | The text to convert to speech (max 4096 characters)                             |
| `voice`           | string | Yes      | alloy, ash, ballad, cedar, coral, echo, fable, marin, nova, onyx, sage, shimmer |
| `response_format` | string | No       | mp3, opus, aac, flac, wav, pcm. Default: mp3                                    |
| `speed`           | number | No       | Playback speed 0.25–4.0. Default: 1.0                                           |

<CodeTabs>

```tchavi
import Tchavi from '@tchavi/sdk';
import { writeFileSync } from 'fs';

const client = new Tchavi({ apiKey: 'YOUR_API_KEY' });

const response = await client.audio.speech.create({
  model: 'tts-1',
  input: 'Tchavi is the best AI API gateway in Africa.',
  voice: 'nova',
  response_format: 'mp3',
});

const buffer = Buffer.from(await response.arrayBuffer());
writeFileSync('speech.mp3', buffer);
```

```javascript
const response = await fetch('https://tchavi.com/api/v1/audio/speech', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    Authorization: 'Bearer YOUR_API_KEY',
  },
  body: JSON.stringify({
    model: 'tts-1',
    input: 'Tchavi is the best AI API gateway in Africa.',
    voice: 'nova',
    response_format: 'mp3',
  }),
});

const buffer = await response.arrayBuffer();
// Save or play the audio buffer
```

```python
import requests

response = requests.post(
    "https://tchavi.com/api/v1/audio/speech",
    headers={
        "Content-Type": "application/json",
        "Authorization": "Bearer YOUR_API_KEY",
    },
    json={
        "model": "tts-1",
        "input": "Tchavi is the best AI API gateway in Africa.",
        "voice": "nova",
        "response_format": "mp3",
    },
)

with open("speech.mp3", "wb") as f:
    f.write(response.content)
```

```curl
curl -X POST https://tchavi.com/api/v1/audio/speech \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{
    "model": "tts-1",
    "input": "Tchavi is the best AI API gateway in Africa.",
    "voice": "nova"
  }' --output speech.mp3
```

</CodeTabs>

## Transcription (Whisper)

<Endpoint method="POST" path="/v1/audio/transcriptions" />

Transcribes audio files to text. Send as `multipart/form-data`.

| Parameter         | Type   | Required | Description                                                                                             |
| ----------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------- |
| `model`           | string | Yes      | "whisper-1"                                                                                             |
| `file`            | file   | Yes      | Audio file (mp3, wav, m4a, webm, ogg…). Max 25MB                                                        |
| `language`        | string | No       | ISO-639-1 code (e.g. "fr", "en"). Auto-detected if omitted                                              |
| `response_format` | string | No       | json, text, srt, vtt, verbose_json. Default: json                                                       |
| `prompt`          | string | No       | Optional text to guide the model's style or continue a previous segment. Must match the audio language. |
| `temperature`     | number | No       | Sampling temperature 0–1. Higher values yield more varied transcriptions. Default: 0                    |

<CodeTabs>

```tchavi
import Tchavi from '@tchavi/sdk';
import { createReadStream } from 'fs';

const client = new Tchavi({ apiKey: 'YOUR_API_KEY' });

const result = await client.audio.transcriptions.create({
  model: 'whisper-1',
  file: createReadStream('audio.mp3'),
  language: 'fr',
});

console.log(result.text);
console.log('Duration:', result.tchavi.duration_minutes, 'min');
console.log('Credits used:', result.tchavi.credits_used);
```

```javascript
const formData = new FormData();
formData.append('model', 'whisper-1');
formData.append('file', audioFile); // File or Blob
formData.append('language', 'fr');

const response = await fetch('https://tchavi.com/api/v1/audio/transcriptions', {
  method: 'POST',
  headers: { Authorization: 'Bearer YOUR_API_KEY' },
  body: formData,
});

const data = await response.json();
console.log(data.text);
```

```python
import requests

with open("audio.mp3", "rb") as f:
    response = requests.post(
        "https://tchavi.com/api/v1/audio/transcriptions",
        headers={"Authorization": "Bearer YOUR_API_KEY"},
        files={"file": ("audio.mp3", f, "audio/mpeg")},
        data={"model": "whisper-1", "language": "fr"},
    )

data = response.json()
print(data["text"])
```

```curl
curl -X POST https://tchavi.com/api/v1/audio/transcriptions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "model=whisper-1" \
  -F "file=@audio.mp3" \
  -F "language=fr"
```

</CodeTabs>

