Patterns
Patterns help recover short, structured alphanumeric tokens - order codes, reference numbers, licence plates - that are easy to mishear when spoken letter-by-letter and digit-by-digit. When you know the shape of a token that may appear in the audio, describe it with a subset of regular-expression syntax and the transcription is corrected to fit.
Patterns are available on the Prerecorded, Realtime, and Turns APIs.
Using Patterns
Section titled “Using Patterns”Pass the patterns query parameter as a comma-separated list of patterns. Each one describes a single token to recover.
?patterns=AMZ[0-9]{6}?patterns=[A-Z]{2}[0-9]{2} [A-Z]{3}?patterns=(INV)?[0-9]{4,5}?patterns=AMZ[0-9]{6},ORD[0-9]{5}Patterns use a subset of regular-expression syntax:
| Syntax | Meaning | Example |
|---|---|---|
[0-9] |
a digit | [0-9]{6} |
[A-Z] |
a letter | [A-Z]{3} |
{n} |
repeat the preceding class exactly n times |
[0-9]{6} |
{m,n} |
repeat the preceding class m to n times |
[0-9]{4,6} |
(...)? |
an optional group - matched only when spoken | (INV)?[0-9]{5} |
AMZ |
literal letters/digits, e.g. a fixed prefix | AMZ[0-9]{6} |
or - |
a separator | [A-Z]{2} [0-9]{3} |
Optional groups and ranges are resolved against the audio: an optional prefix is added only when it is actually spoken, and a {m,n} range adopts the spoken length. The more specific the pattern, the better - a fixed prefix or known structure (AMZ[0-9]{6}) is recovered more reliably than an open one.
A pattern matches tokens of at most 32 characters once fully expanded (the prefix and any digits or letters combined, separators excluded), and may describe at most 32 alternative shapes (each optional group and {m,n} range multiplies the alternatives). Syntax outside this subset - for example unbounded repeats like [0-9]+ - and patterns exceeding either limit are rejected with a 400 Bad Request.
Patterns cannot be combined with phrase biasing: don’t set patterns together with phrases or custom_model_id, or on requests from an API client with a custom model configured.
Examples
Section titled “Examples”| Token type | Example value | Pattern |
|---|---|---|
| Order code | AMZ374019 |
AMZ[0-9]{6} |
| Reference number | 4429105538 |
[0-9]{10} |
| Licence plate | RU77 TVG |
[A-Z]{2}[0-9]{2} [A-Z]{3} |
| Invoice (optional prefix) | INV4821 or 4821 |
(INV)?[0-9]{4} |
| Variable-length code | AMZ3740 … AMZ374019 |
AMZ[0-9]{4,6} |
See the API reference for Prerecorded, Realtime, and Turns.