phonemes
Shared pronunciation parsing and normalization utilities for TTS services.
A pronunciation reaches a TTS service as an IPA string. Services each want their own markup for it, but they all start from the same steps: tidy the notation, split it into phones, and find which vowel each stress mark belongs to. Those steps live here, so a service’s formatter only has to render the result.
Normalization is notation-only. It unifies ways of writing the same symbol
(ʧ and tʃ, g and ɡ, ' and ˈ) and never changes which sound
is written, so it is safe for any language.
- pipecat.utils.text.phonemes.normalize_ipa(ipa: str) str[source]
Unify the notation of an IPA string without changing what it says.
Strips surrounding
/…/or[…], composes Unicode, replaces ligatures and ASCII look-alikes with their IPA symbols, writestʃanddʒuntied and other affricates tied (ʦbecomest͡s), drops syllable breaks, and collapses whitespace.- Parameters:
ipa – An IPA transcription.
- Returns:
The same transcription in canonical notation.
Example:
normalize_ipa("/ˈʧɪ.kən/") # "ˈtʃɪkən"
- pipecat.utils.text.phonemes.ipa_phones(ipa: str) list[str][source]
Split one IPA word into phones, in written order.
Stress marks are returned as tokens of their own, where they were written. Tied sequences (
t͡s),tʃ,dʒand the English diphthongs are one phone each, returned without the tie bar; length marks and combining diacritics stay with the phone they modify.- Parameters:
ipa – An IPA transcription of a single word.
- Returns:
The phones and stress marks of the word.
Example:
ipa_phones("mɛtˈfɔɹmɪn") # ["m", "ɛ", "t", "ˈ", "f", "ɔ", "ɹ", "m", "ɪ", "n"]
- pipecat.utils.text.phonemes.is_ipa_vowel(phone: str) bool[source]
Whether an IPA phone (as returned by
ipa_phones()) is a vowel.
- pipecat.utils.text.phonemes.stress_before_vowels(phones: list[str]) list[str][source]
Move each stress mark from where it was written to just before its vowel.
Transcriptions usually put stress at the start of the syllable (
mɛtˈfɔɹmɪn); some services want it on the vowel itself (mɛtfˈɔɹmɪn). A stress mark with no vowel after it is dropped.- Parameters:
phones – Phones and stress marks, as returned by
ipa_phones().- Returns:
The same phones with every stress mark directly before a vowel.