Skip to navigation

spelling_variants

View as MarkdownOpen in Claude

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.

from signalwire.speech.spelling import spelling_variants

Parameters

units
Sequence[str]Required

The units as heard, such as the list 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] | NoneDefaults to None

Keyword-only. The positions in units that may vary, such as the letters the recognizer was least sure of: AgentBase.speech_finals() gives a confidence for each word the recognizer heard. None lets every position vary.

limit
intDefaults to 50

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

Returns

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

Example

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 module.