Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions api-reference/asyncapi-asr-realtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ channels:
type: string
enum:
- transcribe-stream-1
- transcribe-stream-2
default: transcribe-stream-1
description: Realtime speech-to-text model. Optional; `transcribe-stream-1` (Preview) is the default and the only realtime model. The legacy name `transcribe-1-pro-realtime` reaches the same model.
description: Realtime speech-to-text model. Optional; `transcribe-stream-1` (Preview) is the default. Without the header, or with any other value, the session runs on `transcribe-stream-1`. `session_started.config.model` names the session's model.
description: |
Realtime speech-to-text channel. Clients stream audio and receive
transcripts turn by turn, with turn detection, optional live drafts and
Expand All @@ -102,6 +103,7 @@ channels:
## Connection Headers
- `Authorization: Bearer <api_key>` - Required for authentication (see security section)
- `model: transcribe-stream-1` (Preview) - Optional; the default
- `model: transcribe-stream-2` - Optional; the only model that takes `results.text_format`

Every message in both directions is one MessagePack map in a binary
frame, with a `type` field. Send `config` first, wait for
Expand Down Expand Up @@ -477,7 +479,7 @@ components:
description: Same as the `x-request-id` response header. Include it when you contact support.
config:
type: object
description: The effective configuration, with defaults filled in.
description: The effective configuration, with defaults filled in. `model` names the session's model.
limits:
$ref: "#/components/schemas/AsrLimits"
description: |
Expand Down Expand Up @@ -1180,6 +1182,21 @@ components:
type: boolean
default: true
description: Sound tags such as `[laughter]` in the text; `false` removes them. Only `true` or `false`.
text_format:
oneOf:
- type: string
enum:
- spoken
- written
- type: "null"
default: spoken
description: |
`transcribe-stream-2` only; choose it in `config`, for the
whole session. The style for numbers, amounts and times:
`spoken` (words, the way they were said) or `written` (digits
and symbols). `null` is the same as leaving it out.
`transcribe-stream-1` refuses this field, whatever its value,
`null` included, with `invalid_config`.
vad_events:
type: boolean
default: false
Expand Down
56 changes: 42 additions & 14 deletions api-reference/endpoint/websocket/asr-realtime.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
asyncapi: "/api-reference/asyncapi-asr-realtime.yml asrRealtime"

Check warning on line 2 in api-reference/endpoint/websocket/asr-realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

api-reference/endpoint/websocket/asr-realtime.mdx#L2

Did you really mean 'asrRealtime'?
title: "WebSocket Realtime Speech to Text"

Check warning on line 3 in api-reference/endpoint/websocket/asr-realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

api-reference/endpoint/websocket/asr-realtime.mdx#L3

Did you really mean 'Realtime'?
description: "Stream audio over a WebSocket and receive transcripts turn by turn, with turn detection, live drafts and conversation context"
icon: "webhook"
iconType: "solid"
Expand All @@ -11,7 +11,7 @@
Connect to `wss://api.fish.audio/v1/asr/realtime` with a WebSocket client.
Every message in both directions is one MessagePack map in a binary frame. A
normal HTTP GET request does not start a session. For an introduction, see
[Realtime Speech to Text](/features/speech-to-text/realtime).

Check warning on line 14 in api-reference/endpoint/websocket/asr-realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

api-reference/endpoint/websocket/asr-realtime.mdx#L14

Did you really mean 'Realtime'?
</Note>

<Note>`transcribe-stream-1` is in preview.</Note>
Expand All @@ -20,7 +20,7 @@

You need a [Fish Audio API key](/developer-guide/getting-started/api-key) and a WebSocket client that can set request headers. The API key travels in a request header, so connect from your server, not from a browser; to capture audio in a browser, relay it through your server as in [Transcribe a live audio stream](/developer-guide/sdk-guide/cookbook/realtime-transcription#capture-from-a-browser-microphone). The examples on these pages use Python with `websockets` and `msgpack`, and Node.js with `ws` and `@msgpack/msgpack`.

This endpoint is separate from the realtime endpoints of the [compatible APIs](/developer-guide/compat/capabilities), which use manual commit and have no server-side turn detection.

Check warning on line 23 in api-reference/endpoint/websocket/asr-realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

api-reference/endpoint/websocket/asr-realtime.mdx#L23

Did you really mean 'realtime'?

## Connect

Expand All @@ -30,14 +30,14 @@
model: transcribe-stream-1
```

| Header | Required | Description |
| --------------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `Authorization` | Yes | `Bearer <API key>`. Write the scheme exactly as `Bearer`, followed by a space and the key. |
| `model` | No | `transcribe-stream-1` (Preview), the default and the only realtime model. The legacy name `transcribe-1-pro-realtime` reaches the same model. |
| Header | Required | Description |
| --------------- | -------- | ------------------------------------------------------------------------------------------------------------------ |
| `Authorization` | Yes | `Bearer <API key>`. Write the scheme exactly as `Bearer`, followed by a space and the key. |
| `model` | No | The realtime model: `transcribe-stream-1` (Preview), the default, or `transcribe-stream-2`. See [Models](#models). |

Check warning on line 36 in api-reference/endpoint/websocket/asr-realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

api-reference/endpoint/websocket/asr-realtime.mdx#L36

Did you really mean 'realtime'?

Each open connection counts against the same concurrency limit as your other API requests, from the moment it opens until it closes, even while you send no audio. See [Concurrent request limits](/developer-guide/models-pricing/pricing-and-rate-limits#concurrent-request-limits). A session cannot be resumed: a new connection is a new session.

Sessions are billed per second of session duration, as Realtime ASR. See [ASR pricing](/developer-guide/models-pricing/pricing-and-rate-limits#automatic-speech-recognition-asr-models).
Sessions are billed per second of session duration, as Realtime ASR, at the price of the session's model. See [ASR pricing](/developer-guide/models-pricing/pricing-and-rate-limits#automatic-speech-recognition-asr-models).

Check warning on line 40 in api-reference/endpoint/websocket/asr-realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

api-reference/endpoint/websocket/asr-realtime.mdx#L40

Did you really mean 'Realtime'?

If the server refuses the upgrade, it answers with a plain HTTP response whose JSON body is `{"status": <int>, "message": <str>}`:

Expand All @@ -45,11 +45,22 @@
| ------ | ----------------------------------------------------------------------------------------------- | ----------------------------------------------------- |
| 401 | The API key is missing or invalid, or the `Authorization` header does not start with `Bearer `. | Check the key and the header. |
| 402 | Insufficient API credit. | Top up your balance. |
| 429 | Your team is at its concurrency limit, or the service is at capacity. | Retry with backoff. Honor `Retry-After` when present. |

Check warning on line 48 in api-reference/endpoint/websocket/asr-realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

api-reference/endpoint/websocket/asr-realtime.mdx#L48

Did you really mean 'backoff'?
| 503 | The service is restarting. | Retry. |

The `101 Switching Protocols` response carries an `x-request-id` header, and so do the capacity 429 and 503 refusals. It is the same value as `request_id` in `session_started`, `error` and `session_done`. Log it, and include it when you contact support. Refusals for the key, balance and your concurrency limit (401, 402 and concurrency 429) happen before a session is assigned and carry no `x-request-id`.

### Models

| Model | Price | Notes |
| ------------------------------- | -------------------- | ----------------------------------------------------------------------------- |
| `transcribe-stream-1` (Preview) | $0.36 / session hour | The default. |
| `transcribe-stream-2` | $0.12 / session hour | Takes [`results.text_format`](#text-format), the style for numbers and times. |

Both models use this endpoint and the protocol on this page: the same messages, turn detection modes, errors and limits. The one difference is `results.text_format`, which only `transcribe-stream-2` takes.

Choose the model with the `model` header, written exactly as shown. A connection without the header, or with any other value, gets a `transcribe-stream-1` session, billed as `transcribe-stream-1`, and no error is returned. `session_started.config.model` names the model that serves the session.

## Framing

- Every message is **one binary WebSocket frame holding one MessagePack map** with a `type` field. Audio bytes are MessagePack `bin`. Do not send text frames. JSON is not accepted, in text frames or in binary frames.
Expand Down Expand Up @@ -92,13 +103,13 @@
{
"type": "config",
"audio": { "format": "pcm_s16le", "sample_rate": 16000, "channels": 1 },
"turn_detection": { "mode": "auto", "eager": true },

Check warning on line 106 in api-reference/endpoint/websocket/asr-realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

api-reference/endpoint/websocket/asr-realtime.mdx#L106

Did you really mean 'turn_detection'?
"results": { "drafts": true, "ignore_timestamps": false },
"context": {
"history": [{ "role": "assistant", "text": "Hi, how can I help?" }],
"terms": ["Fish Audio", "transcribe-stream-1"]
},
"client_reference_id": "call-8f2c"

Check warning on line 112 in api-reference/endpoint/websocket/asr-realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

api-reference/endpoint/websocket/asr-realtime.mdx#L112

Did you really mean 'client_reference_id'?
}
```

Expand All @@ -115,13 +126,14 @@
| `results.ignore_timestamps` | No | `true` | `false` adds word timings (`words`) to `committed`. |
| `results.diarize` | No | `true` | `true`, `false` or `"auto"` (same as `true`); the strings `"true"` and `"false"` are accepted too. `false` removes speaker tags from the text. See [Speakers](#speakers). |
| `results.tag_audio_events` | No | `true` | `false` removes sound tags such as `[laughter]` from the text. See [Sound tags](#sound-tags). |
| `results.text_format` | No | `"spoken"` | `transcribe-stream-2` only. The style for numbers, amounts and times: `"spoken"` (words) or `"written"` (digits and symbols). See [Text format](#text-format). |
| `results.vad_events` | No | `false` | `true` sends [`vad`](#vad) messages. |
| `results.eot_events` | No | `false` | `true` sends [`eot_prob`](#eot_prob) messages. |
| `context.history` | No | `[]` | Earlier conversation, oldest first: up to 32 items of `{ "role": "user" \| "assistant", "text": str }`, each up to 2,000 characters. |
| `context.terms` | No | `[]` | Up to 100 terms of up to 32 characters each: names, products and jargon to recognize. |
| `client_reference_id` | No | | Your own ID for the session, up to 256 characters. It is recorded with the session and not sent back. |

A value of the wrong type for `ignore_timestamps` or `tag_audio_events` (both take only `true` or `false`), or a `diarize` value other than those listed, is `invalid_config`. So is an unknown field, including a misspelled one; the error's `message` names the field. `invalid_config` closes the connection with 4400. Send only the fields listed here: not every other field is refused, so check `session_started.config`, which shows the settings in effect.
A value of the wrong type for `ignore_timestamps` or `tag_audio_events` (both take only `true` or `false`), a `diarize` value other than those listed, or a `text_format` other than `"spoken"`, `"written"` or `null`, is `invalid_config`. So is an unknown field, including a misspelled one; the error's `message` names the field. `invalid_config` closes the connection with 4400. Send only the fields listed here: not every other field is refused, so check `session_started.config`, which shows the settings in effect.

#### Audio format

Expand Down Expand Up @@ -175,7 +187,7 @@

Audio in the format from `config`. `data` must be MessagePack `bin` holding the raw PCM bytes. Do not base64-encode the audio, and do not send it as a string or an array of numbers. If you do, you receive a recoverable `invalid_request`, and those messages are dropped: nothing in them is transcribed or counted as received audio.

Send audio after `session_started` (see [`config`](#config) for audio sent earlier). For live audio, send it as it is captured, 20–40 ms per message (see [Audio format](#audio-format)). If your client batches small writes (Nagle's algorithm), turn that off with `TCP_NODELAY`; browsers and common WebSocket libraries already send each message right away. You can send faster than real time, for example from a file: the server accepts it and reads it at a bounded rate, and results keep following the audio.

Check warning on line 190 in api-reference/endpoint/websocket/asr-realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

api-reference/endpoint/websocket/asr-realtime.mdx#L190

Did you really mean 'Nagle's'?

### `finalize`

Expand All @@ -198,7 +210,7 @@
}
```

Change settings during the session. `turn_detection`, `results` and `context` take the same values as in `config`; every field is optional, and a field you leave out keeps its current value. `context` accepts `terms` only, and the new list replaces the old one; send earlier lines with [`context_add`](#context_add). The server answers with [`configured`](#configured). If any value is invalid, nothing in the message is applied.
Change settings during the session. `turn_detection`, `results` and `context` take the same values as in `config`, except `results.text_format`, which is set in `config` for the whole session. Every field is optional, and a field you leave out keeps its current value. `context` accepts `terms` only, and the new list replaces the old one; send earlier lines with [`context_add`](#context_add). The server answers with [`configured`](#configured). If any value is invalid, nothing in the message is applied.

`audio` is fixed for the session: to change the audio format, open a new session. A `configure` with an unknown field, with an `audio` that differs from the session's, or with `context.history` gets `configured` with `ok: false`, and nothing in it is applied. An `audio` identical to the session's is accepted. As with `config`, send only the fields listed here; `configured.config` shows the settings in effect.

Expand Down Expand Up @@ -258,12 +270,12 @@

### `session_started`

| Field | Type | Description |
| ------------ | ------ | --------------------------------------------------------------------------------- |
| `session_id` | string | The session's ID. |
| `request_id` | string | The same value as the `x-request-id` header. Include it when you contact support. |
| `config` | map | The effective configuration, with defaults filled in. |
| `limits` | map | `max_session_ms`, `max_turn_ms` and `max_frame_bytes`. See [Limits](#limits). |
| Field | Type | Description |
| ------------ | ------ | ----------------------------------------------------------------------------------------------- |
| `session_id` | string | The session's ID. |
| `request_id` | string | The same value as the `x-request-id` header. Include it when you contact support. |
| `config` | map | The effective configuration, with defaults filled in. `config.model` names the session's model. |
| `limits` | map | `max_session_ms`, `max_turn_ms` and `max_frame_bytes`. See [Limits](#limits). |

Send audio after this message.

Expand Down Expand Up @@ -333,7 +345,7 @@
| `turn_index` | integer | The open turn, or, if no turn is open, the index the next turn will get. |
| `audio_ms` | integer | Where the acknowledgement is in the audio. |

`auto` mode only, while your agent is speaking (see [`agent_speaking`](#agent_speaking)): the user acknowledged ("mm-hm", "yeah", "right") without taking the turn. Keep talking. One message per acknowledgement. It always comes before the named turn's `committed`, and it can come before that turn's `speech_start`. A backchannel counts for the turn that contains it; that turn commits with `user_turn: false` and `turn_kind: "backchannel"` unless the user goes on to take the turn. A turn that opened in `vad` or `manual` mode never counts an acknowledgement. When your agent is not speaking, an acknowledgement takes the turn (`user_turn_taken`).

Check warning on line 348 in api-reference/endpoint/websocket/asr-realtime.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

api-reference/endpoint/websocket/asr-realtime.mdx#L348

Did you really mean 'backchannel'?

### `committed`

Expand Down Expand Up @@ -453,6 +465,22 @@

Speaker tags still depend on `diarize` alone. A turn that holds only tags still gets its `committed`, without a language, and with a `text` that is empty with `diarize: false`, or holds only the turn's speaker tags with `diarize` on.

## Text format

With `transcribe-stream-2`, `results.text_format` sets the style for numbers, amounts, times and similar in the transcript:

| Value | Style | Example |
| -------------------- | ----------------------------- | ----------------------------------------------- |
| `"spoken"` (default) | Words, the way they were said | "I paid twenty five dollars at three thirty pm" |
| `"written"` | Digits and symbols | "I paid $25 at 3:30 pm" |

- Choose it in `config`, for the whole session.
- It applies to `draft`, `eager_end_of_turn` and `committed` alike.
- `session_started.config.results` shows the value in effect. `null` is the same as not sending the field.
- Any other value, such as another string (`"Written"` included), a number or a boolean, is `invalid_config`, which closes the connection with 4400. The message is `results.text_format must be "spoken" or "written"`.

Only `transcribe-stream-2` takes `text_format`. `transcribe-stream-1` refuses a `config` that sends it, whatever its value, `null` included, with `invalid_config` and close 4400; the error's `message` names the field. With `transcribe-stream-1`, `session_started.config.results` and `configured` have no `text_format`.

## Language

`draft`, `eager_end_of_turn` and `committed` carry the language of their own `text`. Use `language_code` (ISO 639-1) in your code; `language` is its English name, for display, with the same names as [`POST /v1/asr`](/api-reference/endpoint/openapi-v1/speech-to-text). The language is detected from that message's text alone, ignoring speaker tags, sound tags in `[` and `]`, and interjections such as "okay", "hmm" or "uh". With `tag_audio_events: false`, the label can also reflect text that is not shown: the rest of a draft after an unclosed opening bracket, the inside of a tag that holds another tag, or a tag in full-width or lenticular brackets. It is one of:
Expand Down Expand Up @@ -543,7 +571,7 @@

## Related

- [Realtime Speech to Text](/features/speech-to-text/realtime): what the realtime model does and when to use it.
- [Realtime Speech to Text](/features/speech-to-text/realtime): what the realtime models do and when to use them.
- [Transcribe a live audio stream](/developer-guide/sdk-guide/cookbook/realtime-transcription): a complete client in Python and Node.js, and a browser microphone relay.
- [Build a realtime voice agent](/developer-guide/sdk-guide/cookbook/realtime-voice-agent): turn-taking, barge-in and backchannels.
- [Speech to Text](/api-reference/endpoint/openapi-v1/speech-to-text): transcribe a complete audio file with `POST /v1/asr`.
7 changes: 4 additions & 3 deletions developer-guide/models-pricing/pricing-and-rate-limits.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,12 @@
| --------------------------------------------- | -------------------- |
| `transcribe-1-pro` (recommended) | $0.36 / audio hour |
| `transcribe-1` | $0.36 / audio hour |
| `transcribe-stream-1` (Realtime ASR, Preview) | $0.36 / session hour |

Check warning on line 52 in developer-guide/models-pricing/pricing-and-rate-limits.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

developer-guide/models-pricing/pricing-and-rate-limits.mdx#L52

Did you really mean 'Realtime'?
| `transcribe-stream-2` (Realtime ASR) | $0.12 / session hour |

Check warning on line 53 in developer-guide/models-pricing/pricing-and-rate-limits.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

developer-guide/models-pricing/pricing-and-rate-limits.mdx#L53

Did you really mean 'Realtime'?

For recordings, we recommend `transcribe-1-pro`, which handles multi-speaker conversations (speaker markers and speaker turns), long recordings, and inline emotion cues. Both file models cost the same and use the [Speech to Text API](/api-reference/endpoint/openapi-v1/speech-to-text). Send the `model: transcribe-1-pro` HTTP header to select Pro; a request whose `model` header is missing or not an exact match is served and billed as `transcribe-1`. See the [model comparison](/features/speech-to-text#choose-an-asr-model).

`transcribe-stream-1` transcribes live audio over the [realtime WebSocket](/features/speech-to-text/realtime) and is billed as its own line item, Realtime ASR, separate from file transcription.
`transcribe-stream-1` and `transcribe-stream-2` transcribe live audio over the [realtime WebSocket](/features/speech-to-text/realtime) and are billed as their own line item, Realtime ASR, separate from file transcription. Send the `model: transcribe-stream-2` header to select `transcribe-stream-2`; a connection whose `model` header is missing or not an exact match is served and billed as `transcribe-stream-1`.

Check warning on line 57 in developer-guide/models-pricing/pricing-and-rate-limits.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

developer-guide/models-pricing/pricing-and-rate-limits.mdx#L57

Did you really mean 'Realtime'?

**How ASR billing works for files (`transcribe-1-pro`, `transcribe-1`):**

Expand All @@ -62,9 +63,9 @@
- The full duration of the recording is billed, including silence, once per successful request
- Requests that return an error response are not billed

**How Realtime ASR billing works (`transcribe-stream-1`):**
**How Realtime ASR billing works (`transcribe-stream-1`, `transcribe-stream-2`):**

Check warning on line 66 in developer-guide/models-pricing/pricing-and-rate-limits.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

developer-guide/models-pricing/pricing-and-rate-limits.mdx#L66

Did you really mean 'Realtime'?

- Charges are based on session duration, billed per second, once per session
- Charges are based on session duration, billed per second at the price of the session's model, once per session
- Session duration is the time the connection is open, or the duration of the audio you send if that is longer, rounded up to the nearest second

### Voice Design
Expand Down Expand Up @@ -106,7 +107,7 @@

When you are at the limit, the [native API](/api-reference/introduction),
including `POST /v1/asr`, returns 429 without a `Retry-After` header. Retry
with exponential backoff.

Check warning on line 110 in developer-guide/models-pricing/pricing-and-rate-limits.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

developer-guide/models-pricing/pricing-and-rate-limits.mdx#L110

Did you really mean 'backoff'?

### Convert Concurrency to QPS or QPM

Expand Down Expand Up @@ -154,7 +155,7 @@
| AI companion short reply | 2 seconds | ~150 QPM | ~450 QPM | ~1,500 QPM |
| Voice-agent support turn | 4 seconds | ~75 QPM | ~225 QPM | ~750 QPM |
| Narration paragraph | 12 seconds | ~25 QPM | ~75 QPM | ~250 QPM |
| Audiobook or long-form synthesis | 60 seconds | ~5 QPM | ~15 QPM | ~50 QPM |

Check warning on line 158 in developer-guide/models-pricing/pricing-and-rate-limits.mdx

View check run for this annotation

Mintlify / Mintlify Validation (hanabiaiinc) - vale-spellcheck

developer-guide/models-pricing/pricing-and-rate-limits.mdx#L158

Did you really mean 'Audiobook'?

Treat these numbers as examples, not guarantees. Your actual QPS and QPM depend
on text length, model, reference audio, output format, network path, streaming
Expand Down
Loading
Loading