# Transcribe a voice note

> Turn the diner's voice note into text, with the menu's dish names as hints, before sending it as a message.

Source: https://tamr.link/docs/api/transcribe

`POST https://tamr.link/api/v1/transcribe`

A voice note of up to 30 seconds and 2 MB, as `multipart/form-data`, comes back as text (with the menu's dish names as hints) for the app to send as the diner's message. It takes `audio/webm`, `audio/mp4`, `audio/ogg`, `audio/mpeg`, `audio/wav` and `audio/x-m4a`.

## Authentication

**Client API.** Send your publishable key in `x-tamr-key` and the diner's session in `x-tamr-session`, from [Start a session](https://tamr.link/docs/api/start-session). For a guest's session, also send its device id in `x-tamr-device`. A browser may call it only from an origin listed on the key.

## Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `x-tamr-device` | string | No | Guest sessions only: the device id the session was exchanged with. Matches `^[A-Za-z0-9_-]{8,128}$`. |
| `x-tamr-app` | string | No | Native apps only: the app's iOS bundle id or Android package name. A key used from an app it doesn't list is logged, never refused. Matches `^[A-Za-z][A-Za-z0-9_-]*(\.[A-Za-z0-9_-]+)+$`. |

## Request body

Send it as `multipart/form-data`, the recording in `audio`.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `branch` | string | No | An address: lower-case letters, digits and dashes. |
| `mode` | string | No | One of `dine_in`, `pickup`, `delivery`. |
| `audio` | file | Yes |  |
| `durationMs` | integer | No | 0 to 30,000. |

## Response

| Field | Type | Description |
| --- | --- | --- |
| `text` | string |  |
| `language` | string or null | At most 35 characters. |
| `seconds` | number |  |

## Example

curl:

```bash
curl -X POST https://tamr.link/api/v1/transcribe \
  -H "x-tamr-key: $TAMR_APP_KEY" \
  -H "x-tamr-session: $TAMR_SESSION" \
  -F "audio=@note.webm;type=audio/webm"
```

Node:

```js
import { readFile } from "node:fs/promises";
import { createClient } from "@tamr/api";

const tamr = createClient({ appKey: process.env.TAMR_APP_KEY });
// Sign the diner in first, with a token your backend signed (or a launch code).
await tamr.startSession({ token: dinerToken });

const form = new FormData();
form.append("audio", new Blob([await readFile("note.webm")], { type: "audio/webm" }), "note.webm");

const result = await tamr.transcribe(form);
console.log(result.text);
```

Python:

```python
import os

import requests

API = "https://tamr.link/api/v1"
headers = {
    "x-tamr-key": os.environ["TAMR_APP_KEY"],
    "x-tamr-session": os.environ["TAMR_SESSION"],  # from POST /api/v1/sdk/session
}

response = requests.post(
    f"{API}/transcribe",
    headers=headers,
    files={"audio": ("note.webm", open("note.webm", "rb"), "audio/webm")},
    timeout=30,
)
response.raise_for_status()
print(response.json())
```

## Example response

```json
{
  "text": "Do you have anything vegan?",
  "language": "en",
  "seconds": 2.4
}
```

## Errors

Every error has the same body; switch on `data.code`. See [Errors and rate limits](https://tamr.link/docs/errors).

| `data.code` | Status | What to do |
| --- | --- | --- |
| `app_key_invalid` | 401 | The key is wrong, revoked or of another kind. Check it in the dashboard. |
| `sdk_disabled` | 403 | The SDK isn't switched on for this restaurant. Ask Tamr. |
| `origin_not_allowed` | 403 | A browser called from an origin the key doesn't list. Add the origin to the key. |
| `session_expired` | 401 | Start a new session with a fresh token or code, then send the call again once. |
| `invalid_request` | 400 | A field doesn't match the spec. The message says which. |
| `rate_limited` | 429 | Wait `retryAfter` seconds (also in the `Retry-After` header), then try again. |
| `nothing_heard` | 422 | A voice note with no words in it. Ask the diner to try again. |
| `menu_unavailable` | 404 | No published menu is served at that branch and service mode. |
| `unavailable` | 503 | Tamr can't serve this now. Try again later. |
