Metadata-Version: 2.4
Name: ovos-utterance-normalizer
Version: 0.2.8a1
Author-email: jarbasai <jarbasai@mailfence.com>
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/OpenVoiceOS/ovos-utterance-normalizer
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Topic :: Text Processing :: Linguistic
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: ovos-utils<1.0.0,>=0.0.38
Requires-Dist: quebra-frases
Requires-Dist: ovos-plugin-manager>=2.1.0
Requires-Dist: ftfy
Requires-Dist: numtag>=0.12.2a1
Dynamic: license-file

# ovos-utterance-normalizer

`ovos-utterance-normalizer` is an utterance transformer plugin for [OpenVoiceOS](https://github.com/OpenVoiceOS). It runs after speech-to-text and before the intent engines. It gives the intent pipeline extra candidate utterances, and one of these candidates writes numbers as digits.

```python
from ovos_utterance_normalizer import UtteranceNormalizerPlugin

plugin = UtteranceNormalizerPlugin()
plugin.transform(["i'm sure it's twenty past five"], {"lang": "en-US"})[0]
# ["i'm sure it is twenty past five", "i'm sure it's twenty past five", "i'm sure it is 20 past 5"]
```

## What the plugin does

For each utterance, `transform` returns up to three candidates in this order:

1. the utterance with its contractions expanded;
2. the utterance as received;
3. the normalized utterance, with number words written as digits and the settings of the language applied.

The plugin removes punctuation from the start and the end of each candidate, and it removes duplicates. Before these steps, it repairs text encoding errors with [ftfy](https://github.com/rspeer/python-ftfy). See [docs/candidates.md](docs/candidates.md).

## Numbers

The plugin reads numbers with [numtag](https://github.com/TigreGotico/numtag), only in the languages of `NUMBER_LANGUAGES`: an, ar, bg, ca, cs, de, en, es, et, fi, gl, he, hr, hu, id, nb, pt, ro, ru, sk, sl, tr and uk. Every other language passes through unchanged. A language enters the set when a value check over the shipped skill locales finds no new wrong digit for it.

Only a whole-number cardinal said in words becomes digits, when numtag marks it as no article and no word with another meaning. Ordinals, fractions and decimals keep their words. Articles keep their words too. numtag still reads the English pronoun "one" as a number, as in "read the next one". See the known misreads in [docs/numbers.md](docs/numbers.md#known-misreads). numtag does not find idioms or titles, so a number word in an idiom also becomes digits: "mil gracias" gives "1000 gracias".

| Language | Input | Normalized candidate |
|---|---|---|
| pt-PT | põe um temporizador de vinte e cinco minutos | põe um temporizador 25 minutos |
| en-US | the twenty first of may | the twenty first of may |
| de-DE | stell einen Timer auf fünfundzwanzig Minuten | stell einen Timer auf 25 Minuten |
| es-ES | tengo treinta y dos años | tengo 32 años |

See [docs/numbers.md](docs/numbers.md) and [docs/languages.md](docs/languages.md).

Digits can help a template or keyword engine with a number slot. They do not help every pipeline: an engine trained on raw speech-to-text output, or an engine based on a large language model, can gain nothing or do worse. No gain is measured. See [docs/intent-matching.md](docs/intent-matching.md).

No OpenVoiceOS specification defines this normalization. OVOS-INTENT-1 §2 names a separate text-normalization specification that does not exist. See [docs/specification.md](docs/specification.md).

## Install

The package needs Python 3.11 or newer.

```bash
uv pip install --prerelease=allow ovos-utterance-normalizer
```

## Configuration

The default `mycroft.conf` of [ovos-config](https://github.com/OpenVoiceOS/ovos-config) turns the plugin on:

```json
"utterance_transformers": {
   "ovos-utterance-normalizer": {}
}
```

| Key | Default | What it does |
|---|---|---|
| `lang` | `"en-us"` | The language to use when the message context has no `lang` |
| `fix_encoding_errors` | `true` | Repairs encoding errors with ftfy |
| `strip_punctuation` | `true` | Removes punctuation from the start and the end of each candidate |
| `active` | `true` | When it is `false`, the plugin does not load |

See [docs/configuration.md](docs/configuration.md).

## Documentation

The [docs](docs/index.md) directory holds one page for each topic: candidates, the normalized candidate, numbers, languages, contractions, configuration, intent matching and the specification status.

## Related projects

- [ovos-plugin-manager](https://github.com/OpenVoiceOS/ovos-plugin-manager) loads and runs this plugin as an `opm.transformer.text` transformer.
- [ovos-config](https://github.com/OpenVoiceOS/ovos-config) holds the default `mycroft.conf` that turns this plugin on.
- [ovos-core](https://github.com/OpenVoiceOS/ovos-core) calls the utterance transformers before intent matching.
- [numtag](https://github.com/TigreGotico/numtag) finds the numbers and their values.

## License

Apache-2.0
