# Events as XML in the transcript

Last updated: 2026-11-19

**The problem.** Many integrations read one thing from the live API: the text of the transcripts. A voice agent
framework hands `utterance.text` to an LLM, a no-code tool copies it into a document, a plugin forwards it to a chat.
Everything else the session sends (the end of the turn, the translation, the entities, the sentiment) arrives as
other message types, and those integrations drop it.

**The fix.** Add `"xml_events": true` to the session's init. Every event that is not a transcript then arrives **as
a transcript**: a final `transcript` message whose `utterance.text` is one short XML tag holding the event's useful
keys. The transcripts themselves do not change. Read the text, and the events are in it:

```text
<speech_start time="1.02" channel="0"/>
Bonjour, je voudrais réserver une table pour deux.
<sentiment channel="0" start="1.02" end="3.84" sentiment="neutral" emotion="neutral"/>
<named_entities channel="0" start="1.02" end="3.84"><entity entity_type="CARDINAL" start="3.1" end="3.4">deux</entity></named_entities>
<translation from="fr" to="en" channel="0" start="1.02" end="3.84">Hello, I would like to book a table for two.</translation>
<speech_end time="3.84" channel="0"/>
<end_of_turn channel="0" probability="0.97" reason="model" end="3.84"/>
```

## At a glance

| | |
|---|---|
| Live API | `xml_events` |
| Pre-recorded (batch) | Live only |
| Live models | `solaria-3`, `trantoria-1` (every live model) |
| Languages | Every language of the model ([supported languages](/languages/supported-languages/)) |

## Turn it on

```json
{
  "encoding": "wav/pcm",
  "sample_rate": 16000,
  "bit_depth": 16,
  "channels": 1,
  "model": "solaria-3",
  "language_config": { "languages": ["fr"] },
  "realtime_processing": { "translation": true, "translation_config": { "target_languages": ["en"] } },
  "xml_events": true
}
```

With the SDKs, pass it with the other options. Nothing else changes in your code: the events reach your `message`
handler as transcripts. Each program streams a 16-bit WAV file and prints every final, speech and tags. Put your API
key in the `GLADIA_API_KEY` environment variable, then run `python xml_events.py call.wav`.

**Python SDK**

```python title="xml_events.py"
# pip install -U "gladiaio-sdk>=2.2"
import os
import sys
import threading
import wave

from gladiaio_sdk import GladiaClient

API_URL = os.environ.get("GLADIA_API_URL", "https://eu1.api.gladia.io")
API_KEY = os.environ["GLADIA_API_KEY"]

with wave.open(sys.argv[1]) as wav:  # a 16-bit PCM WAV file
    rate, channels = wav.getframerate(), wav.getnchannels()
    audio = wav.readframes(wav.getnframes())

config = {
    "encoding": "wav/pcm",
    "sample_rate": rate,
    "bit_depth": 16,
    "channels": channels,
    "model": "solaria-3",
    "language_config": {"languages": ["en"]},
    "messages_config": {"receive_speech_events": True},
    "xml_events": True,
}

client = GladiaClient(api_key=API_KEY, api_url=API_URL)
# a dict is sent as is: the Gladia Enterprise options included
session = client.live_v2().start_session(config)
ended, errors = threading.Event(), []

@session.on("message")
def on_message(message):
    if message.type == "transcript" and message.data.is_final:
        print(message.data.utterance.text)

session.on("error", errors.append)
session.once("ended", lambda _: ended.set())

# Stream once the socket is open: a stop sent while it opens can pass the audio queued until then.
connected = threading.Event()
session.once("connected", lambda _: connected.set())
session.once("ended", lambda _: connected.set())  # a session that never connects ends
session.on("error", lambda _: connected.set())
if session.status == "connected":  # it opened before the listener above
    connected.set()
if not connected.wait(timeout=30) or errors or ended.is_set():
    sys.exit(1)  # no open session to stream to

step = rate * channels * 2 // 10  # 100 ms of audio per chunk
for start in range(0, len(audio), step):
    session.send_audio(audio[start : start + step])  # live audio: send each chunk as it is captured
session.stop_recording()

ended.wait(timeout=60)
sys.exit(1 if errors or not ended.is_set() else 0)
```

**JavaScript SDK**

```js title="xml_events.mjs"
// npm install @gladiaio/sdk
import { readFileSync } from "node:fs";
import { GladiaClient } from "@gladiaio/sdk";

const { sampleRate, channels, pcm } = readWav(process.argv[2]); // a 16-bit PCM WAV file

const config = {
  encoding: "wav/pcm",
  sample_rate: sampleRate,
  bit_depth: 16,
  channels,
  model: "solaria-3",
  language_config: { languages: ["en"] },
  messages_config: { receive_speech_events: true },
  xml_events: true,
};

const client = new GladiaClient({
  apiKey: process.env.GLADIA_API_KEY,
  apiUrl: process.env.GLADIA_API_URL ?? "https://eu1.api.gladia.io",
});
const session = client.liveV2().startSession(config);

session.on("message", (message) => {
  if (message.type === "transcript" && message.data.is_final) console.log(message.data.utterance.text);
});
session.on("error", (error) => {
  console.error(error);
  process.exitCode = 1;
});
session.once("ended", () => process.exit());

const step = (sampleRate * channels * 2) / 10; // 100 ms of audio per chunk
for (let start = 0; start < pcm.length; start += step) {
  session.sendAudio(pcm.subarray(start, start + step)); // live audio: send each chunk as it is captured
}
session.stopRecording();

function readWav(path) {
  const file = readFileSync(path);
  let fmt, pcm;
  for (let pos = 12; pos < file.length; ) {
    const id = file.toString("ascii", pos, pos + 4);
    const size = file.readUInt32LE(pos + 4);
    if (id === "fmt ") fmt = { channels: file.readUInt16LE(pos + 10), sampleRate: file.readUInt32LE(pos + 12) };
    if (id === "data") pcm = file.subarray(pos + 8, pos + 8 + size);
    pos += 8 + size + (size % 2);
  }
  return { ...fmt, pcm };
}
```

**HTTP**

Create the session, then stream its audio to the returned `url` ([Live WebSocket](/api-reference/v2/live/websocket/)):

```bash
curl -X POST https://eu1.api.gladia.io/v2/live \
  -H "x-gladia-key: $GLADIA_API_KEY" \
  -H "content-type: application/json" \
  -d '{
    "encoding": "wav/pcm",
    "sample_rate": 16000,
    "bit_depth": 16,
    "channels": 1,
    "model": "solaria-3",
    "language_config": {
      "languages": [
        "en"
      ]
    },
    "messages_config": {
      "receive_speech_events": true
    },
    "xml_events": true
  }'
```

## What arrives on the WebSocket

An event becomes a final transcript with an id starting with `xml_`, the event's time as `start` and `end`, and no
words:

```json
{
  "type": "transcript",
  "session_id": "0199d7a2-5c3e-7b41-9f0a-3c2d1e4f5a6b",
  "created_at": "2026-11-06T15:02:11.402Z",
  "data": {
    "id": "xml_3f9a1c2e_00000007",
    "is_final": true,
    "utterance": {
      "text": "<end_of_turn channel=\"0\" probability=\"0.97\" reason=\"model\" end=\"3.84\"/>",
      "start": 3.84,
      "end": 3.84,
      "channel": 0,
      "language": "fr",
      "confidence": 1,
      "words": []
    }
  }
}
```

To tell an event from speech, look at the id (`xml_`) or at the first character of the text (`<`). To parse a tag,
any XML parser does: the attributes are the event's keys, the element's text is its main text.

```python
import xml.etree.ElementTree as ET

text = '<end_of_turn channel="0" probability="0.97" reason="model" end="3.84"/>'
tag = ET.fromstring(text)
print(tag.tag, tag.attrib)  # end_of_turn {'channel': '0', 'probability': '0.97', ...}
```

## Each event, JSON and XML

The JSON message the session sends without the option, then the tag it becomes with it. A key the tag does not keep
is in the JSON only; a key with no value is left out of the tag.

### speech_start, speech_end

```json title="speech_start"
{ "type": "speech_start", "session_id": "0199d7a2-5c3e-7b41-9f0a-3c2d1e4f5a6b", "created_at": "2026-11-06T15:02:09.100Z", "data": { "time": 1.02, "channel": 0 } }
```

```xml title="speech_start"
<speech_start time="1.02" channel="0"/>
```

```json title="speech_end"
{ "type": "speech_end", "session_id": "0199d7a2-5c3e-7b41-9f0a-3c2d1e4f5a6b", "created_at": "2026-11-06T15:02:11.900Z", "data": { "time": 3.84, "channel": 0 } }
```

```xml title="speech_end"
<speech_end time="3.84" channel="0"/>
```

### end_of_turn, turn_resumed

With `end_of_turn.speculation`, the text your agent starts on is the element's text: it arrives before the
final transcript of the turn.

```json title="end_of_turn"
{ "type": "end_of_turn", "session_id": "0199d7a2-5c3e-7b41-9f0a-3c2d1e4f5a6b", "data": { "channel": 0, "probability": 0.97, "reason": "model", "end": 3.84, "speech_duration": 3.1, "text": "book a table for two" } }
```

```xml title="end_of_turn"
<end_of_turn channel="0" probability="0.97" reason="model" end="3.84">book a table for two</end_of_turn>
```

```json title="turn_resumed"
{ "type": "turn_resumed", "session_id": "0199d7a2-5c3e-7b41-9f0a-3c2d1e4f5a6b", "data": { "channel": 0, "end": 4.62 } }
```

```xml title="turn_resumed"
<turn_resumed channel="0" end="4.62"/>
```

### eager_end_of_turn, hold

```json title="eager_end_of_turn"
{ "type": "eager_end_of_turn", "session_id": "0199d7a2-5c3e-7b41-9f0a-3c2d1e4f5a6b", "data": { "channel": 0, "probability": 0.71, "end": 3.6, "speech_duration": 2.9, "text": "book a table for two" } }
```

```xml title="eager_end_of_turn"
<eager_end_of_turn channel="0" probability="0.71" end="3.6">book a table for two</eager_end_of_turn>
```

```json title="hold"
{ "type": "hold", "session_id": "0199d7a2-5c3e-7b41-9f0a-3c2d1e4f5a6b", "data": { "channel": 0, "reason": "phone_in_progress", "listening": true, "end": 6.2, "end_of_turn_probability": 0.12, "inline": null } }
```

```xml title="hold"
<hold channel="0" reason="phone_in_progress" end="6.2" end_of_turn_probability="0.12"/>
```

### speculation

The text your agent started on is the element's text.

```json title="speculation"
{ "type": "speculation", "session_id": "0199d7a2-5c3e-7b41-9f0a-3c2d1e4f5a6b", "created_at": "2026-10-17T10:00:00.000Z", "error": null, "data": { "utterance_id": "00_00000003", "utterance": { "text": "Book a table for two.", "start": 1.0, "end": 4.0, "language": "en", "confidence": 0.9, "channel": 0, "words": [] }, "results": [{ "eager_text": "book a table for two", "eager_end": 4.18, "similarity": 1.0, "lexical_similarity": 1.0, "recommendation": "keep", "reason": "same_text" }] } }
```

```xml title="speculation"
<speculation recommendation="keep" reason="same_text" similarity="1.0" lexical_similarity="1.0" eager_end="4.18">book a table for two</speculation>
```

### translation

The translated text is the element's text; the source utterance is the transcript before it.

```json title="translation"
{ "type": "translation", "session_id": "0199d7a2-5c3e-7b41-9f0a-3c2d1e4f5a6b", "created_at": "2026-11-06T15:02:12.010Z", "error": null, "data": { "utterance_id": "00_00000003", "utterance": { "text": "Bonjour, je voudrais réserver une table pour deux.", "start": 1.02, "end": 3.84, "language": "fr", "confidence": 0.93, "channel": 0, "words": [] }, "original_language": "fr", "target_language": "en", "translated_utterance": { "text": "Hello, I would like to book a table for two.", "start": 1.02, "end": 3.84, "language": "en", "confidence": 0.93, "channel": 0, "words": [] } } }
```

```xml title="translation"
<translation from="fr" to="en" channel="0" start="1.02" end="3.84">Hello, I would like to book a table for two.</translation>
```

### named_entity_recognition

One `<entity>` per entity found, inside one `<named_entities>` for the utterance.

```json title="named_entity_recognition"
{ "type": "named_entity_recognition", "session_id": "0199d7a2-5c3e-7b41-9f0a-3c2d1e4f5a6b", "created_at": "2026-11-06T15:02:12.010Z", "error": null, "data": { "utterance_id": "00_00000003", "utterance": { "text": "Bonjour, je voudrais réserver une table pour deux.", "start": 1.02, "end": 3.84, "language": "fr", "confidence": 0.93, "channel": 0, "words": [] }, "results": [{ "entity_type": "CARDINAL", "text": "deux", "start": 3.1, "end": 3.4 }] } }
```

```xml title="named_entity_recognition"
<named_entities channel="0" start="1.02" end="3.84"><entity entity_type="CARDINAL" start="3.1" end="3.4">deux</entity></named_entities>
```

With [`alternative_names`](/features/named-entity-recognition/#alternative-names), each name also carries its probability and census row,
and one `<alternative>` per name that sounds like it, inside the `<entity>`, after the name as heard. An XML parser's
`entity.text` is still the name as heard; the alternatives are its child elements.

```json title="named_entity_recognition with alternative_names"
{ "type": "named_entity_recognition", "session_id": "0199d7a2-5c3e-7b41-9f0a-3c2d1e4f5a6b", "created_at": "2026-11-07T15:02:11.402Z", "error": null, "data": { "utterance_id": "00_00000004", "utterance": { "text": "Bonjour, c'est Mickaël Dupond pour la réservation.", "start": 0.42, "end": 4.1, "language": "fr", "confidence": 0.93, "channel": 0, "words": [] }, "results": [{ "entity_type": "name_given", "text": "Mickaël", "start": 1.36, "end": 1.8, "id": 1, "probability": 0.41, "census": { "frequency": 1893, "share": 0.0019, "rank": 248, "gender": "m" }, "alternatives": [{ "name": "Michaël", "probability": 0.27, "similarity": 0.95, "census": { "frequency": 2140, "share": 0.0021, "rank": 212, "gender": "m" } }, { "name": "Mikaël", "probability": 0.14, "similarity": 0.94, "census": { "frequency": 1120, "share": 0.0011, "rank": 401, "gender": "m" } }] }, { "entity_type": "name_family", "text": "Dupond", "start": 1.8, "end": 2.31, "id": 1, "probability": 0.22, "census": { "frequency": 3105, "share": 0.0007, "rank": 1290 }, "alternatives": [{ "name": "Dupont", "probability": 0.68, "similarity": 1.0, "census": { "frequency": 98410, "share": 0.0221, "rank": 9 } }] }] } }
```

```xml title="named_entity_recognition with alternative_names"
<named_entities channel="0" start="0.42" end="4.1"><entity entity_type="name_given" start="1.36" end="1.8" probability="0.41" frequency="1893" rank="248" gender="m">Mickaël<alternative probability="0.27" similarity="0.95" frequency="2140" rank="212" gender="m">Michaël</alternative><alternative probability="0.14" similarity="0.94" frequency="1120" rank="401" gender="m">Mikaël</alternative></entity><entity entity_type="name_family" start="1.8" end="2.31" probability="0.22" frequency="3105" rank="1290">Dupond<alternative probability="0.68" similarity="1.0" frequency="98410" rank="9">Dupont</alternative></entity></named_entities>
```

### pii

One `<entity>` per personal data found. The data itself is in the element's text only with
`pii.return_entities`.

```json title="pii"
{ "type": "pii", "session_id": "0199d7a2-5c3e-7b41-9f0a-3c2d1e4f5a6b", "created_at": "2026-11-06T15:02:12.010Z", "error": null, "data": { "utterance_id": "00_00000004", "utterance": { "text": "Mon numéro est le <pii:phone_number id=\"1\"/>.", "start": 4.1, "end": 6.2, "language": "fr", "confidence": 0.93, "channel": 0, "words": [] }, "results": [{ "entity_type": "phone_number", "id": 1, "action": "masked" }] } }
```

```xml title="pii"
<pii channel="0" start="4.1" end="6.2"><entity entity_type="phone_number" id="1" action="masked"/></pii>
```

### sentiment_analysis

One `<sentiment>` per result. The text is the transcript's, so the tag leaves it out.

```json title="sentiment_analysis"
{ "type": "sentiment_analysis", "session_id": "0199d7a2-5c3e-7b41-9f0a-3c2d1e4f5a6b", "created_at": "2026-11-06T15:02:12.010Z", "error": null, "data": { "utterance_id": "00_00000003", "utterance": { "text": "Bonjour, je voudrais réserver une table pour deux.", "start": 1.02, "end": 3.84, "language": "fr", "confidence": 0.93, "channel": 0, "words": [] }, "results": [{ "sentiment": "neutral", "emotion": "neutral", "text": "Bonjour, je voudrais réserver une table pour deux.", "start": 1.02, "end": 3.84, "channel": 0 }] } }
```

```xml title="sentiment_analysis"
<sentiment channel="0" start="1.02" end="3.84" sentiment="neutral" emotion="neutral"/>
```

### start_recording, end_recording, end_session

Sent when `messages_config.receive_lifecycle_events` is on. `end_session` also arrives as JSON, right after its
tag: the SDKs close the session on it.

```json title="end_recording"
{ "type": "end_recording", "session_id": "0199d7a2-5c3e-7b41-9f0a-3c2d1e4f5a6b", "created_at": "2026-11-06T15:02:40.000Z", "data": { "recording_duration": 27.2 } }
```

```xml title="end_recording"
<end_recording recording_duration="27.2"/>
```

### error

Also arrives as JSON, right after its tag, for your error handler.

```json title="error"
{ "type": "error", "session_id": "0199d7a2-5c3e-7b41-9f0a-3c2d1e4f5a6b", "created_at": "2026-11-06T15:02:40.000Z", "error": { "message": "Audio format not supported" } }
```

```xml title="error"
<error>Audio format not supported</error>
```

### Any other event

An event this page does not list (a newer one) still arrives as a tag: its name, every simple value of its `data`
as an attribute, and one `<result/>` per item of its `results`.

### What stays JSON

- The acknowledgments (`audio_chunk`, `stop_recording`, `finalize`, `session_config`): the
  SDKs read them to know which audio they may discard and what to send again after a reconnection.
- `post_transcript`, `post_final_transcript`, `post_summarization`, `post_chapterization`: documents of the whole
  session, not events of the conversation.
- The messages of speech-to-speech sessions.

## Good to know

- **`messages_config` still applies.** A `speech_start` arrives as a tag only when `receive_speech_events` is on,
  an `end_session` only with `receive_lifecycle_events`. `receive_final_transcripts: false` does not hide the tags.
- **The callback does not change.** Your `callback_config` URL receives the JSON messages, never tags.
- **The result keeps the real transcript.** `GET /v2/live/{id}` and `post_final_transcript` hold the speech only,
  never a tag.
- **Chosen at the init.** `xml_events` cannot change in a `session_config` message.
- **Not sent again after a reconnection.** A tag lost while the WebSocket was down is not replayed; the transcripts
  are, as usual.
- **A failure says so.** A translation or an add-on that failed gives its tag with the reason, `<translation
  from="fr" to="en" error="translation timed out"/>`, and its JSON message follows, for your error handler.
- **Ids are unique per connection.** An event's id is `xml_<connection>_<index>`: after a reconnection, the new
  tags never reuse an id you have already seen.
- **Escaped.** `&`, `<`, `>` and quotes in a value are escaped (`&amp;`, `&lt;`…): parse the tag with an XML parser,
  not by splitting the string.

## Related pages

- [End of turn](/live/end-of-turn/)
- [Real-time translation](/features/translation/)
- [Live transcription over WebSocket: how a session works](/live/how-it-works/)
