> This page is for Server SDKs.

> Fetch clean Markdown by appending `.md` to any page URL under https://signalwire.com/docs or requesting it with the HTTP header `Accept: text/markdown`. The root index at https://signalwire.com/docs/llms.txt lists the available documentation indexes.

# spelling_variants

> List the spellings a word could be, given the letters your recognizer confuses.

[ref-speech]: /docs/server-sdks/reference/python/agents/speech

[read-spelled]: /docs/server-sdks/reference/python/agents/speech/read-spelled

Return the spellings `units` could be, given letters the recognizer confuses. The
spelling as heard comes first, then the variants with one change, then two, and so
on, up to `limit`. Look each one up in your own records, in order: the first that
matches is the likeliest.

Which letters a recognizer confuses depends on the recognizer and the voice, so no
confusion groups are built in. Measure them on your own calls.

```python
from signalwire.speech.spelling import spelling_variants
```

## Parameters

**`units`** `Sequence[str]` — required

The units as heard, such as the list [`read_spelled()`][read-spelled] returns.

---

**`groups`** `Mapping[str, Iterable[str]]` — required

For each unit, the units it may have been, such as
`{"S": "F", "F": "S", "M": "N", "N": "M"}`. A string value is read as its letters.

---

**`positions`** `Iterable[int] | None` — default: None

Keyword-only. The positions in `units` that may vary, such as the letters the
recognizer was least sure of: [`AgentBase.speech_finals()`](/docs/server-sdks/reference/python/agents/agent-base/speech-finals) gives a confidence for
each word the recognizer heard. `None` lets every position vary.

---

**`limit`** `int` — default: 50

Keyword-only. The most spellings to return, the spelling as heard included.

---

## Returns

`list[str]` -- The spellings, each joined into one string.

## Example

```python
from signalwire.speech.spelling import read_spelled, spelling_variants

units = read_spelled("S as in Sam, m i t h")
print(spelling_variants(units, {"S": "F", "M": "N"}))
# ['SMITH', 'FMITH', 'SNITH', 'FNITH']
print(spelling_variants(units, {"S": "F", "M": "N"}, positions=[1]))
# ['SMITH', 'SNITH']
```

Part of the [speech helpers][ref-speech] module.