## Documentation Index

Fetch the complete documentation index at: [/llms.txt](https://developer.sanas.ai/llms.txt)

Use this file to discover all available pages before exploring further.

For Language Translation, the SDK always delivers two parallel streams of transcript events — one for the source language (what was spoken) and one for the target language (the translation). Both arrive as JSON strings through your `TranscriptCallback`.

## Registering the callback

```
auto onTranscript =  {
    // parse and handle the JSON event (see schema below)
};

// Pass as the 4th argument to CreateAudioProcessor
auto p = sdk->CreateAudioProcessor(params, rc, onState, onTranscript);
```

## Event types

| `type` field | Contents |
| --- | --- |
| `"transcription"` | Speech recognised in the source language. |
| `"translation"` | Text translated into the target language. |

## JSON schema

```
{
  "type": "transcription",
  "transcription": {
    "lang": "en-US",
    "complete": [
      { "word": " hello", "start": 0.10, "end": 0.42, "probability": 0.99 }
    ],
    "partial": [
      { "word": " world", "start": 0.42, "end": 0.70, "probability": 0.88 }
    ],
    "utterance_idx": 0
  }
}
```

| Field | Type | Description |
| --- | --- | --- |
| `type` | string | `"transcription"` or `"translation"` |
| `lang` | string | BCP-47 language code for this event. |
| `complete` | array | Finalised words — will not change. |
| `partial` | array | In-progress words — may be revised in the next event. |
| `word` | string | Word text with a leading space. Concatenate to rebuild sentences. |
| `start` / `end` | float | Timing offsets in seconds from the start of the utterance. |
| `probability` | float (0–1) | Recognition confidence. Words below ~0.7 are lower-confidence. |
| `utterance_idx` | integer | Monotonically increasing counter that groups words into utterances. |

## Example: print finalised text

```
auto onTranscript =  {
    try {
        auto root = nlohmann::json::parse(jsonData);
        std::string type = root.value("type", "");
        if (!root.contains(type)) return;

const auto& body = root[type];
        std::string text;
        for (const auto& w : body.value("complete", nlohmann::json::array()))
            text += w.value("word", "");
        if (!text.empty())
            std::cout << "["\
                      << (type == "translation" ? "TARGET" : "SOURCE")\
                      << " " << body.value("lang", "") << "] " << text << "\n";
    } catch (const std::exception& e) {
        std::cerr << "parse error: " << e.what() << "\n";
    }
};
```

**JSON library.** `nlohmann/json` is used in examples for brevity. Any JSON library works. Always wrap parsing in try/catch.
