Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

pycotovia

license: GPL-3.0 vibe coded

Pure-Python G2P (grapheme-to-phoneme) phonemizer for Galician and Spanish, based on the Cotovia TTS system.

Features

  • Two languages: Galician (gl) and Spanish (es) with language-specific exception lists and rewrite rules.
  • One tiny dependency: pure Python, no C extensions, no heavy ML models — scriptconv is the only requirement.
  • Fast enough: single-word latency is well under 1 ms on modern hardware.
  • Parity-tested: verified against the original Cotovia C binary for Galician (see docs/parity.md).
  • Multi-alphabet output: native Cotovía notation, IPA, X-SAMPA, ARPABET, Lexique, Kirshenbaum, or RFE, picked with one argument.

Installation

pip install pycotovia

Requires Python >= 3.11.

Quick start

import pycotovia

# Galician (default)
print(pycotovia.phonemize("Ola, como estás?"))      # → "ola komo estajs"
print(pycotovia.phonemize("guerra", lang="gl"))      # → "gerra"

# Spanish
print(pycotovia.phonemize("México", lang="es"))      # → "meksiko"
print(pycotovia.phonemize("México", lang="gl"))      # → "meSiko"

# IPA mapping
print(pycotovia.cotovia_to_ipa("gerra"))              # → "ɣɛra"

Output alphabets

pycotovia's native output is Cotovía notation — the phoneme symbols of the original Cotovía TTS engine. The alphabet argument converts that native output to any alphabet supported by scriptconv:

import pycotovia

print(pycotovia.ALPHABETS)
# ('cotovia', 'ipa', 'arpa', 'x-sampa', 'lexique', 'kirshenbaum', 'rfe')

print(pycotovia.phonemize("guerra", lang="gl"))                        # → "gerra "  (native, default)
print(pycotovia.phonemize("guerra", lang="gl", alphabet="ipa"))        # → "ɡera "
print(pycotovia.phonemize("cantar", lang="gl", alphabet="x-sampa"))    # → "kanta4 "

The default stays the native Cotovía notation, so existing calls are unaffected. Conversion only applies at tra=1 (phonemes only) — the stress and syllable markers available at higher tra levels have no equivalent in the other notations.

A symbol with no equivalent in the target alphabet raises UnmappedSymbolError rather than being dropped or mistranslated. An unknown alphabet name raises AlphabetError, listing the accepted values.

CLI

# Galician
echo "Ola mundo" | pycotovia

# Spanish
echo "Hola mundo" | pycotovia -l es

# IPA output
echo "Ola mundo" | pycotovia -a ipa

# From file
cat words.txt | pycotovia -l gl > phonemes.txt

Differences from the Cotovia binary

Aspect pycotovia Cotovia C binary
Output levels tra=1..5 -t0..-t3; tra=N matches -t(N-1)
Prosody (atonic words, open e/o) tra=4 -t3
Pause and phrase-group markers Not emitted #%pausa%#, %prop% at -t3
Verb timbre Falls through to the noun rules Resolved from the conjugation tables
Word category First entry in palabrasFuncion.txt Viterbi tagger over the dictionaries

At -t3 pycotovia reproduces 96.4% of the binary's words on the ProxectoNos test set. See docs/parity.md for the full results and the open divergences.

Documentation

Examples

See the examples/ directory for:

  • basic_usage.py: single words, phrases, IPA output
  • spanish_usage.py: Spanish-specific examples
  • phrase_processing.py: batch processing from a file

How this port was made, and its licence (please read)

This is an AI-assisted, human-guided, test-driven port. An AI assistant read the public Cotovia C++ source and reimplemented the G2P subsystem (transcription rules, syllabification, stress assignment, exception lists) in Python. A human guided the effort and validated results against the original Cotovia binary. The human collaborators never read the Cotovia C++ source themselves: they drove and checked the work through the binary.

Because the implementing AI read the GPL source, this is not a clean-room reimplementation and we make no such claim. It is a source-derived port. Cotovia is GPL-licensed, so to honour the original work this project is licensed GPL-3.0-or-later (see LICENSE).

Open questions we want to be transparent about (not legal advice):

  • Was this clean-room? No: the implementing agent read the GPL source.
  • Could it be relicensed permissively? Almost certainly not. A port derived from GPL source is a derivative work, so we keep GPL.
  • Can an AI originate or "assign" a licence? Unsettled: authorship/copyright of AI-generated code is legally unclear. We apply GPL-3.0 as the conservative, upstream-respecting default rather than asserting any novel rights.

Acknowledgements

The Cotovia G2P rules, syllabification, stress assignment and exception lists this port derives from are the work of the Multimedia Technologies Group, University of Vigo and the Centro Ramón Piñeiro para a Investigación en Humanidades. This credit does not imply their endorsement.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycotovia-0.4.0a1.tar.gz (64.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycotovia-0.4.0a1-py3-none-any.whl (52.5 kB view details)

Uploaded Python 3

File details

Details for the file pycotovia-0.4.0a1.tar.gz.

File metadata

  • Download URL: pycotovia-0.4.0a1.tar.gz
  • Upload date:
  • Size: 64.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pycotovia-0.4.0a1.tar.gz
Algorithm Hash digest
SHA256 afbddf6ec45a92578f13c5df9f60e205f713858ffbee28e3579745050a4cd2de
MD5 b7739ffa90862ffacab298b683558774
BLAKE2b-256 5b9c480c7cd3de244e2216bdbe2919b2c2b81dd43ff91844129fc5dc9e4d835b

See more details on using hashes here.

File details

Details for the file pycotovia-0.4.0a1-py3-none-any.whl.

File metadata

  • Download URL: pycotovia-0.4.0a1-py3-none-any.whl
  • Upload date:
  • Size: 52.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pycotovia-0.4.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 d497d5509b62bcc9afdc19933411c74fdadc1b9dd6bde0de0d962e92bfd5997f
MD5 1dbf1d08c7626c91afb234d7e747f2e5
BLAKE2b-256 3023e24a5a6bb70b7421aa79a3436a6f638456758226118fb5e58d27e1c8eef5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page