> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gnani.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Find and replace

> Replace words and phrases in the finished transcript with your own rules, on REST and Realtime, with either model.

Use this when the transcript is right but you want a word written your way every time, such as a product name, a spelling or an internal term.

## Turn it on

Send `enable_substitution=true` and your rules in `substitution_map`, as a JSON list. This example fixes three words in the names sample clip:

```bash cURL theme={null}
curl -o names.wav https://docs.gnani.ai/audio/samples/names-and-terms-hi-IN.wav

curl --request POST \
  --url https://api.vachana.ai/stt/v3 \
  --header "X-API-Key-ID: $GNANI_API_KEY" \
  --form audio_file=@names.wav \
  --form model=prisma-v3.0 \
  --form language_code=hi-IN \
  --form enable_substitution=true \
  --form-string 'substitution_map=[{"patterns":["India"],"replacement":"Inya"},{"patterns":["वचना"],"replacement":"Vachana"},{"patterns":["renew"],"replacement":"रिन्यू"}]'
```

```python Python theme={null}
import json
import os

import requests

rules = [
    {"patterns": ["India"], "replacement": "Inya"},
    {"patterns": ["वचना"], "replacement": "Vachana"},
    {"patterns": ["renew"], "replacement": "रिन्यू"},
]

with open("names.wav", "rb") as f:
    r = requests.post(
        "https://api.vachana.ai/stt/v3",
        headers={"X-API-Key-ID": os.environ["GNANI_API_KEY"]},
        files={"audio_file": ("names.wav", f, "audio/wav")},
        data={
            "model": "prisma-v3.0",
            "language_code": "hi-IN",
            "enable_substitution": "true",
            "substitution_map": json.dumps(rules, ensure_ascii=False),
        },
        timeout=60,
    )
r.raise_for_status()
print(r.json()["transcript"])
```

```javascript Node.js theme={null}
import { readFileSync } from "node:fs";

const rules = [
  { patterns: ["India"], replacement: "Inya" },
  { patterns: ["वचना"], replacement: "Vachana" },
  { patterns: ["renew"], replacement: "रिन्यू" },
];

const form = new FormData();
form.append("audio_file", new Blob([readFileSync("names.wav")], { type: "audio/wav" }), "names.wav");
form.append("model", "prisma-v3.0");
form.append("language_code", "hi-IN");
form.append("enable_substitution", "true");
form.append("substitution_map", JSON.stringify(rules));

const response = await fetch("https://api.vachana.ai/stt/v3", {
  method: "POST",
  headers: { "X-API-Key-ID": process.env.GNANI_API_KEY },
  body: form,
});
if (!response.ok) throw new Error(await response.text());
console.log((await response.json()).transcript);
```

```python Python SDK theme={null}
# The Python SDK (gnani-vachana 0.11.0) cannot send enable_substitution or substitution_map.
# Use the Python tab, or apply your own replacements to result["transcript"].
```

## Examples

The names sample clip (synthetic, Timbre v3.0), with `language_code=hi-IN`. Each model mishears different words, so each needs its own rules:

| Listen | What is said |
| - | - |
| <audio controls preload="none" src="https://docs.gnani.ai/audio/samples/names-and-terms-hi-IN.wav" aria-label="Sample clip with names and terms, in Hindi" /> | नमस्ते, मैं Inya से प्रियंवदा बोल रही हूँ। आपका NACH mandate कल Vachana पर रिन्यू हो जाएगा। |

| Model | Rules | Transcript |
| - | - | - |
| Prisma v3.0 | none | नमस्ते, मैं **India** से प्रियम्वदा बोल रही हूँ, आपका NACH mandate कल **वचना** पर **renew** हो जाएगा। |
| Prisma v3.0 | `India` → `Inya`, `वचना` → `Vachana`, `renew` → `रिन्यू` | नमस्ते, मैं **Inya** से प्रियम्वदा बोल रही हूँ, आपका NACH mandate कल **Vachana** पर **रिन्यू** हो जाएगा। |
| Prisma v2.5 | none | नमस्ते, मैं **इंडिया** से प्रियंवदा बोल रही हूँ, आपका **एन ए सी एच मैंडेट** कल **वाचना** पर रिन्यू हो जाएगा। |
| Prisma v2.5 | `इंडिया` → `Inya`, `वाचना` → `Vachana`, `एन ए सी एच मैंडेट` → `NACH mandate` | नमस्ते, मैं **Inya** से प्रियंवदा बोल रही हूँ, आपका **NACH mandate** कल **Vachana** पर रिन्यू हो जाएगा। |

Each request gave the same result both times it was run. The last row shows a pattern of several words. The name *प्रियंवदा* is not in the rules, so it stays as each model wrote it. To help the model hear names in the first place, use [keyterms](https://docs.gnani.ai/api/STT/names-and-terms.md) instead.

## By interface

> [tab] REST
>
> Form fields `enable_substitution` and `substitution_map` on [`POST /stt/v3`](https://docs.gnani.ai/api/STT/speech-to-text).

> [tab] Realtime
>
> Headers `enable_substitution` and `substitution_map` on [`WS /stt/v3/stream`](https://docs.gnani.ai/api/STT/stt-websocket). The rules apply to each transcript segment. Turn them on or off, or replace them, mid-session with the `substitution` key of `update_settings`; it applies from the next segment:
>
> ```json theme={null}
> {"type": "update_settings", "substitution": {"enabled": true, "map": [{"patterns": ["ok", "okay"], "replacement": "acknowledged"}]}}
> ```
>
> Send `enabled` alone to switch the stored rules on or off, or `map` alone to swap them.

> [tab] Batch
>
> Not available. Batch jobs do not accept `enable_substitution` or `substitution_map`; apply your rules to the transcripts after the job finishes.

## By model

Find-and-replace works the same way on Prisma v3.0 and Prisma v2.5. It runs on the finished transcript, after recognition and after number formatting, so it does not depend on the model. What differs is the text it runs on: the two models write the same speech differently (see the [Examples](#examples)), so write your patterns for the model you use.

## Rules and limits

```json theme={null}
[
  {"patterns": ["okay", "ok"], "replacement": "acknowledged"},
  {"patterns": ["rupees", "rs"], "replacement": "INR"}
]
```

| | Rule |
| - | - |
| Rules | Up to 10 per request. |
| Patterns | Any number per rule, all replaced by that rule's `replacement`. A pattern can be several words. |
| Case | Ignored: `india` matches *India*. |
| Whole words only | A pattern matches at word boundaries, in any script: `ok` does not match inside *okay*, and `Ind` does not match inside *India*. |
| Order | Longer phrases are matched before shorter ones, so `New Delhi` is tried before `Delhi`. |
| One pass | A replacement is never matched again by another rule. |
| When it runs | After recognition and after number formatting (`format=transcribe`). |

## Things to watch for

* **`substitution_map` is ignored unless `enable_substitution=true`.** There is no error.
* **Every match is replaced.** A rule `India` → `Inya` also changes a real mention of India. Keep patterns specific, and use [keyterms](https://docs.gnani.ai/api/STT/names-and-terms.md) when the problem is that the model mishears a word.
* **Write patterns for the formatted text.** With `format=transcribe`, match *₹500*, not the words for it.
* **Only the transcript you receive changes.** Billing and analytics records keep the original transcript.
* **More than 10 rules:** the result is TBC. Keep to 10.
* **Realtime:** an invalid `update_settings` frame is ignored as a whole, and the previous rules stay in effect.
* **Python SDK:** cannot send find-and-replace. Use an HTTP request or the Realtime WebSocket directly.

## Related

> [card] [Improve names and terms](https://docs.gnani.ai/api/STT/names-and-terms.md)
>
> Help the model hear names and domain words in the first place.

> [card] [Format numbers](https://docs.gnani.ai/api/STT/format-numbers.md)
>
> Numbers, money and dates as digits, before your rules run.

> [card] [Choose an output style](https://docs.gnani.ai/api/STT/output-styles.md)
>
> How English words and numbers are written.

> [card] [Realtime streaming](https://docs.gnani.ai/api/STT/stt-websocket.md#client-control-frames)
>
> `update_settings` and the other control frames.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.