Introduction
Unlike English, German is considered to have quite a phonemic writing system. That means that the correspondence between spelling and pronunciation is close. Given any word you aren't familiar with, you would still know how to pronounce it because of the spelling system. This means a computer should be able to do it too right?
Challenge
Write a program or function that takes as input a string representing a German word, and prints or returns its pronunciation in the International Phonetic Alphabet (IPA).
I am of course not going to make you learn German or the full IPA. This one Wikipedia section provides almost all the German to IPA rules you need, and I've coded an ungolfed C# reference implementation.
Also provided in that link is a list of 400 common German words and their IPA pronunciation (needed for validation). Taking an example from that list, if the input is solltest
, the correct output is ˈzɔltəst
.
The reference implementation adds two helpful rules not mentioned in the Wikipedia section: It assumes word stress is on first syllable (very likely in German), and uses a better heuristic for determining when the letter "e" represents the schwa sound /ə/. It also implements special processing for prefixes, but that didn't improve results as much as I thought it would.
Details
To be considered a valid entry, your program must meet the following requirements:
- Your IPA output must be an exact match for at least 300 of the 400 words in the reference word list (the reference implementation gets 333 correct)
- Your program must make a guess for any plausibly German word. So we have a technical requirement, this will mean that for any input that matches the regex
[a-zA-ZäÄöÖüÜ][a-zäöüß]*
and has at least one vowel (aeiouyäöü), you must produce non-whitespace-only output and not error out. - The program must be deterministic (always produce the same output given the same input)
- Otherwise, standard loopholes are forbidden (especially the one about fetching off-site resources)
Miscellaneous things you are allowed to do:
- Have leading and trailing whitespace in your output if you must
- Use any pre-existing character encoding in the output (I can't imagine anything other than Unicode working well, but if you can, congrats)
- Assume the input is in some normalized form like Unicode normalization forms NFD, NFC, etc. For example, is ä written as a single character or a base character + a combining character?
- Use standard input and output methods
Scoring & IPA Characters
Scoring is in bytes. Be warned that the German characters and the IPA characters are 2 bytes in UTF-8. Also, the IPA character U+0327 COMBINING INVERTED BREVE BELOW ( ̯) is a Unicode combining character and is a 2 byte UTF-8 character on its own. That means something like ɐ̯ would count as 4 bytes in UTF-8. For the curious, this symbol means the vowel does not form the syllable nucleus (the previous one does instead).
Also, beware of these IPA characters that in some fonts look like other ASCII characters: ɡ, ɪ, ʏ, ː (marks a long vowel), ˈ (marks which syllable has the stress in a multisyllable word).
How the reference word list was created
This section is extra info not needed for the challenge.
The word list was grabbed from this Wiktionary word frequency list, removing repeats because of casing difference and two words that didn't have German entries in the English Wiktionary (oh & hey). The IPA was from looking at both the English and German Wiktionaries. Where multiple pronunciations were offered, I chose the more formal and standard one. If this wasn't clear, I chose the one that most fit the general rules.
I also had to standardize how the letter "r" is pronounced. It is heavily dependent on the region how this letter pronounced, and Wiktionary was not at all consistent in which one it chose. I felt it tended towards the following: "r" is pronounced /ɐ̯/ when followed by a long vowel and a vowel does not follow, otherwise, it is ʁ. So, I changed all of them to follow that rule, except for the ver- and er- prefixes that were quite consistently /(f)ɛɐ̯/. Similarly, I standardized "eu" as /ɔʏ̯/.
#~WordData~"PhoneticForm"&
), but it works only for English words. \$\endgroup\$