# Speech and calls

Read text aloud, transcribe a recording or live audio as it is spoken, place an outbound phone call, and run long transcription or meeting-notes jobs, with the real request shapes and status codes.

Source: https://docs.omazy.ai/reference/core-api/speech-and-calls/

Five things your server can do with a voice, behind three scopes.

| You want | Route | Scope | Answers |
|---|---|---|---|
| Text read aloud | `POST /voice/speak` | `voice:speech` | `200` with audio |
| A short recording as text | `POST /voice/transcribe` | `voice:speech` | `200` with JSON |
| Live audio as text, while it is spoken | `GET /voice/transcribe/stream` | `voice:speech` | A WebSocket |
| A phone call placed | `POST /voice/calls` | `voice:calls` | `202`, outcome later |
| A long recording transcribed, or notes written | `POST /voice/jobs` | `voice:tasks` | `202`, result later |

The scopes are separate on purpose. Being allowed to turn text into audio says
nothing about being allowed to ring somebody's phone.

## Read text aloud

```
POST /voice/speak
```

```sh
curl https://mw.omazy.ai/api/v1/core/voice/speak \
  -H "Authorization: Bearer $OMAZY_CORE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "text": "Your order has shipped and arrives on Thursday." }' \
  --output reply.wav
```

| Field | Type | Notes |
|---|---|---|
| `text` | string | Required. At most `2000` characters. |
| `lang` | string | A language code such as `en` or `bn`. Left out, it is read from the text: Bangla script is spoken as Bangla, anything else as English. |
| `app` | string | The app's handle. Needed only when the workspace has more than one app. |

The text is spoken in the app's own voice, the one set under
[Voice](/how-to/voice/changing-voice/). Markdown and links are cleaned out
before it is read, so you can pass a reply as your agent wrote it.

**The response is not JSON.** On success the body is the audio itself:

| | |
|---|---|
| Status | `200` |
| `Content-Type` | `audio/wav` |
| Body | WAV, 16-bit PCM, mono, `24000` Hz |
| `X-Omazy-Speech-Lang` | The language that was spoken |

On failure the response is the usual JSON error envelope, so check the status
before you treat the body as sound.

## Transcribe a recording

```
POST /voice/transcribe
```

The request body is the audio file itself, not JSON and not a form upload.

```sh
curl "https://mw.omazy.ai/api/v1/core/voice/transcribe?lang=en" \
  -H "Authorization: Bearer $OMAZY_CORE_TOKEN" \
  --data-binary @question.webm
```

| Parameter | Where | Notes |
|---|---|---|
| The audio | Body | Required. At most `8` MB (`8388608` bytes). |
| `lang` | Query | `en` or `bn`: which to expect first. Other values are ignored. |
| `terms` | Query | Names and words to expect, such as your staff's names or your brand. Comma-separated, or repeat the parameter. At most `200` terms of at most `100` bytes each; more is `400`, never cut short. |
| `app` | Query | The app's handle. Needed only when the workspace has more than one app. |

Send `terms` whenever names matter. Without them "Rashed Karim" can come back
"Rasht Kareem"; with them it comes back right.

```sh
curl "https://mw.omazy.ai/api/v1/core/voice/transcribe?lang=en&terms=Rashed%20Karim,Betopia" \
  -H "Authorization: Bearer $OMAZY_CORE_TOKEN" \
  --data-binary @question.wav
```

A finished clip in WebM, Ogg or WAV works. The format is detected from the
audio, so no `Content-Type` is needed.

```json
{
  "success": true,
  "data": { "text": "Where is my order?", "language": "en" }
}
```

This route is for a clip somebody just recorded. It answers once the whole
clip has been heard, about 4 seconds for a 5 second clip. To have the text
about 0.3 seconds after the person stops speaking, stream the audio while they
speak: see [Transcribe live audio](#transcribe-live-audio). For an hour of
audio, use a [voice job](#long-recordings-and-meeting-notes).

## Transcribe live audio

```
GET /voice/transcribe/stream
```

A WebSocket. Open it when the person starts speaking (or when a conversation
starts), send their audio while they speak, and read the words as they are
heard. Measured on production from Dhaka, the text arrives 0.27 to 0.45
seconds after the last audio, the same as calling the speech vendor directly.

Open the socket from your server, with your token on the upgrade request, the
same `Authorization: Bearer` header as every Core call. Never send the token to
a browser or an app: they stream to your own backend, and it relays to this
route.

```js
// Node 22 or later, Bun or Deno. In a Cloudflare Worker, open it with
// fetch(url, { headers: { Upgrade: 'websocket', Authorization } }).
const ws = new WebSocket('wss://mw.omazy.ai/api/v1/core/voice/transcribe/stream', {
  headers: { Authorization: `Bearer ${process.env.OMAZY_CORE_TOKEN}` },
})
ws.onopen = () => {
  ws.send(JSON.stringify({
    type: 'start', language: 'en', terms: ['Rashed Karim'],
    audio_format: 'pcm_s16le', sample_rate: 16000,
  }))
  // then ws.send(chunk) for each piece of audio, as it is captured
}
ws.onmessage = (e) => console.log(JSON.parse(e.data))
// when the person stops: ws.send(JSON.stringify({ type: 'end' }))
```

The client libraries get it in their next release, 0.4.0, as
`voice.transcribeStream` (TypeScript), `voice.transcribe_stream` (Python) and
`Voice.TranscribeStream` (Go).

### What you send

The first frame is text, the start frame:

| Field | Type | Notes |
|---|---|---|
| `type` | string | Required. `start`. |
| `language` | string | `en` or `bn`: which to expect first. The other is still heard. |
| `terms` | string[] | Names and words to expect. At most `200` of at most `100` bytes each. |
| `audio_format` | string | `auto` (the default), `pcm_s16le`, `mulaw` or `alaw`. `auto` is a WebM/Opus, Ogg or WAV stream, which names its own rate. |
| `sample_rate` | integer | Required for raw audio: `8000` to `48000`. |
| `num_channels` | integer | `1` (the default) or `2`, for raw audio. |

Then send the audio as binary frames, in real time, each at most 256 KB. 20 to
100 ms of audio per frame is right. You do not have to wait for `ready`: audio
sent before it is kept and heard in order.

Three text frames control the session:

| Frame | Means |
|---|---|
| `{"type":"commit"}` | The person stopped (they let go of the button). Answer what was said and keep the session open. |
| `{"type":"keepalive"}` | Still here, no audio for now. |
| `{"type":"end"}` | No more audio. Answer and close. |

### What you receive

| Frame | When |
|---|---|
| `{"type":"ready","request_id":…}` | The recognizer is up. |
| `{"type":"partial","text":…,"language":…}` | As words are heard: the utterance so far. Show it, do not keep it. |
| `{"type":"final","text":…,"language":…}` | An utterance ended: the person paused, or you sent `commit`. Keep it. The one that answers a `commit` has `"committed": true`, and it is sent even when its text is empty, so you never wait for nothing. |
| `{"type":"done","text":…,"language":…,"audio_ms":…,"request_id":…}` | After `end`: every final joined, and the length of audio heard. The socket then closes with `1000`. |
| `{"type":"error","code":…,"message":…,"request_id":…}` | Something went wrong. The socket then closes. |

| Error `code` | Close | Means |
|---|---|---|
| `BAD_REQUEST` | `1008` | The start frame was missing or wrong. The message says which field. |
| `UPSTREAM_UNAVAILABLE` | `1011` | Speech recognition could not be reached, or stopped. Try again, or send the clip to `POST /voice/transcribe`. |
| `UPSTREAM_REJECTED` | `1011` | The recognizer ended the session. |

A frame larger than 256 KB closes the socket with `1009` and no error frame.

Before the upgrade, the usual errors answer as HTTP: `401` without a valid
token, `403` without `voice:speech`, `402 PLAN_LIMIT_REACHED` when the plan's
voice minutes are used up, `429` past the rate limit, and `426` for a request
that is not a WebSocket upgrade.

### One session for a conversation

A session is counted once, when it closes: its length of audio, rounded up to
whole voice minutes, with a minimum of one. So hold one session open for a
whole conversation and send `commit` each time the person stops, rather than
opening one per sentence. A session that sends nothing for `60` seconds is
closed, so send `keepalive` every 20 to 30 seconds while nobody speaks. A
session ends as if you had sent `end` after 30 minutes.

### What speech costs

Speaking and transcribing are recorded against your workspace as voice minutes,
the same unit a phone call uses. Each request, or each live session, is rounded
up to a whole minute, with a minimum of one.

That minimum changes how you should call it. Ten sentences sent as ten requests
count as ten minutes. The same ten sentences in one request count as one. Send
a whole reply at a time.

The minutes come out of your plan's allowance for the period. When it is used
up, speech, voice jobs and call placement answer `402 PLAN_LIMIT_REACHED`. See
[Your plan's voice minutes](/reference/core-api/errors-and-limits/#your-plans-voice-minutes).

Both routes have `60` seconds to answer.

## Place a phone call

```
POST /voice/calls
```

Your agent rings somebody and holds the conversation. Scope: `voice:calls`.

An outbound call made by software is the fastest way to lose a customer's
trust, a phone carrier, or both. So this route does not dial on demand. It
accepts a request to call, checks it against a set of rules, and places the
call when the rules allow. The rules are enforced by the server, not left to
your good intentions.

```sh
curl https://mw.omazy.ai/api/v1/core/voice/calls \
  -H "Authorization: Bearer $OMAZY_CORE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "to": "+447700900123",
    "purpose": "confirmation",
    "consent_basis": "transaction",
    "opening": "Hello, this is Nordwell calling about your delivery tomorrow.",
    "goal": "Confirm that someone will be home between 10am and 2pm.",
    "callback_url": "https://api.example.com/hooks/omazy-call"
  }'
```

### Request

| Field | Type | Notes |
|---|---|---|
| `to` | string | Required. The number to call, in E.164 form, such as `+447700900123`. |
| `purpose` | string | Required. Why you are calling. See the rules below. |
| `consent_basis` | string | Required. Why you are allowed to. See the rules below. |
| `opening` | string | The first thing the agent says. At most `500` bytes. |
| `goal` | string | What the call should achieve. At most `500` bytes. |
| `script_id` | string | The id of a published call script, used in place of `opening` and `goal`. |
| `script` | object | A one-off script with questions. At most `16` KB. See below. |
| `variables` | object | String values that fill `{{name}}` gaps in a script. At most `32` keys. |
| `from` | string | The number to call from, in E.164 form. It must be an active number on the app. |
| `tz` | string | The person's time zone, such as `America/Chicago`. |
| `lang` | string | The language of the call. |
| `not_before` | string | An RFC 3339 time. No attempt is made before it. |
| `not_after` | string | An RFC 3339 time. The call expires if it has not been placed by then. |
| `max_attempts` | integer | How many times to try. Capped, see below. |
| `callback_url` | string | An `https` URL that receives the outcome. |
| `fallback` | string | `sms` or `none`. What to do when every attempt fails. |
| `consent_ref` | string | Your own reference for the consent, kept on the record. |
| `contact_ref` | string | Your own id for the person. It comes back in the outcome. |
| `app` | string | The app's handle. Needed only when the workspace has more than one app. |

Give the call something to say: a `script_id`, a `script`, or an `opening` and
`goal`. With only one of `opening` and `goal`, the other is taken from it.

`fallback` also accepts `whatsapp` and `task`. Neither does anything today.
Only `sms` acts: after the last failed attempt, the person is sent a text from
the same number.

### The rules

A request that breaks one is refused with `400 BAD_REQUEST`, and the message
names the rule.

**Purpose.** One of `confirmation`, `reminder`, `survey`, `collection`,
`callback` or `notification`. Marketing calls are refused by name. Outbound
calls here are for something the person already has with you.

**Consent.** One of `requested`, `transaction`, `relationship` or `explicit`,
and it has to fit the purpose.

| Purpose | Accepted consent |
|---|---|
| `callback` | `requested` only: the person asked to be called |
| `confirmation`, `reminder` | `transaction`, `requested` or `explicit` |
| `survey`, `collection`, `notification` | Any of the four |

**Calling hours.** Calls are placed between 09:00 and 20:00 in the person's own
time zone, and never on a Bangladesh public holiday for a `+880` number. A
request made at midnight is accepted and held until morning.

**Time zone.** For `+880` and `+44` numbers the zone is known from the number.
For every other country you must send `tz`. A person whose time zone is
unknown is not called at all, because there is no way to keep the hours.

**Caller ID.** The call comes from a phone number your app holds. Left out,
`from` is the app's first number. An app with no active number cannot place
calls.

**Do-not-call list.** The workspace's list is checked when you ask and again
immediately before dialling. A listed number is never rung.

**Attempts.** Two at most, or three for `survey` and `collection`. A higher
`max_attempts` is lowered to the cap. An unanswered call is tried again `90`
minutes later.

**Premium numbers.** Premium-rate and short-code ranges are never dialled.

### Response

`202 Accepted`. The call has been recorded, not placed.

```json
{
  "success": true,
  "data": {
    "ref": "7d3b0d2a-51a5-4f0b-8b56-3d0f3f7a9c21",
    "from": "+442079460018",
    "to": "+447700900123",
    "status": "pending",
    "next_attempt_at": "2026-11-20T09:00:00Z"
  }
}
```

Keep `ref`. It is how you ask about the call later, and it is what the outcome
is keyed by.

A number on the do-not-call list is not an error. The request is accepted with
`"status": "suppressed"`, so your records show why nothing happened.

### Placing a call once

If the answer does not reach you, you cannot tell whether the call was
recorded. Sending the request again would record a second one. Send an
`Idempotency-Key` header with the request, and a repeat with the same key
returns the first answer, with the same `ref`, and places nothing:

```http
Idempotency-Key: delivery-48213-confirm
```

See [Sending a request again](/reference/core-api/errors-and-limits/#sending-a-request-again).

### Reading the outcome

```
GET /voice/calls/{ref}
```

```json
{
  "success": true,
  "data": {
    "ref": "7d3b0d2a-51a5-4f0b-8b56-3d0f3f7a9c21",
    "status": "done",
    "outcome": "answered",
    "disposition": "answered",
    "attempts": 1,
    "max_attempts": 2,
    "result": {}
  }
}
```

| `status` | Meaning |
|---|---|
| `pending` | Waiting for its next attempt. `next_attempt_at` says when, `last_error` says why it is waiting. |
| `dialling` | Being placed. |
| `in_call` | Ringing or in progress. |
| `done` | The person answered. |
| `failed` | Every attempt was used, or the call could not be placed. |
| `suppressed` | The number is on the do-not-call list. |
| `expired` | `not_after` passed before the call could be placed. |
| `cancelled` | Somebody in the workspace cancelled it in the console while it was still waiting. |

On a `done` call, `outcome` is `completed` when every required question was
answered, `partial` when some were, and `answered` when the call had no
questions to record. On a `failed` call it is how the last attempt ended, such
as `no_answer` or `busy`.

`result` holds the answers the agent recorded, keyed by question id. It is an
empty object until there are any.

A `pending` call whose `last_error` reads `outbound calling is not configured`
has passed every rule and is waiting on the phone carrier side. It is tried
again each hour. If it stays that way, tell us.

There is no route to cancel a call from this API. Use `not_after` to bound how
long a request stays alive.

When the workspace has more than one app, add `?app=` with the handle. An
unknown `ref`, or one that belongs to another app, answers `404`.

### Getting the outcome pushed to you

Send a `callback_url` and Omazy posts the outcome to it when the call is
settled. This one is from a call that ran the survey script further down:

```json
{
  "ref": "7d3b0d2a-51a5-4f0b-8b56-3d0f3f7a9c21",
  "status": "done",
  "outcome": "completed",
  "attempts": 1,
  "result": { "on_time": true, "rating": 5 },
  "disposition": "answered",
  "contact_ref": "customer-4410"
}
```

The request carries an `X-Omazy-Signature` header: `sha256=` followed by the
hex HMAC-SHA256 of the raw request body, keyed with your app's callback signing
key. Verify it before you believe the body.

```ts
import { createHmac, timingSafeEqual } from 'node:crypto'

export function isFromOmazy(rawBody: string, header: string | undefined, signingKey: string) {
  const expected = 'sha256=' + createHmac('sha256', signingKey).update(rawBody).digest('hex')
  const got = Buffer.from(header ?? '')
  const want = Buffer.from(expected)
  return got.length === want.length && timingSafeEqual(got, want)
}
```

Compute it over the bytes you received, before any JSON parsing.

Two honest limits. The Core API has no route that returns the signing key, so
ask for it when your token is issued. And the callback is sent once, with a
`10` second timeout and no retry. Treat it as a prompt to act, and keep
`GET /voice/calls/{ref}` as the source of truth for anything you cannot afford
to miss.

### A script with questions

An `opening` and a `goal` are enough for a simple call. When you need specific
answers back, send a `script`. The agent asks each question, checks the answer
against its type, and records it under the question's `id`.

```json
{
  "to": "+447700900123",
  "purpose": "survey",
  "consent_basis": "relationship",
  "script": {
    "opening": "Hello {{name}}, this is Nordwell. Do you have a minute for two questions about your delivery?",
    "goal": "Find out how the delivery went.",
    "questions": [
      { "id": "on_time", "ask": "Did it arrive on time?", "type": "yes_no", "required": true },
      { "id": "rating", "ask": "Out of five, how would you rate it?", "type": "rating", "min": 1, "max": 5 }
    ],
    "voicemail": "Hello {{name}}, Nordwell here. We will try you again later."
  },
  "variables": { "name": "Sam" }
}
```

A question's `type` is one of `yes_no`, `choice`, `rating`, `number`, `date` or
`text`. A `choice` needs at least two `options`. A `rating` needs `min` and
`max`, with `max` no higher than `10`. A script holds at most `12` questions,
and each `id` is lower case letters, digits and underscores.

Four more fields are there when a script needs them.

| Field | On | Does |
|---|---|---|
| `when` | A question | Asks the question only if an earlier answer matches, written as `"on_time == no"` or `"rating != 5"`. It must name a question that comes before it |
| `dtmf` | A question | Lets the person answer on the keypad. Each key is one digit, `*` or `#`, and maps to the answer it stands for: `{ "1": "yes", "2": "no" }` |
| `closing` | The script | What the agent says before hanging up. `default` is the usual line. A line keyed by the first question's answer (`yes` or `no` for a yes or no question) is said in its place when that was the answer |
| `lang` | The script | The language code the call is spoken in |

```json
"questions": [
  { "id": "on_time", "ask": "Did it arrive on time? Press 1 for yes, 2 for no.", "type": "yes_no", "required": true, "dtmf": { "1": "yes", "2": "no" } },
  { "id": "what_happened", "ask": "Sorry to hear that. What happened?", "type": "text", "when": "on_time == no" }
],
"closing": { "default": "Thank you. Goodbye.", "no": "Thank you. Someone will call you about it today." }
```

## Long recordings and meeting notes

```
POST /voice/jobs
GET  /voice/jobs/{id}
```

Scope: `voice:tasks`. A voice job takes a recording and returns a transcript
with speakers and timestamps, or meeting notes written from one. It needs no
agent and no phone number.

```sh
curl https://mw.omazy.ai/api/v1/core/voice/jobs \
  -H "Authorization: Bearer $OMAZY_CORE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "kind": "meeting_notes",
    "source_url": "https://files.example.com/standup-tuesday.mp3",
    "template": "standup",
    "diarize": true
  }'
```

| Field | Type | Notes |
|---|---|---|
| `kind` | string | Required. `transcribe` or `meeting_notes`. |
| `source_url` | string | An `https` URL of the recording, reachable from the public internet. |
| `source_call_id` | string | The id of a call in this workspace, used in place of `source_url`. |
| `lang` | array | Languages to expect, such as `["en"]`. Default `["en", "bn"]`. |
| `diarize` | boolean | Label who is speaking. |
| `template` | string | For notes: `general`, `standup`, `client_call`, `interview` or `board`. Default `general`. |
| `callback_url` | string | An `https` URL that receives the finished job. |

Give exactly one source. The app can be named with `?app=` in the URL or as
`app` in the body of the `POST`. The URL wins when both are there. Reading a
job takes `?app=`.

`POST /voice/jobs` takes an
[`Idempotency-Key`](/reference/core-api/errors-and-limits/#sending-a-request-again),
so a request sent twice starts one job.

The answer is `202 Accepted` with the job, in status `queued`. Read it back with
its `id`:

```json
{
  "success": true,
  "data": {
    "id": "b7f5a7a0-4f0b-4d53-9a3e-6f0a3f1c2d44",
    "kind": "meeting_notes",
    "status": "done",
    "source_url": "https://files.example.com/standup-tuesday.mp3",
    "options": { "lang": ["en", "bn"], "diarize": true, "template": "standup", "keep_source": false },
    "audio_seconds": 912,
    "attempts": 1,
    "result": {
      "transcript": {
        "text": "Morning. Yesterday I finished the export fix.",
        "segments": [
          { "speaker": "1", "start_ms": 0, "end_ms": 4200, "text": "Morning. Yesterday I finished the export fix." }
        ],
        "duration_ms": 912000
      },
      "notes": {
        "summary": "The export fix is done. The release moves to Thursday.",
        "decisions": ["Release on Thursday"],
        "action_items": [{ "item": "Write the release note", "owner": "Sam", "due": "Wednesday" }],
        "open_questions": []
      }
    }
  }
}
```

The job also carries `workspace_id`, `app_id`, `created_at`, `started_at` and
`finished_at`.

| `status` | Meaning |
|---|---|
| `queued` | Accepted, not started. |
| `running` | Being transcribed. |
| `done` | `result` is filled. |
| `failed` | `error` says why, in a sentence. |

A `transcribe` job fills `result.transcript`. A `meeting_notes` job fills
`result.notes`, and `result.transcript` as well when the notes were written
from audio. A job that has not finished within four hours fails.

With a `callback_url`, the finished job is posted to it as the same JSON object
you would read back, signed with `X-Omazy-Signature` in the same way as a call
outcome. Voice jobs are signed with a workspace-wide key, not the per-app key
calls use. The same caution applies: it is sent once, so poll for anything you
must not miss.

The audio is recorded against your workspace as voice minutes, rounded up.
