# Transcribe an audio file

`POST https://api.morevoice.ai/v1/speech/transcriptions`

Transcribes a short audio file, such as a WhatsApp voice note: OGG/Opus, WebM/Opus, WAV, MP3 or MP4/AAC, up to 16 MB and 10 minutes, as multipart/form-data (a `file` part) or as JSON with the file base64. Billed per started second of audio; audio with no speech (422 `no_speech`), audio over `max_duration_sec` (422 `audio_too_long`) and unsupported files (415 `unsupported_audio`) are not billed. The audio is processed in memory and not stored. With an `Idempotency-Key`, a retry within 24 hours returns the first result and is not billed again. Test-mode keys get a fixed sample transcript in the requested language (after the same format and length checks) and are never billed.

Authenticate with a secret API key: `Authorization: Bearer $MOREVOICE_API_KEY`.

Operation ID: `speech_transcribe`.

## Parameters

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `MoreVoice-Version` | `string` | no | The API version to use for this request. Defaults to the version the API key is pinned to. |
| `Idempotency-Key` | `string` | no | A unique key (for example a UUID) that makes this request safe to retry: for 24 hours, a retry with the same key and parameters returns the first response instead of acting twice. |

## Request body

Required, `application/json` or `multipart/form-data`.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `file` | `object` | yes | The audio: OGG/Opus (a WhatsApp voice note), WebM/Opus, WAV, MP3 or MP4/AAC. JSON requests send it base64; multipart/form-data requests send a `file` part. |
| `file.content_base64` | `string` | yes | The audio file, base64 (up to 16 MB decoded). |
| `file.content_type` | `string` | no | The file's media type, e.g. `audio/ogg`. Informational: the format is read from the file itself. |
| `file.filename` | `string` | no | — |
| `language` | `string` | no | The language spoken, as a hint (`he`, `en`, …). Without it the language is detected among the platform's default languages. |
| `max_duration_sec` | `integer` | no | The longest audio to accept, in seconds (default and maximum 600). Longer audio is refused with 422 `audio_too_long` and nothing is billed. |
| `purpose` | `"voice_note"` | no | What the audio is (`voice_note`); informational. |

Example:

```json
{
  "file": {
    "content_base64": "T2dnUwACAAAAAAAAAAA=",
    "content_type": "audio/ogg",
    "filename": "note.ogg"
  },
  "language": "he",
  "max_duration_sec": 180,
  "purpose": "voice_note"
}
```

## Responses

### 200 OK

The transcript. Returns `Transcription`.

| Field | Type | Description |
| --- | --- | --- |
| `id` | `string` | This transcription's ID (prefix `stx_`); quote it to support. The result is kept only to replay an `Idempotency-Key` retry (24 hours). |
| `object` | `"speech.transcription"` | — |
| `livemode` | `boolean` | `true` in live mode, `false` in test mode. |
| `text` | `string` | What was said. |
| `language` | `string \| null` | The language of the transcript: the hint when one was sent, else the detected language (null when none was detected). |
| `duration_sec` | `number` | The audio's length in seconds. Billed per started second. |

Example:

```json
{
  "duration_sec": 4.36,
  "id": "stx_4Gk2LmN9pQ4rS6tV8wX0yZ",
  "language": "he",
  "livemode": true,
  "object": "speech.transcription",
  "text": "היי, רציתי לבדוק אם ההזמנה שלי כבר יצאה."
}
```

### 400 Bad Request

The request is invalid: a parameter is missing, malformed or unknown, or the version header is unknown. Returns `ErrorEnvelope`.

### 401 Unauthorized

No valid API key was sent. Returns `ErrorEnvelope`.

### 403 Forbidden

The key may not do this (a missing scope, a plan limit, or a compliance block). Returns `ErrorEnvelope`.

### 404 Not Found

No object with this ID (in the path or the body) exists in this organisation and mode. Returns `ErrorEnvelope`.

### 409 Conflict

The request conflicts with the object's state, or the Idempotency-Key was reused with other parameters. Returns `ErrorEnvelope`.

### 413 Payload Too Large

The request body is larger than the endpoint accepts, or has more parts or files than it takes. Returns `ErrorEnvelope`.

### 415 Unsupported Media Type

The request body's Content-Type is not one the endpoint takes. Returns `ErrorEnvelope`.

### 422 Unprocessable Entity

The request is well formed, but its content can't be processed: for example audio longer than allowed, audio with no speech, or text over the length limit. Returns `ErrorEnvelope`.

### 429 Too Many Requests

Too many requests, or no call capacity right now. Retry after the Retry-After delay. Returns `ErrorEnvelope`.

### 500 Internal Server Error

Something went wrong on MoreVoice's side. Retry with the same Idempotency-Key. Returns `ErrorEnvelope`.

### 503 Service Unavailable

A dependency this endpoint needs (a speech or language model, file storage) is temporarily unavailable. Retry later. Returns `ErrorEnvelope`.

## Code samples

**TypeScript**

```ts
import MoreVoice from "@morevoice/sdk";

const mv = new MoreVoice(); // MOREVOICE_API_KEY from the environment

const transcription = await mv.speech.transcribe({
	file: {
		content_base64: "T2dnUwACAAAAAAAAAAA=",
		content_type: "audio/ogg",
		filename: "note.ogg",
	},
	language: "he",
	max_duration_sec: 180,
	purpose: "voice_note",
});
console.log(transcription);
```

**Python**

```python
from morevoice import MoreVoice

client = MoreVoice()  # MOREVOICE_API_KEY from the environment

transcription = client.speech.transcribe({
    "file": {
        "content_base64": "T2dnUwACAAAAAAAAAAA=",
        "content_type": "audio/ogg",
        "filename": "note.ogg",
    },
    "language": "he",
    "max_duration_sec": 180,
    "purpose": "voice_note",
})
print(transcription)
```

**cURL**

```sh
curl -X POST https://api.morevoice.ai/v1/speech/transcriptions \
  -H "Authorization: Bearer $MOREVOICE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
  "file": {
    "content_base64": "T2dnUwACAAAAAAAAAAA=",
    "content_type": "audio/ogg",
    "filename": "note.ogg"
  },
  "language": "he",
  "max_duration_sec": 180,
  "purpose": "voice_note"
}'
```
